Created
May 6, 2009 15:26
-
-
Save toolmantim/107554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example of simplifying Cucumber stories by assuming you can read simple Ruby structures | |
| # | |
| # Used in my presentation: | |
| # | |
| # http://www.slideshare.net/toolmantim/roro-may-lightning-preso-madness | |
| # | |
| # Use them like so: | |
| # | |
| # Feature: Feedback form | |
| # | |
| # Scenario: submitting feedback w/ an email address | |
| # Given logged in | |
| # When post /feedback with {:email => "[email protected]"} | |
| # Then response 302 to /feedback/thanks?reply=true | |
| # And [email protected] receives an email | |
| When /^get (.+)/ do |path| | |
| get path | |
| end | |
| When /^post ([^\s]+)$/ do |path| | |
| post path | |
| end | |
| When /^post ([^\s]+) with (\{.*\})$/ do |path, params| | |
| post path, eval(params) | |
| end | |
| Then /^response (\d+)$/ do |code| | |
| begin | |
| status.should == code.to_i | |
| rescue Spec::Expectations::ExpectationNotMetError | |
| STDERR.puts response.body | |
| raise | |
| end | |
| end | |
| Then /^response 302 to (.*)$/ do |path| | |
| Then "response 302" | |
| response.location.should == "http://www.example.com#{path}" | |
| end | |
| Then /^body includes "(.+)"$/ do |str| | |
| body.should include(str) | |
| end | |
| Then /^body has tag (.*)$/ do |selector| | |
| if Hpricot(response.body).search(selector).empty? | |
| STDERR.puts response.body | |
| raise "Could not find selector #{selector} in response body" | |
| end | |
| end | |
| Then /^body doesn't include "(.+)"$/ do |str| | |
| body.should_not include(str) | |
| end | |
| Then /^a (.*) exists with (\{.*\})$/ do |class_name, attributes| | |
| begin | |
| eval(class_name).exists?(eval(attributes)).should be_true | |
| rescue Spec::Expectations::ExpectationNotMetError | |
| STDERR.puts "#{class_name}.all " + eval(class_name).all.inspect | |
| raise | |
| end | |
| end | |
| Given /^there is a (.*) with (\{.*\})$/ do |class_name, attributes| | |
| eval(class_name).make(eval(attributes)) | |
| end | |
| Then /^(.*) receives an email$/ do |email| | |
| ActionMailer::Base.deliveries.first.to.should == [email] | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment