[rspec-users] Specifying a few valid values

Jonathan Leighton j at jonathanleighton.com
Thu Jul 17 07:18:49 EDT 2008


I have a Rails spec where I want to check that the action_name is either
"create" or "update". I can think of a couple of ways to do it, but none
of them reads fantastically well:

1. ["create", "update"].should include(controller.action_name)

Problem: The error message, should it fail, is: expected ["create",
"update"] to include "foo"

2. controller.action_name.should match(/^create|update$/)

Problem: Not brilliantly readable, but the error message would be
better.

Is there a better way to do it? Something like this would be cool:

controller.action_name.should == any_of("create", "update")

Jon



More information about the rspec-users mailing list