[rspec-users] 'And' step definition
lists at ruby-forum.com
Fri Dec 5 21:55:55 EST 2008
Mark Wilden wrote:
> Can you have an And step in a feature? With this, I get a NoMethodError
> Given /a company named (.+)/ do |name|
> @company = Company.create!(:name => name)
> And /a user named (.+)/ do |name|
> @user = create_user name
> I'm probably missing something really obvious.
Given, 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)
When /a user named (.+)/ do |name|
@user = create_user name
While in the feature file you can have:
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/.
More information about the rspec-users