Skip to content

Commit 2857198

Browse files
LindseyLindseyB
authored andcommitted
Setup all the test stuff.
1 parent 370f435 commit 2857198

7 files changed

Lines changed: 279 additions & 0 deletions

File tree

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ gem "rspec"
55
gem "cucumber"
66
gem "webrat"
77
gem "mongo_mapper"
8+
gem "cucumber-sinatra"
9+
gem "capybara"
10+
gem "factory_girl"

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'rubygems'
2+
require 'spec/rake/spectask'
3+
Spec::Rake::SpecTask.new do |t|
4+
t.spec_files = FileList['spec/*_spec.rb',]
5+
end

factories/.gitignore

Whitespace-only changes.
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# Taken from the cucumber-rails project.
2+
# IMPORTANT: This file is generated by cucumber-sinatra - edit at your own peril.
3+
# It is recommended to regenerate this file in the future when you upgrade to a
4+
# newer version of cucumber-sinatra. Consider adding your own code to a new file
5+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
6+
# files.
7+
8+
require 'uri'
9+
require 'cgi'
10+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
11+
12+
module WithinHelpers
13+
def with_scope(locator)
14+
locator ? within(locator) { yield } : yield
15+
end
16+
end
17+
World(WithinHelpers)
18+
19+
Given /^(?:|I )am on (.+)$/ do |page_name|
20+
visit path_to(page_name)
21+
end
22+
23+
When /^(?:|I )go to (.+)$/ do |page_name|
24+
visit path_to(page_name)
25+
end
26+
27+
When /^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/ do |button, selector|
28+
with_scope(selector) do
29+
click_button(button)
30+
end
31+
end
32+
33+
When /^(?:|I )follow "([^\"]*)"(?: within "([^\"]*)")?$/ do |link, selector|
34+
with_scope(selector) do
35+
click_link(link)
36+
end
37+
end
38+
39+
When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, value, selector|
40+
with_scope(selector) do
41+
fill_in(field, :with => value)
42+
end
43+
end
44+
45+
When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
46+
with_scope(selector) do
47+
fill_in(field, :with => value)
48+
end
49+
end
50+
51+
# Use this to fill in an entire form with data from a table. Example:
52+
#
53+
# When I fill in the following:
54+
# | Account Number | 5002 |
55+
# | Expiry date | 2009-11-01 |
56+
# | Note | Nice guy |
57+
# | Wants Email? | |
58+
#
59+
# TODO: Add support for checkbox, select og option
60+
# based on naming conventions.
61+
#
62+
When /^(?:|I )fill in the following(?: within "([^\"]*)")?:$/ do |selector, fields|
63+
with_scope(selector) do
64+
fields.rows_hash.each do |name, value|
65+
When %{I fill in "#{name}" with "#{value}"}
66+
end
67+
end
68+
end
69+
70+
When /^(?:|I )select "([^\"]*)" from "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
71+
with_scope(selector) do
72+
select(value, :from => field)
73+
end
74+
end
75+
76+
When /^(?:|I )check "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
77+
with_scope(selector) do
78+
check(field)
79+
end
80+
end
81+
82+
When /^(?:|I )uncheck "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
83+
with_scope(selector) do
84+
uncheck(field)
85+
end
86+
end
87+
88+
When /^(?:|I )choose "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
89+
with_scope(selector) do
90+
choose(field)
91+
end
92+
end
93+
94+
When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
95+
with_scope(selector) do
96+
attach_file(field, path)
97+
end
98+
end
99+
100+
Then /^(?:|I )should see JSON:$/ do |expected_json|
101+
require 'json'
102+
expected = JSON.pretty_generate(JSON.parse(expected_json))
103+
actual = JSON.pretty_generate(JSON.parse(response.body))
104+
expected.should == actual
105+
end
106+
107+
Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
108+
with_scope(selector) do
109+
if page.respond_to? :should
110+
page.should have_content(text)
111+
else
112+
assert page.has_content?(text)
113+
end
114+
end
115+
end
116+
117+
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
118+
regexp = Regexp.new(regexp)
119+
with_scope(selector) do
120+
if page.respond_to? :should
121+
page.should have_xpath('//*', :text => regexp)
122+
else
123+
assert page.has_xpath?('//*', :text => regexp)
124+
end
125+
end
126+
end
127+
128+
Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
129+
with_scope(selector) do
130+
if page.respond_to? :should
131+
page.should have_no_content(text)
132+
else
133+
assert page.has_no_content?(text)
134+
end
135+
end
136+
end
137+
138+
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
139+
regexp = Regexp.new(regexp)
140+
with_scope(selector) do
141+
if page.respond_to? :should
142+
page.should have_no_xpath('//*', :text => regexp)
143+
else
144+
assert page.has_no_xpath?('//*', :text => regexp)
145+
end
146+
end
147+
end
148+
149+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value|
150+
with_scope(selector) do
151+
field = find_field(field)
152+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
153+
if field_value.respond_to? :should
154+
field_value.should =~ /#{value}/
155+
else
156+
assert_match(/#{value}/, field_value)
157+
end
158+
end
159+
end
160+
161+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should not contain "([^\"]*)"$/ do |field, selector, value|
162+
with_scope(selector) do
163+
field = find_field(field)
164+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
165+
if field_value.respond_to? :should_not
166+
field_value.should_not =~ /#{value}/
167+
else
168+
assert_no_match(/#{value}/, field_value)
169+
end
170+
end
171+
end
172+
173+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |label, selector|
174+
with_scope(selector) do
175+
field_checked = find_field(label)['checked']
176+
if field_checked.respond_to? :should
177+
field_checked.should == 'checked'
178+
else
179+
assert_equal 'checked', field_checked
180+
end
181+
end
182+
end
183+
184+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
185+
with_scope(selector) do
186+
field_checked = find_field(label)['checked']
187+
if field_checked.respond_to? :should_not
188+
field_checked.should_not == 'checked'
189+
else
190+
assert_not_equal 'checked', field_checked
191+
end
192+
end
193+
end
194+
195+
Then /^(?:|I )should be on (.+)$/ do |page_name|
196+
current_path = URI.parse(current_url).path
197+
if current_path.respond_to? :should
198+
current_path.should == path_to(page_name)
199+
else
200+
assert_equal path_to(page_name), current_path
201+
end
202+
end
203+
204+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
205+
query = URI.parse(current_url).query
206+
actual_params = query ? CGI.parse(query) : {}
207+
expected_params = {}
208+
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
209+
210+
if actual_params.respond_to? :should
211+
actual_params.should == expected_params
212+
else
213+
assert_equal expected_params, actual_params
214+
end
215+
end
216+
217+
Then /^show me the page$/ do
218+
save_and_open_page
219+
end

features/support/env.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by cucumber-sinatra. (Sat Jul 10 15:46:03 -0400 2010)
2+
3+
require File.join(File.dirname(__FILE__), '..', '..', 'hackety.rb')
4+
5+
require 'capybara'
6+
require 'capybara/cucumber'
7+
require 'spec'
8+
9+
Hackety.set(:environment, :test)
10+
11+
World do
12+
Capybara.app = Hackety
13+
include Capybara
14+
include Spec::Expectations
15+
include Spec::Matchers
16+
end
17+
18+
require 'factory_girl'
19+
Dir.glob(File.join(File.dirname(__FILE__), '..', '..', '/factories/*.rb')).each do |factory|
20+
require factory
21+
end
22+
23+

features/support/paths.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Taken from the cucumber-rails project.
2+
3+
module NavigationHelpers
4+
# Maps a name to a path. Used by the
5+
#
6+
# When /^I go to (.+)$/ do |page_name|
7+
#
8+
# step definition in web_steps.rb
9+
#
10+
def path_to(page_name)
11+
case page_name
12+
13+
when /the home\s?page/
14+
'/'
15+
16+
# Add more mappings here.
17+
# Here is an example that pulls values out of the Regexp:
18+
#
19+
# when /^(.*)'s profile page$/i
20+
# user_profile_path(User.find_by_login($1))
21+
22+
else
23+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
24+
"Now, go and add a mapping in #{__FILE__}"
25+
end
26+
end
27+
end
28+
29+
World(NavigationHelpers)

spec/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)