cucumber-rails 0.1.1.rc2 → 0.1.1.rc3

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.
@@ -0,0 +1,22 @@
1
+ require 'cucumber/webrat/element_locator' # Deprecated - remove this line if you don't use #element_at or #table_at
2
+ require 'cucumber/web/tableish'
3
+ World(Cucumber::Tableish)
4
+ require 'webrat'
5
+ require 'webrat/core/matchers'
6
+ Webrat.configure do |config|
7
+ config.mode = :rails
8
+ config.open_error_files = false # Set to true if you want error pages to pop up in the browser
9
+ end
10
+
11
+ # If you set this to true, each scenario will run in a database transaction.
12
+ # You can still turn off transactions on a per-scenario basis, simply tagging
13
+ # a feature or scenario with the @no-txn tag.
14
+ #
15
+ # If you set this to false, transactions will be off for all scenarios,
16
+ # regardless of whether you use @no-txn or not.
17
+ #
18
+ # Beware that turning transactions off will leave data in your database
19
+ # after each scenario, which can lead to hard-to-debug failures in
20
+ # subsequent scenarios. If you do this, we recommend you create a Before
21
+ # block that will explicitly put your database in a known state.
22
+ Cucumber::Rails::World.use_transactional_fixtures = true
@@ -14,6 +14,7 @@ class FeatureGenerator < Rails::Generator::NamedBase
14
14
 
15
15
  class NamedArg
16
16
  attr_reader :name
17
+ attr_reader :type
17
18
 
18
19
  def initialize(s)
19
20
  @name, @type = *s.split(':')
@@ -7,7 +7,11 @@ Feature: Manage <%= plural_name %>
7
7
  Given I am on the new <%= singular_name %> page
8
8
  <% keyword = 'When' -%>
9
9
  <% named_args.each do |arg| -%>
10
- <%= keyword %> I fill in "<%= arg.name.humanize %>" with "<%= arg.value(1) %>"
10
+ <% if arg.type == 'boolean' -%>
11
+ <%= keyword %> I uncheck "<%= arg.name.humanize %>"
12
+ <% else -%>
13
+ <%= keyword %> I fill in "<%= arg.name.humanize %>" with "<%= arg.value(1) %>"
14
+ <% end -%>
11
15
  <% keyword = 'And' -%>
12
16
  <% end -%>
13
17
  And I press "Create"
@@ -10,5 +10,5 @@ When /^I delete the (\d+)(?:st|nd|rd|th) <%= singular_name %>$/ do |pos|
10
10
  end
11
11
 
12
12
  Then /^I should see the following <%= plural_name %>:$/ do |expected_<%= plural_name %>_table|
13
- expected_<%= plural_name %>_table.diff!(table_at('table').to_a)
13
+ expected_<%= plural_name %>_table.diff!(tableish('table tr', 'td,th'))
14
14
  end
@@ -15,7 +15,7 @@ end
15
15
  module Cucumber #:nodoc:
16
16
  module Rails
17
17
  class World < ActionController::IntegrationTest
18
- include ActiveSupport::Testing::SetupAndTeardown
18
+ include ActiveSupport::Testing::SetupAndTeardown if ActiveSupport::Testing.const_defined?("SetupAndTeardown")
19
19
  def initialize #:nodoc:
20
20
  @_result = Test::Unit::TestResult.new
21
21
  end
