cucumber-rails-training-wheels 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +156 -0
  4. data/README.md +29 -0
  5. data/Rakefile +10 -0
  6. data/cucumber-rails-training-wheels.gemspec +25 -0
  7. data/features/step_defintions/rails_steps.rb +21 -0
  8. data/features/support/env.rb +8 -0
  9. data/features/use_training_wheels.feature +17 -0
  10. data/lib/generators/cucumber_rails_training_wheels/feature/USAGE +16 -0
  11. data/lib/generators/cucumber_rails_training_wheels/feature/feature_generator.rb +27 -0
  12. data/lib/generators/cucumber_rails_training_wheels/feature/named_arg.rb +20 -0
  13. data/lib/generators/cucumber_rails_training_wheels/feature/templates/feature.erb +63 -0
  14. data/lib/generators/cucumber_rails_training_wheels/feature/templates/steps.erb +14 -0
  15. data/lib/generators/cucumber_rails_training_wheels/install/USAGE +15 -0
  16. data/lib/generators/cucumber_rails_training_wheels/install/install_generator.rb +33 -0
  17. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps.rb.erb +235 -0
  18. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps_cs.rb.erb +127 -0
  19. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps_da.rb.erb +105 -0
  20. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps_de.rb.erb +127 -0
  21. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps_es.rb.erb +127 -0
  22. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps_ja.rb.erb +140 -0
  23. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps_ko.rb.erb +142 -0
  24. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps_no.rb.erb +105 -0
  25. data/lib/generators/cucumber_rails_training_wheels/install/templates/step_definitions/web_steps_pt-BR.rb.erb +132 -0
  26. data/lib/generators/cucumber_rails_training_wheels/install/templates/support/paths.rb +38 -0
  27. data/lib/generators/cucumber_rails_training_wheels/install/templates/support/selectors.rb +44 -0
  28. data/lib/generators/cucumber_rails_training_wheels/install/templates/support/web_steps_warning.txt +19 -0
  29. data/lib/generators/cucumber_rails_training_wheels/install/templates/tasks/cucumber.rake.erb +60 -0
  30. metadata +148 -0
