[rspec-users] Specifying a few valid values

David Chelimsky dchelimsky at gmail.com
Thu Jul 17 08:28:48 EDT 2008

On Thu, Jul 17, 2008 at 6:18 AM, Jonathan Leighton
<j at jonathanleighton.com> wrote:
> 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")

Hi Jon -

There's not really anything more clear supported, but you could always
write a custom matcher for this.

I'm wondering why the examples aren't more specific though. Why is it
OK that the action could be one of two possibilities given a specific
set of givens?


> Jon

More information about the rspec-users mailing list