@@ -0,0 +1,27 @@
1
+ require 'nokogiri'
2
+
3
+ module Cucumber
4
+ module Tableish
5
+ def tableish(row_selector, column_selectors)
6
+ html = defined?(Capybara) ? body : response_body
7
+ _tableish(html, row_selector, column_selectors)
8
+ end
9
+
10
+ def _tableish(html, row_selector, column_selectors)
11
+ doc = Nokogiri::HTML(html)
12
+ column_count = nil
13
+ doc.search(row_selector).map do |row|
14
+ cells = case(column_selectors)
15
+ when String
16
+ row.search(column_selectors)
17
+ when Proc
18
+ column_selectors.call(row)
19
+ end
20
+ column_count ||= cells.length
21
+ cells[0...column_count].map do |cell|
22
+ cell.text.strip
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,103 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+ require 'cucumber/web/tableish'
3
+
4
+ module Cucumber
5
+ module Web
6
+ describe Tableish do
7
+ include Tableish
8
+
9
+ unless RUBY_PLATFORM =~ /java/
10
+ it "should convert a table" do
11
+ html = <<-HTML
12
+ <table>
13
+ <tr>
14
+ <th>tool</th>
15
+ <th>dude</th>
16
+ </tr>
17
+ <tr>
18
+ <td>webrat</td>
19
+ <td>bryan</td>
20
+ </tr>
21
+ <tr>
22
+ <td>cucumber</td>
23
+ <td>aslak</td>
24
+ </tr>
25
+ </table>
26
+ HTML
27
+
28
+ _tableish(html, 'table tr', 'td,th').should == [
29
+ %w{tool dude},
30
+ %w{webrat bryan},
31
+ %w{cucumber aslak}
32
+ ]
33
+ end
34
+
35
+ it "should size to the first row" do
36
+ html = <<-HTML
37
+ <table>
38
+ <tr>
39
+ <th>tool</th>
40
+ <th>dude</th>
41
+ </tr>
42
+ <tr>
43
+ <td>webrat</td>
44
+ <td>bryan</td>
45
+ <td>crapola</td>
46
+ </tr>
47
+ <tr>
48
+ <td>cucumber</td>
49
+ <td>aslak</td>
50
+ <td>gunk</td>
51
+ <td>filth</td>
52
+ </tr>
53
+ </table>
54
+ HTML
55
+
56
+ _tableish(html, 'table tr', 'td,th').should == [
57
+ %w{tool dude},
58
+ %w{webrat bryan},
59
+ %w{cucumber aslak}
60
+ ]
61
+ end
62
+
63
+ it "should convert a dl" do
64
+ html = <<-HTML
65
+ <dl>
66
+ <dt>webrat</dt>
67
+ <dd>bryan</dd>
68
+ <dt>cucumber</dt>
69
+ <dd>aslak</dd>
70
+ </dl>
71
+ HTML
72
+
73
+ _tableish(html, 'dl dt', lambda{|dt| [dt, dt.next.next]}).should == [
74
+ %w{webrat bryan},
75
+ %w{cucumber aslak}
76
+ ]
77
+ end
78
+
79
+ it "should convert a ul" do
80
+ html = <<-HTML
81
+ <ul id="phony">
82
+ <li>nope</li>
83
+ </ul>
84
+
85
+ <ul id="yes">
86
+ <li>webrat</li>
87
+ <li>bryan</li>
88
+ <li>cucumber</li>
89
+ <li>aslak</li>
90
+ </ul>
91
+ HTML
92
+
93
+ _tableish(html, 'ul#yes li', lambda{|li| [li]}).should == [
94
+ %w{webrat},
95
+ %w{bryan},
96
+ %w{cucumber},
97
+ %w{aslak},
98
+ ]
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ gem 'rspec'
3
+ require 'spec'
4
+ require 'spec/autorun'
5
+
6
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run RSpec"
5
+ Spec::Rake::SpecTask.new do |t|
6
+ t.spec_opts = %w{--color --diff --format profile}
7
+ t.spec_files = FileList['spec/**/*_spec.rb']
8
+ t.rcov = ENV['RCOV']
9
+ t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/}
10
+ end
11
+ rescue LoadError
12
+ task :spec
13
+ end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.rc2
4
+ version: 0.1.1.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Dennis Bl\xC3\xB6te"
8
8
  - "Aslak Helles\xC3\xB8y"
9
+ - Rob Holland
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
13
 
13
- date: 2009-11-11 00:00:00 +01:00
14
+ date: 2009-12-07 00:00:00 +01:00
14
15
  default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
@@ -19,9 +20,9 @@ dependencies:
19
20
  version_requirement:
20
21
  version_requirements: !ruby/object:Gem::Requirement
21
22
  requirements:
22
- - - "="
23
+ - - ">="
23
24
  - !ruby/object:Gem::Version
24
- version: 0.4.3
25
+ version: 0.4.5.rc1
25
26
  version:
26
27
  description: Cucumber Generators and Runtime for Rails
27
28
  email: cukes@googlegroups.com
@@ -33,12 +34,14 @@ extra_rdoc_files:
33
34
  - README.rdoc
34
35
  files:
35
36
  - .gitignore
37
+ - History.txt
36
38
  - README.rdoc
