Forum: RSpec Cucumber - Recommended viewing.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-04-11 02:07
994e42bda994be2cd1d791f18ee6d561?d=identicon&s=25 Stephen Eley (Guest)
on 2009-04-11 05:11
(Received via mailing list)
On Fri, Apr 10, 2009 at 8:07 PM, James Byrne <lists@ruby-forum.com>
wrote:
> http://mwrc2009.confreaks.com/14-mar-2009-15-00-bd...

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 Eley (sfeley@gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-04-11 07:38
(Received via mailing list)
Stephen Eley wrote:
> syntax tricks I'd never picked up on.
>
> Great job, Ben!
>
>

Thanks!

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

http://blog.josephwilk.net/ruby/outside-in-develop...

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
0b8749d1e2ad3c2c2b7418fc694fab5e?d=identicon&s=25 Hector Gomez (Guest)
on 2009-04-11 23:00
(Received via mailing list)
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
Ee6788c2faaad7a5cd0bc466c9ea60d8?d=identicon&s=25 aidy lewis (Guest)
on 2009-04-11 23:51
(Received via mailing list)
Maybe not as clear as Ben's

http://skillsmatter.com/podcast/ajax-ria/cucumber-...

Aidy

2009/4/11 James Byrne <lists@ruby-forum.com>:
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-04-12 14:43
(Received via mailing list)
On 11 Apr 2009, at 01:07, James Byrne wrote:

> http://mwrc2009.confreaks.com/14-mar-2009-15-00-bd...

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 Wynne
http://beta.songkick.com
http://blog.mattwynne.net
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-04-12 17:37
(Received via mailing list)
Matt Wynne 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. :/  Let me know if that helps to
clarify things or what part of it is confusing.

-Ben
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-04-12 18:16
(Received via mailing list)
On 12 Apr 2009, at 16:35, Ben Mabey 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. :/  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 Wynne
http://beta.songkick.com
http://blog.mattwynne.net
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-04-13 00:22
(Received via mailing list)
Matt Wynne 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
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-04-13 07:58
(Received via mailing list)
On Sun, Apr 12, 2009 at 5:35 PM, Ben Mabey <ben@benmabey.com> 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/brow...
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2009-04-13 08:36
(Received via mailing list)
aslak hellesoy wrote:
> 
http://mwrc2009.confreaks.com/14-mar-2009-15-00-bd...
>         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/brow...

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
This topic is locked and can not be replied to.