@@ -0,0 +1,33 @@
1
+ module CucumberRailsTrainingWheels
2
+ class InstallGenerator < ::Rails::Generators::Base
3
+ source_root File.expand_path("../templates", __FILE__)
4
+ argument :language, :type => :string, :banner => "LANG", :optional => true
5
+
6
+ def create_env_steps
7
+ empty_directory 'features/step_definitions'
8
+
9
+ if language
10
+ template "step_definitions/web_steps_#{language}.rb.erb", "features/step_definitions/web_steps.rb"
11
+ else
12
+ template "step_definitions/web_steps.rb.erb", 'features/step_definitions/web_steps.rb'
13
+ end
14
+ end
15
+
16
+ def create_feature_support
17
+ empty_directory 'features/support'
18
+ copy_file 'support/paths.rb', 'features/support/paths.rb'
19
+ copy_file 'support/selectors.rb', 'features/support/selectors.rb'
20
+ end
21
+
22
+ protected
23
+
24
+ def embed_file(source, indent='')
25
+ IO.read(File.join(self.class.source_root, source)).gsub(/^/, indent)
26
+ end
27
+
28
+ def embed_template(source, indent='')
29
+ template = File.join(self.class.source_root, source)
30
+ ERB.new(IO.read(template), nil, '-').result(binding).gsub(/^/, indent)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,235 @@
1
+ <%= embed_file('support/web_steps_warning.txt') %>
2
+
3
+ require 'uri'
4
+ require 'cgi'
5
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
6
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
7
+
8
+ module WithinHelpers
9
+ def with_scope(locator)
10
+ locator ? within(*selector_for(locator)) { yield } : yield
11
+ end
12
+ end
13
+ World(WithinHelpers)
14
+
15
+ # Single-line step scoper
16
+ When /^(.*) within (.*[^:])$/ do |step, parent|
17
+ with_scope(parent) { When step }
18
+ end
19
+
20
+ # Multi-line step scoper
21
+ When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
22
+ with_scope(parent) { When "#{step}:", table_or_string }
23
+ end
24
+
25
+ Given /^(?:|I )am on (.+)$/ do |page_name|
26
+ visit path_to(page_name)
27
+ end
28
+
29
+ When /^(?:|I )go to (.+)$/ do |page_name|
30
+ visit path_to(page_name)
31
+ end
32
+
33
+ When /^(?:|I )press "([^"]*)"$/ do |button|
34
+ click_button(button)
35
+ end
36
+
37
+ When /^(?:|I )follow "([^"]*)"$/ do |link|
38
+ click_link(link)
39
+ end
40
+
41
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
42
+ fill_in(field, :with => value)
43
+ end
44
+
45
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
46
+ fill_in(field, :with => value)
47
+ end
48
+
49
+ # Use this to fill in an entire form with data from a table. Example:
50
+ #
51
+ # When I fill in the following:
52
+ # | Account Number | 5002 |
53
+ # | Expiry date | 2009-11-01 |
54
+ # | Note | Nice guy |
55
+ # | Wants Email? | |
56
+ #
57
+ # TODO: Add support for checkbox, select or option
58
+ # based on naming conventions.
59
+ #
60
+ When /^(?:|I )fill in the following:$/ do |fields|
61
+ fields.rows_hash.each do |name, value|
62
+ When %{I fill in "#{name}" with "#{value}"}
63
+ end
64
+ end
65
+
66
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
67
+ select(value, :from => field)
68
+ end
69
+
70
+ When /^(?:|I )check "([^"]*)"$/ do |field|
71
+ check(field)
72
+ end
73
+
74
+ When /^(?:|I )uncheck "([^"]*)"$/ do |field|
75
+ uncheck(field)
76
+ end
77
+
78
+ When /^(?:|I )choose "([^"]*)"$/ do |field|
79
+ choose(field)
80
+ end
81
+
82
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
83
+ attach_file(field, File.expand_path(path))
84
+ end
85
+
86
+ Then /^(?:|I )should see "([^"]*)"$/ do |text|
87
+ if page.respond_to? :should
88
+ page.should have_content(text)
89
+ else
90
+ assert page.has_content?(text)
91
+ end
92
+ end
93
+
94
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
95
+ regexp = Regexp.new(regexp)
96
+
97
+ if page.respond_to? :should
98
+ page.should have_xpath('//*', :text => regexp)
99
+ else
100
+ assert page.has_xpath?('//*', :text => regexp)
101
+ end
102
+ end
103
+
104
+ Then /^(?:|I )should not see "([^"]*)"$/ do |text|
105
+ if page.respond_to? :should
106
+ page.should have_no_content(text)
107
+ else
108
+ assert page.has_no_content?(text)
109
+ end
110
+ end
111
+
112
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
113
+ regexp = Regexp.new(regexp)
114
+
115
+ if page.respond_to? :should
116
+ page.should have_no_xpath('//*', :text => regexp)
117
+ else
118
+ assert page.has_no_xpath?('//*', :text => regexp)
119
+ end
120
+ end
121
+
122
+ Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
123
+ with_scope(parent) do
124
+ field = find_field(field)
125
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
126
+ if field_value.respond_to? :should
127
+ field_value.should =~ /#{value}/
128
+ else
129
+ assert_match(/#{value}/, field_value)
130
+ end
131
+ end
132
+ end
133
+
134
+ Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
135
+ with_scope(parent) do
136
+ field = find_field(field)
137
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
138
+ if field_value.respond_to? :should_not
139
+ field_value.should_not =~ /#{value}/
140
+ else
141
+ assert_no_match(/#{value}/, field_value)
142
+ end
143
+ end
144
+ end
145
+
146
+ Then /^the "([^"]*)" field should have the error "([^"]*)"$/ do |field, error_message|
147
+ element = find_field(field)
148
+ classes = element.find(:xpath, '..')[:class].split(' ')
149
+
150
+ form_for_input = element.find(:xpath, 'ancestor::form[1]')
151
+ using_formtastic = form_for_input[:class].include?('formtastic')
152
+ error_class = using_formtastic ? 'error' : 'field_with_errors'
153
+
154
+ if classes.respond_to? :should
155
+ classes.should include(error_class)
156
+ else
157
+ assert classes.include?(error_class)
158
+ end
159
+
160
+ if page.respond_to?(:should)
161
+ if using_formtastic
162
+ error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]')
163
+ error_paragraph.should have_content(error_message)
164
+ else
165
+ page.should have_content("#{field.titlecase} #{error_message}")
166
+ end
167
+ else
168
+ if using_formtastic
169
+ error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]')
170
+ assert error_paragraph.has_content?(error_message)
171
+ else
172
+ assert page.has_content?("#{field.titlecase} #{error_message}")
173
+ end
174
+ end
175
+ end
176
+
177
+ Then /^the "([^"]*)" field should have no error$/ do |field|
178
+ element = find_field(field)
179
+ classes = element.find(:xpath, '..')[:class].split(' ')
180
+ if classes.respond_to? :should
181
+ classes.should_not include('field_with_errors')
182
+ classes.should_not include('error')
183
+ else
184
+ assert !classes.include?('field_with_errors')
185
+ assert !classes.include?('error')
186
+ end
187
+ end
188
+
189
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
190
+ with_scope(parent) do
191
+ field_checked = find_field(label)['checked']
192
+ if field_checked.respond_to? :should
193
+ field_checked.should be_true
194
+ else
195
+ assert field_checked
196
+ end
197
+ end
198
+ end
199
+
200
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
201
+ with_scope(parent) do
202
+ field_checked = find_field(label)['checked']
203
+ if field_checked.respond_to? :should
204
+ field_checked.should be_false
205
+ else
206
+ assert !field_checked
207
+ end
208
+ end
209
+ end
210
+
211
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
212
+ current_path = URI.parse(current_url).path
213
+ if current_path.respond_to? :should
214
+ current_path.should == path_to(page_name)
215
+ else
216
+ assert_equal path_to(page_name), current_path
217
+ end
218
+ end
219
+
220
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
221
+ query = URI.parse(current_url).query
222
+ actual_params = query ? CGI.parse(query) : {}
223
+ expected_params = {}
224
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
225
+
226
+ if actual_params.respond_to? :should
227
+ actual_params.should == expected_params
228
+ else
229
+ assert_equal expected_params, actual_params
230
+ end
231
+ end
232
+
233
+ Then /^show me the page$/ do
234
+ save_and_open_page
235
+ end
@@ -0,0 +1,127 @@
1
+ # encoding: utf-8
2
+ <%= embed_file('support/web_steps_warning.txt') %>
3
+
4
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
6
+
7
+ # Single-line step scoper
8
+ When /^(.*) uvnitř ([^:]+)$/ do |step, parent|
9
+ with_scope(parent) { When step }
10
+ end
11
+
12
+ # Multi-line step scoper
13
+ When /^(.*) uvnitř ([^:]+):$/ do |step, parent, table_or_string|
14
+ with_scope(parent) { When "#{step}:", table_or_string }
15
+ end
16
+
17
+ Given /^jsem na (.+)$/ do |page_name|
18
+ Given %{I am on #{page_name}}
19
+ end
20
+
21
+ When /^jdu na (.+)$/ do |page_name|
22
+ When %{I go to #{page_name}}
23
+ end
24
+
25
+ When /^stisknu tlačítko "([^"]*)"$/ do |button|
26
+ When %{I press "#{button}"}
27
+ end
28
+
29
+ When /^kliknu na "([^"]*)"$/ do |link|
30
+ When %{I follow "#{link}"}
31
+ end
32
+
33
+ When /^vyplním pole "([^"]*)" hodnotou "([^"]*)"$/ do |field, value|
34
+ When %{I fill in "#{field}" with "#{value}"}
35
+ end
36
+
37
+ When /^vyplním "([^"]*)" do pole "([^"]*)"$/ do |value, field|
38
+ When %{I fill in "#{value}" for "#{field}"}
39
+ end
40
+
41
+ When /^vyplním následující:$/ do |fields|
42
+ When %{I fill in the following:}, fields
43
+ end
44
+
45
+ When /^vyberu "([^"]*)" z "([^"]*)"$/ do |value, field|
46
+ When %{I select "#{value}" from "#{field}"}
47
+ end
48
+
49
+ When /^vyberu "([^"]*)" jako datum a čas$/ do |time|
50
+ When %{I select "#{time}" as the date and time}
51
+ end
52
+
53
+ When /^vyberu "([^"]*)" jako "([^"]*)" datum a čas$/ do |datetime, datetime_label|
54
+ When %{I select "#{datetime}" as the "#{datetime_label}" date and time}
55
+ end
56
+
57
+ When /^vyberu "([^"]*)" jako čas$/ do |time|
58
+ When %{I select "#{time}" as the time}
59
+ end
60
+
61
+ When /^vyberu "([^"]*)" jako "([^"]*)" čas$/ do |time, time_label|
62
+ When %{I select "#{time}" as the "#{time_label}" time}
63
+ end
64
+
65
+ When /^vyberu cd jako datum$/ do |date|
66
+ When %{I select "#{date}" as the date}
67
+ end
68
+
69
+ When /^vyberu "([^"]*)" jako "([^"]*)" datum$/ do |date, date_label|
70
+ When %{I select "#{date}" as the "#{date_label}" date}
71
+ end
72
+
73
+ When /^zaškrtnu "([^"]*)"$/ do |field|
74
+ When %{I check "#{field}"}
75
+ end
76
+
77
+ When /^vyškrtnu "([^"]*)"$/ do |field|
78
+ When %{I uncheck "#{field}"}
79
+ end
80
+
81
+ When /^vyberu "([^"]*)"$/ do |field|
82
+ When %{I choose "#{field}"}
83
+ end
84
+
85
+ When /^připojím soubor "([^"]*)" do pole "([^"]*)"$/ do |path, field|
86
+ When %{I attach the file "#{path}" to "#{field}"}
87
+ end
88
+
89
+ Then /^(?:|také )bych měl vidět "([^"]*)"$/ do |text|
90
+ Then %{I should see "#{text}"}
91
+ end
92
+
93
+ Then /^(?:|také )bych měl vidět \/([^\/]*)\/$/ do |regexp|
94
+ Then %{I should see /#{regexp}/}
95
+ end
96
+
97
+ Then /^(?:|také )bych neměl vidět "([^"]*)"$/ do |text|
98
+ Then %{I should not see "#{text}"}
99
+ end
100
+
101
+ Then /^(?:|také )bych neměl vidět \/([^\/]*)\/$/ do |regexp|
102
+ Then %{I should not see /#{regexp}/}
103
+ end
104
+
105
+ Then /^pole "([^"]*)" by mělo obsahovat "([^"]*)"$/ do |field, value|
106
+ Then %{the "#{field}" field should contain "#{value}"}
107
+ end
108
+
109
+ Then /^pole "([^"]*)" by nemělo obsahovat "([^"]*)"$/ do |field, value|
110
+ Then %{the "#{field}" field should not contain "#{value}"}
111
+ end
112
+
113
+ Then /^pole "([^"]*)" by mělo být zaškrtnuté$/ do |label|
114
+ Then %{the "#{label}" checkbox should be checked}
115
+ end
116
+
117
+ Then /^pole "([^"]*)" by nemělo být zaškrtnuté$/ do |label|
118
+ Then %{the "#{label}" checkbox should not be checked}
119
+ end
120
+
121
+ Then /^(?:|také )bych měl být na (.+)$/ do |page_name|
122
+ Then %{I should be on #{page_name}}
123
+ end
124
+
125
+ Then /^(?:|také )mi ukaž stránku$/ do
126
+ Then %{show me the page}
127
+ end
@@ -0,0 +1,105 @@
1
+ # encoding: utf-8
2
+ <%= embed_file('support/web_steps_warning.txt') %>
3
+
4
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
6
+
7
+ # Single-line step scoper
8
+ Når /^(.*) under ([^:]+)$/ do |step, parent|
9
+ with_scope(parent) { Når step }
10
+ end
11
+
12
+ # Multi-line step scoper
13
+ Når /^(.*) under ([^:]+):$/ do |step, parent, table_or_string|
14
+ with_scope(parent) { Når "#{step}:", table_or_string }
15
+ end
16
+
17
+ Givet /^(?:|at )jeg står på (.*)$/ do |page_name|
18
+ Given %{I am on #{page_name}}
19
+ end
20
+
21
+ Når /^jeg går til (.*)$/ do |page_name|
22
+ When %{I go to #{page_name}}
23
+ end
24
+
25
+ Når /^jeg trykker "([^"]*)"$/ do |button|
26
+ When %{I press "#{button}"}
27
+ end
28
+
29
+ Når /^jeg klikker "([^"]*)"$/ do |link|
30
+ When %{I follow "#{link}"}
31
+ end
32
+
33
+ Når /^jeg fylder ud "([^"]*)" med "([^"]*)"$/ do |field, value|
34
+ When %{I fill in "#{field}" with "#{value}"}
35
+ end
36
+
37
+ Når /^jeg fylder ud "([^"]*)" for "([^"]*)"$/ do |value, field|
38
+ When %{I fill in "#{value}" for "#{field}"}
39
+ end
40
+
41
+ Når /^jeg fylder følgende ud:$/ do |fields|
42
+ When %{I fill in the following:}, fields
43
+ end
44
+
45
+ Når /^jeg vælger "([^"]*)" fra "([^"]*)"$/ do |value, field|
46
+ When %{I select "#{value}" from "#{field}"}
47
+ end
48
+
49
+ # Missing: date stuff
50
+
51
+ Når /^jeg afkrydser "([^"]*)"$/ do |field|
52
+ When %{I check "#{field}"}
53
+ end
54
+
55
+ Når /^jeg fjerner afkrydsning for "([^"]*)"$/ do |field|
56
+ When %{I uncheck "#{field}"}
57
+ end
58
+
59
+ Når /^jeg vælger "([^"]*)"$/ do |field|
60
+ When %{I choose "#{field}"}
61
+ end
62
+
63
+ Når /^jeg tilsætter filen "([^"]*)" til "([^"]*)"$/ do |path, field|
64
+ When %{I attach the file "#{path}" to "#{field}"}
65
+ end
66
+
67
+ Så /^(?:skal jeg|jeg skal) se "([^"]*)"$/ do |text|
68
+ Then %{I should see "#{text}"}
69
+ end
70
+
71
+ Så /^(?:skal jeg|jeg skal) se \/([^\/]*)\/$/ do |regexp|
72
+ Then %{I should see /#{regexp}/}
73
+ end
74
+
75
+ Så /^(?:skal jeg|jeg skal) ikke se "([^"]*)"$/ do |text|
76
+ Then %{I should not see "#{text}"}
77
+ end
78
+
79
+ Så /^(?:skal jeg|jeg skal) ikke se \/([^\/]*)\/$/ do |regexp|
80
+ Then %{I should not see /#{regexp}/}
81
+ end
82
+
83
+ Så /^(?:skal )"([^"]*)" feltet (?:skal )indeholde "([^"]*)"$/ do |field, value|
84
+ Then %{the "#{field}" field should contain "#{value}"}
85
+ end
86
+
87
+ Så /^(?:skal ) "([^"]*)" feltet (?:skal )ikke indeholde "([^"]*)"$/ do |field, value|
88
+ Then %{the "#{field}" field should not contain "#{value}"}
89
+ end
90
+
91
+ Så /^(?:skal ) "([^"]*)" afkrydsningsboksen (?:skal )være krydset af$/ do |label|
92
+ Then %{the "#{label}" checkbox should be checked}
93
+ end
94
+
95
+ Så /^(?:skal ) "([^"]*)" afkrydsningsboksen (?:skal )ikke være krydset af$/ do |label|
96
+ Then %{the "#{label}" checkbox should not be checked}
97
+ end
98
+
99
+ Så /^(?:skal jeg|jeg skal) komme til (.+)$/ do |page_name|
100
+ Then %{I should be on #{page_name}}
101
+ end
102
+
103
+ Så /^vil jeg se siden$/ do |page_name|
104
+ Then %{show me the page}
105
+ end