37
39
  - Rakefile
38
40
  - VERSION
39
41
  - cucumber-rails.gemspec
40
42
  - generators/cucumber/USAGE
41
43
  - generators/cucumber/cucumber_generator.rb
44
+ - generators/cucumber/templates/capybara_env.rb
42
45
  - generators/cucumber/templates/cucumber
43
46
  - generators/cucumber/templates/cucumber.rake
44
47
  - generators/cucumber/templates/cucumber_environment.rb
@@ -46,18 +49,25 @@ files:
46
49
  - generators/cucumber/templates/paths.rb
47
50
  - generators/cucumber/templates/spork_env.rb
48
51
  - generators/cucumber/templates/version_check.rb
49
- - generators/cucumber/templates/webrat_steps/webrat_steps_de.rb
50
- - generators/cucumber/templates/webrat_steps/webrat_steps_en.rb
52
+ - generators/cucumber/templates/web_steps/capybara_steps.rb
53
+ - generators/cucumber/templates/web_steps/web_steps_de.rb
54
+ - generators/cucumber/templates/web_steps/web_steps_no.rb
55
+ - generators/cucumber/templates/web_steps/web_steps_pt-BR.rb
56
+ - generators/cucumber/templates/web_steps/webrat_steps.rb
57
+ - generators/cucumber/templates/webrat_env.rb
51
58
  - generators/feature/USAGE
52
59
  - generators/feature/feature_generator.rb
53
60
  - generators/feature/templates/feature.erb
54
61
  - generators/feature/templates/steps.erb
55
- - lib/cucumber-rails.rb
56
62
  - lib/cucumber/rails/action_controller.rb
57
63
  - lib/cucumber/rails/active_record.rb
58
64
  - lib/cucumber/rails/rspec.rb
59
65
  - lib/cucumber/rails/test_unit.rb
60
66
  - lib/cucumber/rails/world.rb
67
+ - lib/cucumber/web/tableish.rb
68
+ - spec/cucumber/web/tableish_spec.rb
69
+ - spec/spec_helper.rb
70
+ - tasks/rspec.rake
61
71
  has_rdoc: true
62
72
  homepage: http://github.com/dbloete/cucumber-rails
63
73
  licenses: []
@@ -86,5 +96,6 @@ rubygems_version: 1.3.5
86
96
  signing_key:
87
97
  specification_version: 3
88
98
  summary: Cucumber Generators and Runtime for Rails
