cucumber-sinatra 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.md +9 -0
- data/README.md +4 -2
- data/Rakefile +1 -1
- data/cucumber-sinatra.gemspec +5 -2
- data/lib/cucumber/sinatra/generators.rb +2 -2
- data/lib/cucumber/sinatra/templates/features/step_definitions/web_steps.rbt +218 -0
- data/lib/cucumber/sinatra/templates/features/support/paths.rbt +27 -0
- data/lib/cucumber/sinatra.rb +1 -1
- metadata +6 -3
data/CHANGES.md
ADDED
data/README.md
CHANGED
@@ -20,8 +20,9 @@ It's available as a gem that can be installed with the following command.
|
|
20
20
|
To initialize the cucumber environment, just execute `cucumber-sinatra` like this:
|
21
21
|
|
22
22
|
# cucumber-sinatra init MyApp lib/my_app.rb
|
23
|
-
[ADDED] features/step_definitions
|
24
23
|
[ADDED] features/support/env.rb
|
24
|
+
[ADDED] features/support/paths.rb
|
25
|
+
[ADDED] features/step_definitions/web_steps.rb
|
25
26
|
#
|
26
27
|
|
27
28
|
* The first argument is the class name of your application.
|
@@ -31,8 +32,9 @@ Using the `--app` option with `init` will also generate the given application fi
|
|
31
32
|
and a working `config.ru`.
|
32
33
|
|
33
34
|
# cucumber-sinatra init --app MyApp lib/my_app.rb
|
34
|
-
[ADDED] features/step_definitions
|
35
35
|
[ADDED] features/support/env.rb
|
36
|
+
[ADDED] features/support/paths.rb
|
37
|
+
[ADDED] features/step_definitions/web_steps.rb
|
36
38
|
[ADDED] lib/my_app.rb
|
37
39
|
[ADDED] config.ru
|
38
40
|
#
|
data/Rakefile
CHANGED
@@ -100,7 +100,7 @@ task :release => :build do
|
|
100
100
|
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
101
101
|
sh "git tag v#{version}"
|
102
102
|
sh "git push origin master"
|
103
|
-
sh "git push v#{version}"
|
103
|
+
sh "git push origin tag v#{version}"
|
104
104
|
sh "gem push pkg/#{name}-#{version}.gem"
|
105
105
|
end
|
106
106
|
|
data/cucumber-sinatra.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
|
|
7
7
|
## If your rubyforge_project name is different, then edit it and comment out
|
8
8
|
## the sub! line in the Rakefile
|
9
9
|
s.name = 'cucumber-sinatra'
|
10
|
-
s.version = '0.
|
11
|
-
s.date = '2010-05-
|
10
|
+
s.version = '0.2.0'
|
11
|
+
s.date = '2010-05-26'
|
12
12
|
s.rubyforge_project = 'cucumber-sinatra'
|
13
13
|
|
14
14
|
s.summary = "Initialize a cucumber environment for sinatra"
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
|
33
33
|
# = MANIFEST =
|
34
34
|
s.files = %w[
|
35
|
+
CHANGES.md
|
35
36
|
LICENSE
|
36
37
|
README.md
|
37
38
|
Rakefile
|
@@ -41,7 +42,9 @@ Gem::Specification.new do |s|
|
|
41
42
|
lib/cucumber/sinatra/generators.rb
|
42
43
|
lib/cucumber/sinatra/templates/app.rbt
|
43
44
|
lib/cucumber/sinatra/templates/config.ru
|
45
|
+
lib/cucumber/sinatra/templates/features/step_definitions/web_steps.rbt
|
44
46
|
lib/cucumber/sinatra/templates/features/support/env.rbt
|
47
|
+
lib/cucumber/sinatra/templates/features/support/paths.rbt
|
45
48
|
]
|
46
49
|
# = MANIFEST =
|
47
50
|
|
@@ -21,11 +21,11 @@ module Cucumber
|
|
21
21
|
option :app, :as => :boolean, :default => false, :desc => 'Create the application files as well.'
|
22
22
|
|
23
23
|
template :env, 'features/support/env.rb'
|
24
|
+
template :paths, 'features/support/paths.rb'
|
25
|
+
template :steps, 'features/step_definitions/web_steps.rb'
|
24
26
|
template :app_file, 'app.rbt', '%app_file_path%', :app => true
|
25
27
|
template :rackup_file, 'config.ru', 'config.ru', :app => true
|
26
28
|
|
27
|
-
empty_directory :step_definitions, 'features/step_definitions'
|
28
|
-
|
29
29
|
def app_file_path
|
30
30
|
app_file
|
31
31
|
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
# IMPORTANT: This file is generated by cucumber-sinatra - edit at your own peril.
|
2
|
+
# It is recommended to regenerate this file in the future when you upgrade to a
|
3
|
+
# newer version of cucumber-sinatra. Consider adding your own code to a new file
|
4
|
+
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
5
|
+
# files.
|
6
|
+
|
7
|
+
require 'uri'
|
8
|
+
require 'cgi'
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
10
|
+
|
11
|
+
module WithinHelpers
|
12
|
+
def with_scope(locator)
|
13
|
+
locator ? within(locator) { yield } : yield
|
14
|
+
end
|
15
|
+
end
|
16
|
+
World(WithinHelpers)
|
17
|
+
|
18
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
19
|
+
visit path_to(page_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
23
|
+
visit path_to(page_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
When /^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/ do |button, selector|
|
27
|
+
with_scope(selector) do
|
28
|
+
click_button(button)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
When /^(?:|I )follow "([^\"]*)"(?: within "([^\"]*)")?$/ do |link, selector|
|
33
|
+
with_scope(selector) do
|
34
|
+
click_link(link)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, value, selector|
|
39
|
+
with_scope(selector) do
|
40
|
+
fill_in(field, :with => value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
|
45
|
+
with_scope(selector) do
|
46
|
+
fill_in(field, :with => value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Use this to fill in an entire form with data from a table. Example:
|
51
|
+
#
|
52
|
+
# When I fill in the following:
|
53
|
+
# | Account Number | 5002 |
|
54
|
+
# | Expiry date | 2009-11-01 |
|
55
|
+
# | Note | Nice guy |
|
56
|
+
# | Wants Email? | |
|
57
|
+
#
|
58
|
+
# TODO: Add support for checkbox, select og option
|
59
|
+
# based on naming conventions.
|
60
|
+
#
|
61
|
+
When /^(?:|I )fill in the following(?: within "([^\"]*)")?:$/ do |selector, fields|
|
62
|
+
with_scope(selector) do
|
63
|
+
fields.rows_hash.each do |name, value|
|
64
|
+
When %{I fill in "#{name}" with "#{value}"}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
When /^(?:|I )select "([^\"]*)" from "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
|
70
|
+
with_scope(selector) do
|
71
|
+
select(value, :from => field)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
When /^(?:|I )check "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
76
|
+
with_scope(selector) do
|
77
|
+
check(field)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
When /^(?:|I )uncheck "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
82
|
+
with_scope(selector) do
|
83
|
+
uncheck(field)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
When /^(?:|I )choose "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector|
|
88
|
+
with_scope(selector) do
|
89
|
+
choose(field)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
|
94
|
+
with_scope(selector) do
|
95
|
+
attach_file(field, path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
Then /^(?:|I )should see JSON:$/ do |expected_json|
|
100
|
+
require 'json'
|
101
|
+
expected = JSON.pretty_generate(JSON.parse(expected_json))
|
102
|
+
actual = JSON.pretty_generate(JSON.parse(response.body))
|
103
|
+
expected.should == actual
|
104
|
+
end
|
105
|
+
|
106
|
+
Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
|
107
|
+
with_scope(selector) do
|
108
|
+
if page.respond_to? :should
|
109
|
+
page.should have_content(text)
|
110
|
+
else
|
111
|
+
assert page.has_content?(text)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
|
117
|
+
regexp = Regexp.new(regexp)
|
118
|
+
with_scope(selector) do
|
119
|
+
if page.respond_to? :should
|
120
|
+
page.should have_xpath('//*', :text => regexp)
|
121
|
+
else
|
122
|
+
assert page.has_xpath?('//*', :text => regexp)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
|
128
|
+
with_scope(selector) do
|
129
|
+
if page.respond_to? :should
|
130
|
+
page.should have_no_content(text)
|
131
|
+
else
|
132
|
+
assert page.has_no_content?(text)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector|
|
138
|
+
regexp = Regexp.new(regexp)
|
139
|
+
with_scope(selector) do
|
140
|
+
if page.respond_to? :should
|
141
|
+
page.should have_no_xpath('//*', :text => regexp)
|
142
|
+
else
|
143
|
+
assert page.has_no_xpath?('//*', :text => regexp)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value|
|
149
|
+
with_scope(selector) do
|
150
|
+
field = find_field(field)
|
151
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
152
|
+
if field_value.respond_to? :should
|
153
|
+
field_value.should =~ /#{value}/
|
154
|
+
else
|
155
|
+
assert_match(/#{value}/, field_value)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should not contain "([^\"]*)"$/ do |field, selector, value|
|
161
|
+
with_scope(selector) do
|
162
|
+
field = find_field(field)
|
163
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
164
|
+
if field_value.respond_to? :should_not
|
165
|
+
field_value.should_not =~ /#{value}/
|
166
|
+
else
|
167
|
+
assert_no_match(/#{value}/, field_value)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |label, selector|
|
173
|
+
with_scope(selector) do
|
174
|
+
field_checked = find_field(label)['checked']
|
175
|
+
if field_checked.respond_to? :should
|
176
|
+
field_checked.should == 'checked'
|
177
|
+
else
|
178
|
+
assert_equal 'checked', field_checked
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector|
|
184
|
+
with_scope(selector) do
|
185
|
+
field_checked = find_field(label)['checked']
|
186
|
+
if field_checked.respond_to? :should_not
|
187
|
+
field_checked.should_not == 'checked'
|
188
|
+
else
|
189
|
+
assert_not_equal 'checked', field_checked
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
195
|
+
current_path = URI.parse(current_url).path
|
196
|
+
if current_path.respond_to? :should
|
197
|
+
current_path.should == path_to(page_name)
|
198
|
+
else
|
199
|
+
assert_equal path_to(page_name), current_path
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
204
|
+
query = URI.parse(current_url).query
|
205
|
+
actual_params = query ? CGI.parse(query) : {}
|
206
|
+
expected_params = {}
|
207
|
+
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
208
|
+
|
209
|
+
if actual_params.respond_to? :should
|
210
|
+
actual_params.should == expected_params
|
211
|
+
else
|
212
|
+
assert_equal expected_params, actual_params
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
Then /^show me the page$/ do
|
217
|
+
save_and_open_page
|
218
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module NavigationHelpers
|
2
|
+
# Maps a name to a path. Used by the
|
3
|
+
#
|
4
|
+
# When /^I go to (.+)$/ do |page_name|
|
5
|
+
#
|
6
|
+
# step definition in web_steps.rb
|
7
|
+
#
|
8
|
+
def path_to(page_name)
|
9
|
+
case page_name
|
10
|
+
|
11
|
+
when /the home\s?page/
|
12
|
+
'/'
|
13
|
+
|
14
|
+
# Add more mappings here.
|
15
|
+
# Here is an example that pulls values out of the Regexp:
|
16
|
+
#
|
17
|
+
# when /^(.*)'s profile page$/i
|
18
|
+
# user_profile_path(User.find_by_login($1))
|
19
|
+
|
20
|
+
else
|
21
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
22
|
+
"Now, go and add a mapping in #{__FILE__}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
World(NavigationHelpers)
|
data/lib/cucumber/sinatra.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Bernd Ahlers
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-26 00:00:00 +02:00
|
18
18
|
default_executable: cucumber-sinatra
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,7 @@ extra_rdoc_files:
|
|
41
41
|
- README.md
|
42
42
|
- LICENSE
|
43
43
|
files:
|
44
|
+
- CHANGES.md
|
44
45
|
- LICENSE
|
45
46
|
- README.md
|
46
47
|
- Rakefile
|
@@ -50,7 +51,9 @@ files:
|
|
50
51
|
- lib/cucumber/sinatra/generators.rb
|
51
52
|
- lib/cucumber/sinatra/templates/app.rbt
|
52
53
|
- lib/cucumber/sinatra/templates/config.ru
|
54
|
+
- lib/cucumber/sinatra/templates/features/step_definitions/web_steps.rbt
|
53
55
|
- lib/cucumber/sinatra/templates/features/support/env.rbt
|
56
|
+
- lib/cucumber/sinatra/templates/features/support/paths.rbt
|
54
57
|
has_rdoc: true
|
55
58
|
homepage: http://github.com/bernd/cucumber-sinatra
|
56
59
|
licenses: []
|