Can you have an And step in a feature? With this, I get a NoMethodError for ''And'': Given /a company named (.+)/ do |name| @company = Company.create!(:name => name) end And /a user named (.+)/ do |name| @user = create_user name end I''m probably missing something really obvious. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081205/1dde454f/attachment.html>
On Fri, Dec 5, 2008 at 8:16 PM, Mark Wilden <mark at mwilden.com> wrote:> Can you have an And step in a feature? With this, I get a NoMethodError for > ''And'': > > Given /a company named (.+)/ do |name| > @company = Company.create!(:name => name) > end > > And /a user named (.+)/ do |name| > @user = create_user name > end > > I''m probably missing something really obvious.And is something the grammar allows in scenarios, but it always maps And (and But) to the last type of Given, When or Then. So what you really have here is a Given step that you are invoking with an alias, And, from the Scenario. Cheers, David> > ///ark > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Mark Wilden wrote:> Can you have an And step in a feature? With this, I get a NoMethodError > for > ''And'': > > Given /a company named (.+)/ do |name| > @company = Company.create!(:name => name) > end > > And /a user named (.+)/ do |name| > @user = create_user name > end > > I''m probably missing something really obvious. > > ///arkGiven, When, Then and And in a feature file are all calls to the same code. You can map any of these in a feature file to a matcher prefaced with any of Given, When and Then in a step definitions file. My current practice is to only use When in the step definitions file as it reads (for me) more naturally. So, in the step definitions file, if you have: When /a company named (.+)/ do |name| @company = Company.create!(:name => name) end When /a user named (.+)/ do |name| @user = create_user name end While in the feature file you can have: Scenario Given a company named Acme And a company named Pinnacle When a user named Smith Then a company named Zenith And a user named Doe and all of these will match one of the two step definitions given above. -- Posted via http://www.ruby-forum.com/.
Thanks for your replies, David and James. I figured as much, actually, since you wouldn''t want to have some And steps in your definition file and some Given steps. I was led astray by "Inside a step_definitions.rb file, steps (which strictly speaking should always be called step definitions) refers to the * matcher* methods, given exactly the same names (Given, When, Then, or And), each provided with a matcher regexp that corresponds to one or more feature steps" in James''s backgrounder. Maybe I misunderstood it. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081205/7ee1074c/attachment.html>
Mark Wilden wrote:> Thanks for your replies, David and James. I figured as much, actually, > since > you wouldn''t want to have some And steps in your definition file and > some > Given steps. > > I was led astray by "Inside a step_definitions.rb file, steps (which > strictly speaking should always be called step definitions) refers to > the * > matcher* methods, given exactly the same names (Given, When, Then, or > And), > each provided with a matcher regexp that corresponds to one or more > feature > steps" in James''s backgrounder. Maybe I misunderstood it. >That aspect of cucumber, that Given == When == Then, is elaborated later in the article but I have added further clarification at that point as well. -- Posted via http://www.ruby-forum.com/.