89
- test_files: []
90
-
99
+ test_files:
100
+ - spec/cucumber/web/tableish_spec.rb
101
+ - spec/spec_helper.rb
@@ -1,241 +0,0 @@
1
- # IMPORTANT: This file was generated by Cucumber <%= Cucumber::VERSION %>
2
- # Edit at your own peril - it's recommended to regenerate this file
3
- # in the future When you upgrade to a newer version of Cucumber.
4
- # Consider adding your own code to a new file instead of editing this one.
5
-
6
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
7
-
8
- # Commonly used webrat steps
9
- # http://github.com/brynary/webrat
10
-
11
- Given /^(?:|ich )bin auf (.+)$/ do |page_name|
12
- visit path_to(page_name)
13
- end
14
-
15
- When /^(?:|ich )auf (.+) gehe$/ do |page_name|
16
- visit path_to(page_name)
17
- end
18
-
19
- When /^(?:|ich )auf "([^\"]*)" drücke$/ do |button|
20
- click_button(button)
21
- end
22
-
23
- When /^(?:|ich )auf "([^\"]*)" klicke$/ do |link|
24
- click_link(link)
25
- end
26
-
27
- When /^(?:|ich )auf "([^\"]*)" innerhalb "([^\"]*)" klicke$/ do |link, parent|
28
- click_link_within(parent, link)
29
- end
30
-
31
- When /^(?:|ich )"([^\"]*)" mit "([^\"]*)" ausfülle$/ do |field, value|
32
- fill_in(field, :with => value)
33
- end
34
-
35
- When /^(?:|ich )"([^\"]*)" in "([^\"]*)" eingebe$/ do |value, field|
36
- fill_in(field, :with => value)
37
- end
38
-
39
- # Wird benutzt, um ein Formular mittels Tabelle zu füllen. Beispiel:
40
- #
41
- # Wenn ich folgendes eingebe:
42
- # | Account Number | 5002 |
43
- # | Expiry date | 2009-11-01 |
44
- # | Note | Nice guy |
45
- # | Wants Email? | |
46
- #
47
- # TODO: Add support for checkbox, select og option
48
- # based on naming conventions.
49
- #
50
- When /^(?:|ich )folgendes eingebe:$/ do |fields|
51
- fields.rows_hash.each do |name, value|
52
- When %{ich "#{name}" mit "#{value}" ausfülle}
53
- end
54
- end
55
-
56
- When /^(?:|ich )"([^\"]*)" in "([^\"]*)" auswähle$/ do |value, field|
57
- select(value, :from => field)
58
- end
59
-
60
- # Use this step in conjunction with Rail's datetime_select helper. For example:
61
- # When I select "December 25, 2008 10:00" as the date and time
62
- When /^(?:|ich )"([^\"]*)" als Datum und Uhrzeit auswähle$/ do |time|
63
- select_datetime(time)
64
- end
65
-
66
- # Use this step when using multiple datetime_select helpers on a page or
67
- # you want to specify which datetime to select. Given the following view:
68
- # <%%= f.label :preferred %><br />
69
- # <%%= f.datetime_select :preferred %>
70
- # <%%= f.label :alternative %><br />
71
- # <%%= f.datetime_select :alternative %>
72
- # The following steps would fill out the form:
73
- # When I select "November 23, 2004 11:20" as the "Preferred" date and time
74
- # And I select "November 25, 2004 10:30" as the "Alternative" date and time
75
- When /^(?:|ich )"([^\"]*)" als "([^\"]*)" Datum und Uhrzeit auswähle$/ do |datetime, datetime_label|
76
- select_datetime(datetime, :from => datetime_label)
77
- end
78
-
79
- # Use this step in conjunction with Rail's time_select helper. For example:
80
- # When I select "2:20PM" as the time
81
- # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
82
- # will convert the 2:20PM to 14:20 and Then select it.
83
- When /^(?:|ich )"([^\"]*)" als Uhrzeit auswähle$/ do |time|
84
- select_time(time)
85
- end
86
-
87
- # Use this step When using multiple time_select helpers on a page or you want to
88
- # specify the name of the time on the form. For example:
89
- # When I select "7:30AM" as the "Gym" time
90
- When /^(?:|ich )"([^\"]*)" als "([^\"]*)" Uhrzeit auswähle$/ do |time, time_label|
91
- select_time(time, :from => time_label)
92
- end
93
-
94
- # Use this step in conjunction with Rail's date_select helper. For example:
95
- # When I select "February 20, 1981" as the date
96
- When /^(?:|ich )"([^\"]*)" als Datum auswähle$/ do |date|
97
- select_date(date)
98
- end
99
-
100
- # Use this step When using multiple date_select helpers on one page or
101
- # you want to specify the name of the date on the form. For example:
102
- # When I select "April 26, 1982" as the "Date of Birth" date
103
- When /^(?:|ich )"([^\"]*)" als "([^\"]*)" Datum auswähle$/ do |date, date_label|
104
- select_date(date, :from => date_label)
105
- end
106
-
107
- When /^(?:|ich )"([^\"]*)" anhake$/ do |field|
108
- check(field)
109
- end
110
-
111
- When /^(?:|ich )"([^\"]*)" abhake$/ do |field|
112
- uncheck(field)
113
- end
114
-
115
- When /^(?:|ich )"([^\"]*)" auswähle$/ do |field|
116
- choose(field)
117
- end
118
-
119
- When /^(?:|ich )die Datei "([^\"]*)" als "([^\"]*)" anhänge$/ do |path, field|
120
- attach_file(field, path)
121
- end
122
-
123
- Then /^(?:|ich sollte |sollte (?:|ich )?)"([^\"]*)" sehen$/ do |text|
124
- <% if framework == :rspec -%>
125
- response.should contain(text)
126
- <% else -%>
127
- assert_contain text
128
- <% end -%>
129
- end
130
-
131
- Then /^(?:|ich sollte |sollte (?:|ich )?)"([^\"]*)" innerhalb "([^\"]*)" sehen$/ do |text, selector|
132
- within(selector) do |content|
133
- <% if framework == :rspec -%>
134
- content.should contain(text)
135
- <% else -%>
136
- assert content.include?(text)
137
- <% end -%>
138
- end
139
- end
140
-
141
- Then /^(?:|ich sollte |sollte (?:|ich )?)\/([^\/]*)\/ sehen$/ do |regexp|
142
- regexp = Regexp.new(regexp)
143
- <% if framework == :rspec -%>
144
- response.should contain(regexp)
145
- <% else -%>
146
- assert_contain regexp
147
- <% end -%>
148
- end
149
-
150
- Then /^(?:|ich sollte |sollte (?:|ich )?)\/([^\/]*)\/ innerhalb "([^\"]*)" sehen$/ do |regexp, selector|
151
- within(selector) do |content|
152
- regexp = Regexp.new(regexp)
153
- <% if framework == :rspec -%>
154
- content.should contain(regexp)
155
- <% else -%>
156
- assert content =~ regexp
157
- <% end -%>
158
- end
159
- end
160
-
161
- Then /^(?:|ich sollte |sollte (?:|ich )?)nicht "([^\"]*)" sehen$/ do |text|
162
- <% if framework == :rspec -%>
163
- response.should_not contain(text)
164
- <% else -%>
165
- assert_not_contain text
166
- <% end -%>
167
- end
168
-
169
- Then /^(?:|ich sollte |sollte (?:|ich )?)nicht "([^\"]*)" innerhalb "([^\"]*)" sehen$/ do |text, selector|
170
- within(selector) do |content|
171
- <% if framework == :rspec -%>
172
- content.should_not contain(text)
173
- <% else -%>
174
- assert !content.include?(text)
175
- <% end -%>
176
- end
177
- end
178
-
179
- Then /^(?:|ich sollte |sollte (?:|ich )?)nicht \/([^\/]*)\/ sehen$/ do |regexp|
180
- regexp = Regexp.new(regexp)
181
- <% if framework == :rspec -%>
182
- response.should_not contain(regexp)
183
- <% else -%>
184
- assert_not_contain regexp
185
- <% end -%>
186
- end
187
-
188
- Then /^(?:|ich sollte |sollte (?:|ich )?)nicht \/([^\/]*)\/ innerhalb "([^\"]*)" sehen$/ do |regexp, selector|
189
- within(selector) do |content|
190
- regexp = Regexp.new(regexp)
191
- <% if framework == :rspec -%>
192
- content.should_not contain(regexp)
193
- <% else -%>
194
- assert content !~ regexp
195
- <% end -%>
196
- end
197
- end
198
-
199
- Then /^sollte das "([^\"]*)" Feld "([^\"]*)" enthalten$/ do |field, value|
200
- <% if framework == :rspec -%>
201
- field_labeled(field).value.should =~ /#{value}/
202
- <% else -%>
203
- assert_match(/#{value}/, field_labeled(field).value)
204
- <% end -%>
205
- end
206
-
207
- Then /^sollte das "([^\"]*)" Feld nicht "([^\"]*)" enthalten$/ do |field, value|
208
- <% if framework == :rspec -%>
209
- field_labeled(field).value.should_not =~ /#{value}/
210
- <% else -%>
211
- assert_no_match(/#{value}/, field_labeled(field).value)
212
- <% end -%>
213
- end
214
-
215
- Then /^sollte die "([^\"]*)" Checkbox angehakt sein$/ do |label|
216
- <% if framework == :rspec -%>
217
- field_labeled(label).should be_checked
218
- <% else -%>
219
- assert field_labeled(label).checked?
220
- <% end -%>
221
- end
222
-
223
- Then /^sollte die "([^\"]*)" Checkbox nicht angehakt sein$/ do |label|
224
- <% if framework == :rspec -%>
225
- field_labeled(label).should_not be_checked
226
- <% else -%>
227
- assert !field_labeled(label).checked?
228
- <% end -%>
229
- end
230
-
231
- Then /^(?:|ich sollte |sollte (?:|ich )?)auf (.+) sein$/ do |page_name|
232
- <% if framework == :rspec -%>
233
- URI.parse(current_url).path.should == path_to(page_name)
234
- <% else -%>
235
- assert_equal path_to(page_name), URI.parse(current_url).path
236
- <% end -%>
237
- end
238
-
239
- Then /^zeig mir die Seite$/ do
240
- save_and_open_page
241
- end