I finally found some time to mess with cucumber, its pretty nice but has some edges and quircks… but for now i like it 🙂
Install
This was rather hard… (these libraries and frex should not be necessary for mac)
sudo apt-get install libxslt1-dev libxml2-dev racc sudo gem install aaronp-frex brynary-webrat sudo gem install cucumber ./script/generate cucumber rake features
First story
#features/signup.feature Feature: Signup Scenario: A new user comes to the page and wants to register. Given I am on "/" When I click "register" And I fill in "user[name]" with "Michael G" And I fill in "Email" with "test@test.de" And I fill in "Password" with "test" And I fill in "Password confirmation" with "test" And I press "Register for the free basic account" Then I should be on "/" And I should be logged in And I should see a flash about "activation"
Environment setup
#append to features/support/env.rb #load all fixtures -- https://pragmatig.wordpress.com/2008/12/25/load-all-fixtures-when-not-in-test/ include AuthenticatedTestHelper # restful authentification include RspecResponseEnhancer # https://pragmatig.wordpress.com/2008/04/20/rspec-responseshould-information-enhancers/
Common steps
There is a nice collection of steps already available in steps/webrat_steps, but some basics where missing….
#features/step_definitions/common_steps.rb When /^I click "(.*)"$/ do |link| click_link(link) end When /^I am on "(.*)"$/ do |path| header('Accept-Language','EN-en') visit path end Then /^I should be on "(.*)"$/ do |path| response.request.request_uri.should == path end Then /^I should see a flash about "(.*)"/ do |message| doc.search('div.flash_notice').inner_html.include?(message).should be_true end Then /^I should be logged in$/ do should be_logged_in end def doc Hpricot(response.body) end
Output
rake features Feature: Signup # features/signup.feature Scenario: A new user comes to the page and wants to register. # features/signup.feature:2 Given I am on "/" # features/step_definitions/common_steps.rb:6 When I click register # features/step_definitions/common_steps.rb:1 And I fill in "user[name]" with "Michael G" # features/step_definitions/webrat_steps.rb:12 And I fill in "Email" with "test@test.de" # features/step_definitions/webrat_steps.rb:12 And I fill in "Password" with "test" # features/step_definitions/webrat_steps.rb:12 And I fill in "Password confirmation" with "test" # features/step_definitions/webrat_steps.rb:12 And I press "Register for the free basic account" # features/step_definitions/webrat_steps.rb:4 Then I should be on "/" # features/step_definitions/common_steps.rb:11 And I should be logged in # features/step_definitions/common_steps.rb:19 And I should see a flash about "activation" # features/step_definitions/common_steps.rb:15 10 steps passed
Feels great to write stories again, sadly takes more time then unit tests, but the readability is superb! IMO a very nice way of doing integration tests…
Just a quick note — Unless you’re looking for something specific that’s not in my webrat repository (if so, please open a ticket and lets talk about it), it might be best to clone from my Webrat repository where I’m regularly pushing updates.
http://github.com/brynary/webrat
Cheers,
-Bryan
Thanks for the tip, when i looked yesterday i got a 404 from github so i went for the next best think on google 🙂
BTW: thanks for this great tool 😉
Why are you including racc and aaronp-frex? Is it anything to do with RspecResponseEnhancer.
What do these things do? I’ve not seen them in other Cucumber tutorials.
They were required to get it working for ubuntu, I think they are not needed for mac, ill add that, thanks for the tip.