Cucumber - Recommended viewing

http://mwrc2009.confreaks.com/14-mar-2009-15-00-bdd-with-cucumber-ben-mabey.html

On Fri, Apr 10, 2009 at 8:07 PM, James B. [email protected]
wrote:

http://mwrc2009.confreaks.com/14-mar-2009-15-00-bdd-with-cucumber-ben-mabey.html

Strongly agreed. I’ve been watching all of the Mountain West RubyConf
presentations, and came close to skipping the BDD one, thinking “I’ve
been working with this stuff for a few months now, do I really need to
spend time on one more Cucumber tutorial?” But as it happened, I
learned quite a bit – both in fundamental philosophy, and a few
syntax tricks I’d never picked up on.

Great job, Ben!


Have Fun,
Steve E. ([email protected])
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org

Stephen E. wrote:

syntax tricks I’d never picked up on.

Great job, Ben!

Thanks!

I also recommend reading/viewing is Joesph’s presentation from SoR:

I have been eagerly awaiting the video but I don’t think it is online
yet. However, there are recorded code demos (minus the sound) in it you
can watch right now.

-Ben

Nice presentation Ben, very good coverage of the process in so limited
time.
Like Stephen I picked some syntax tips that I didn’t know.

Hector

On 11 Apr 2009, at 01:07, James B. wrote:

http://mwrc2009.confreaks.com/14-mar-2009-15-00-bdd-with-cucumber-ben-mabey.html

Great job with the talk Ben, it’s a really good intro to Cucumber and
I will be pointing anyone who asks towards it.

One question about the kitten-killing. I was surprised that defining
methods in your env / step_definition files adds methods to every
instance
of Object. I thought it just added those methods to the
particular instance of Object that’s used to create the World.

Did I misunderstand the you in the talk, or misunderstand the code in
Cucumber?

cheers,
Matt W.

http://blog.mattwynne.net

Maybe not as clear as Ben’s

Aidy

2009/4/11 James B. [email protected]:

Matt W. wrote:

methods in your env / step_definition files adds methods to every
instance
of Object. I thought it just added those methods to the
particular instance of Object that’s used to create the World.

Did I misunderstand the you in the talk, or misunderstand the code in
Cucumber?

Well, the step definitions themselves don’t add themselves to every
instance. The Given, When, and Then methods have actually killed some
kittens and already live on Object (sometimes it is okay). The step
methods will register the passed in blocks to the StepMother-- not onto
Object. So if that is what you are referring to you are correct.

However, if you want to create a ruby helper method then you will need
to wrap it in a module to prevent to from being added to every object
instance. In my example I had something like:

def login_as(user)
visit ‘/login’
fill_in ‘Email’, :with => user.email
fill_in ‘Password’, :with => ‘password’
click_button
end

If you place that method in the top-level in either your env.rb or any
step files it is going to be living on Object since Cucumber will load
up these files as any other ruby file. So you could call #login_as on
an Array or any other object! Definitely not what we want. So, you
need to wrap it in a module and use the World hook to make the helper
methods available only in your World (which you get a new one for every
scenario). With the new World syntax (as of 0.2.3 I believe) it would
be:

module UserHelpers
def login_as(user)
visit ‘/login’
fill_in ‘Email’, :with => user.email
fill_in ‘Password’, :with => ‘password’
click_button
end
end

World(UserHelpers)

I feel like I may of just repeated what I said in the presentation… so
you still may be just as confused. :confused: Let me know if that helps to
clarify things or what part of it is confusing.

-Ben

On 12 Apr 2009, at 16:35, Ben M. wrote:

defining methods in your env / step_definition files adds methods
step methods will register the passed in blocks to the StepMother–
fill_in ‘Password’, :with => ‘password’
0.2.3 I believe) it would be:
World(UserHelpers)

I feel like I may of just repeated what I said in the
presentation… so you still may be just as confused. :confused: Let me
know if that helps to clarify things or what part of it is confusing.

Yeah you did, but I think you’ve made me realise something obvious:
there’s a difference between the ruby you write in the env and step
matchers, and the ruby you write inside the step matchers. It’s the
later that gets evaluated in the context of the World instance, the
former that gets evaluated in the root namespace.

Right?

Matt W.

http://blog.mattwynne.net

Matt W. wrote:

Great job with the talk Ben, it’s a really good intro to Cucumber
Well, the step definitions themselves don’t add themselves to every
def login_as(user)
want. So, you need to wrap it in a module and use the World hook to
end
matchers, and the ruby you write inside the step matchers. It’s the
later that gets evaluated in the context of the World instance, the
former that gets evaluated in the root namespace.

Right?
Correct.

-Ben

On Sun, Apr 12, 2009 at 5:35 PM, Ben M. [email protected] wrote:

will be pointing anyone who asks towards it.
instance. The Given, When, and Then methods have actually killed some
kittens and already live on Object (sometimes it is okay). The step methods
will register the passed in blocks to the StepMother-- not onto Object. So
if that is what you are referring to you are correct.

This isn’t exactly how it works. The Given, When, Then methods (and a
few
others) are defined in the Cucumber::StepMother module. This module is
extended by the Ruby top level object, which is a single instance.
Object is
not altered. Here is an interesting discussion about it:
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/7b023b23385241c7?pli=1

aslak hellesoy wrote:

        http://mwrc2009.confreaks.com/14-mar-2009-15-00-bdd-with-cucumber-ben-mabey.html
    to create the World.

This isn’t exactly how it works. The Given, When, Then methods (and a
few others) are defined in the Cucumber::StepMother module. This
module is extended by the Ruby top level object, which is a single
instance. Object is not altered. Here is an interesting discussion
about it:
http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/7b023b23385241c7?pli=1

Interesting… I knew that the methods started out in
Cucumber::StepMother but I thought they had to be added to every
instance of Object to exhibit the behaviour that they do. That makes
even more sense now-- and it is a very nice technique to know about!
Thanks for clearing up that misunderstanding.

-Ben