How to use Config.mappings?

5 views
Skip to first unread message

Nick W

unread,
Dec 23, 2009, 3:55:44 PM12/23/09
to pickle
I have the following in my env.rb file - taken straight from the
pickle example:

Pickle.configure do |config|
config.adapters = [:factory_girl]
config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
end

However I get an undefined method 'me' for Cucumber::World when
running this step:

Given "I am logged in" do
Given "I am activated"
When "I login with \"#{me.email}\", \"#{me.password}\""
Then "I should see \"Logged in successfully\""
end

Has anyone successfully used mappings and have an example of the
proper usage?

Ian White

unread,
Dec 23, 2009, 5:09:52 PM12/23/09
to pickle-...@googlegroups.com
Hi Nick,

The mappings feature is intended for use in step parsing rather than
step definitions.

For example(s)

Given I exist

Then 1 email should be delivered to me


Inside a step def you can use the refs with the model method

model('me')


Hope that helps

Cheers,
Ian

Sent from my iPhone

> --
>
> You received this message because you are subscribed to the Google
> Groups "pickle" group.
> To post to this group, send email to pickle-...@googlegroups.com.
> To unsubscribe from this group, send email to pickle-cucumb...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/pickle-cucumber?hl=en
> .
>
>

Ian White

unread,
Dec 23, 2009, 5:11:48 PM12/23/09
to pickle-...@googlegroups.com
I think I should write some better docs about this...

Sent from my iPhone

On 23 Dec 2009, at 20:55, Nick W <nick.w...@gmail.com> wrote:

Nick W

unread,
Dec 23, 2009, 6:14:04 PM12/23/09
to pickle
Agreed - this seems like a very handy feature. I'm still not quite
getting it tho.


I have this in my scenario:

Given I am logged in

Then my step definition now looks like this:

Given "I am logged in" do

me = model('I')


Given "I am activated"
When "I login with \"#{me.email}\", \"#{me.password}\""
Then "I should see \"Logged in successfully\""
end

And I get this error:

Can't find pickle model: 'user: "me"' in this scenario (RuntimeError)

Is pickle looking for a factory called "me", or do I have to define a
pickle model in called "me" in every scenario?

Thanks!
Nick

On Dec 23, 2:11 pm, Ian White <ian.w.wh...@gmail.com> wrote:
> I think I should write some better docs about this...
>
> Sent from my iPhone
>

Ian White

unread,
Dec 23, 2009, 7:24:29 PM12/23/09
to pickle-...@googlegroups.com
All that pickle does is map (say) 'I' to 'the user: "me"', it doesn't
try to create or find the model (because it doesn't know what your
intentions are with this). I think that's the element that's missing
here.

If you add
Given "I exist"

as the 2nd line of your step, then it should work (given that you have
a user factory set up).

You could also use this as a find example, say you;ve filled in some
forms and you expect a user to exist at the end of it you could do:

Then I should exist with username: "fred"

Which would assert that a user exists with the said attributes, and
also assigning a pickle ref (the user: "me") to that, which means you
could then do (for example):

And 1 email should be sent to me
When I go to my account page
I should see "You have just signed up"

etc

Does that make sense?

Cheers,
Ian

Nick W

unread,
Dec 25, 2009, 3:50:44 PM12/25/09
to pickle
Thanks Ian, I think I have it now. One issue I had was that I have a
user factory called ":me" so my mapping needed to look like:

config.map 'I', 'myself', 'me', 'my', :to => 'me: "me"'

Reply all
Reply to author
Forward
0 new messages