[rspec-users] loading custom matchers into cucumber
Ben Mabey
ben at benmabey.com
Wed Jul 8 11:33:57 EDT 2009
Joaquin Rivera Padron wrote:
>
> hi there,
> In a step I need to assert (don't know hoe to translate this into
> "should" terms) state before keep going, example:
>
Perhaps you need to make an "expectation" instead of an "assert"? :)
>
> Given "I have signed up as tom who is an admin" do |user, role| do
> # call some steps to create user tom
>
> end
>
>
> oops, sorry that was gone unfinished!
>
> Given "I have signed up as tom who is an admin" do |user, role| do
> # call some steps to create user tom
> # I need to assert that tom really have the rol (this is not the
> most important, so please bear with me)
> user_should_have_role user, role
> end
>
> that as you see is not very pretty, I would like to do:
>
> Spec::Matchers.define :have_rol do |role|
> match do |user|
> user.roles.collect{ |r| r.name <http://r.name> }.include?(role)
> end
> end
>
> and then "assert":
>
> tom.should have_role role
>
> only I don't get to load the matcher. how you normally load custom
> machters to be used in cucumber?
Try putting your Spec::Matchers.define block in your env.rb file to see
if that works. I haven't looked closely at how the new matcher DSL adds
the matchers but I would think that would work.
-Ben
More information about the rspec-users
mailing list