timriley (owner)

Revisions

gist: 110054 Download_button fork
public
Public Clone URL: git://gist.github.com/110054.git
Embed All Files: show embed
generic_steps.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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 => "bob@bob.com"}
# Then response 302 to /feedback/thanks?reply=true
# And contact@agencyrainford.com 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