casecumber-rails 1.0.2.1

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.
Files changed (84) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +205 -0
  6. data/History.md +219 -0
  7. data/LICENSE +22 -0
  8. data/README.md +77 -0
  9. data/Rakefile +9 -0
  10. data/config/.gitignore +1 -0
  11. data/config/cucumber.yml +1 -0
  12. data/cucumber-rails.gemspec +46 -0
  13. data/dev_tasks/cucumber.rake +5 -0
  14. data/dev_tasks/rspec.rake +8 -0
  15. data/dev_tasks/yard.rake +0 -0
  16. data/dev_tasks/yard/default/layout/html/bubble_32x32.png +0 -0
  17. data/dev_tasks/yard/default/layout/html/footer.erb +5 -0
  18. data/dev_tasks/yard/default/layout/html/index.erb +1 -0
  19. data/dev_tasks/yard/default/layout/html/layout.erb +25 -0
  20. data/dev_tasks/yard/default/layout/html/logo.erb +1 -0
  21. data/dev_tasks/yard/default/layout/html/setup.rb +4 -0
  22. data/features/allow_rescue.feature +63 -0
  23. data/features/capybara_javascript_drivers.feature +87 -0
  24. data/features/database_cleaner.feature +44 -0
  25. data/features/emulate_javascript.feature +34 -0
  26. data/features/inspect_query_string.feature +37 -0
  27. data/features/install_cucumber_rails.feature +16 -0
  28. data/features/mongoid.feature +53 -0
  29. data/features/multiple_databases.feature +74 -0
  30. data/features/named_selectors.feature +33 -0
  31. data/features/no_database.feature +70 -0
  32. data/features/pseduo_class_selectors.feature +24 -0
  33. data/features/rerun_profile.feature +38 -0
  34. data/features/rest_api.feature +47 -0
  35. data/features/routing.feature +18 -0
  36. data/features/select_dates.feature +99 -0
  37. data/features/step_definitions/cucumber_rails_steps.rb +89 -0
  38. data/features/support/env.rb +37 -0
  39. data/features/test_unit.feature +43 -0
  40. data/lib/cucumber/rails.rb +23 -0
  41. data/lib/cucumber/rails/action_controller.rb +12 -0
  42. data/lib/cucumber/rails/application.rb +17 -0
  43. data/lib/cucumber/rails/capybara.rb +6 -0
  44. data/lib/cucumber/rails/capybara/javascript_emulation.rb +83 -0
  45. data/lib/cucumber/rails/capybara/select_dates_and_times.rb +50 -0
  46. data/lib/cucumber/rails/hooks.rb +4 -0
  47. data/lib/cucumber/rails/hooks/active_record.rb +21 -0
  48. data/lib/cucumber/rails/hooks/allow_rescue.rb +8 -0
  49. data/lib/cucumber/rails/hooks/database_cleaner.rb +13 -0
  50. data/lib/cucumber/rails/hooks/mail.rb +5 -0
  51. data/lib/cucumber/rails/rspec.rb +21 -0
  52. data/lib/cucumber/rails/world.rb +26 -0
  53. data/lib/cucumber/web/tableish.rb +118 -0
  54. data/lib/generators/cucumber/feature/USAGE +16 -0
  55. data/lib/generators/cucumber/feature/feature_generator.rb +28 -0
  56. data/lib/generators/cucumber/feature/named_arg.rb +19 -0
  57. data/lib/generators/cucumber/feature/templates/feature.erb +63 -0
  58. data/lib/generators/cucumber/feature/templates/steps.erb +14 -0
  59. data/lib/generators/cucumber/install/USAGE +15 -0
  60. data/lib/generators/cucumber/install/install_generator.rb +88 -0
  61. data/lib/generators/cucumber/install/templates/config/cucumber.yml.erb +8 -0
  62. data/lib/generators/cucumber/install/templates/script/cucumber +10 -0
  63. data/lib/generators/cucumber/install/templates/step_definitions/web_steps.rb.erb +192 -0
  64. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_cs.rb.erb +127 -0
  65. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_da.rb.erb +105 -0
  66. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_de.rb.erb +127 -0
  67. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_es.rb.erb +127 -0
  68. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_ja.rb.erb +140 -0
  69. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_ko.rb.erb +142 -0
  70. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_no.rb.erb +105 -0
  71. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_pt-BR.rb.erb +132 -0
  72. data/lib/generators/cucumber/install/templates/support/_rails_each_run.rb.erb +36 -0
  73. data/lib/generators/cucumber/install/templates/support/_rails_prefork.rb.erb +1 -0
  74. data/lib/generators/cucumber/install/templates/support/capybara.rb +5 -0
  75. data/lib/generators/cucumber/install/templates/support/edit_warning.txt +5 -0
  76. data/lib/generators/cucumber/install/templates/support/paths.rb +33 -0
  77. data/lib/generators/cucumber/install/templates/support/rails.rb.erb +4 -0
  78. data/lib/generators/cucumber/install/templates/support/rails_spork.rb.erb +13 -0
  79. data/lib/generators/cucumber/install/templates/support/selectors.rb +39 -0
  80. data/lib/generators/cucumber/install/templates/support/web_steps_warning.txt +19 -0
  81. data/lib/generators/cucumber/install/templates/tasks/cucumber.rake.erb +60 -0
  82. data/spec/cucumber/web/tableish_spec.rb +239 -0
  83. data/spec/spec_helper.rb +3 -0
  84. metadata +514 -0
@@ -0,0 +1,36 @@
1
+ # By default, any exception happening in your Rails application will bubble up
2
+ # to Cucumber so that your scenario will fail. This is a different from how
3
+ # your application behaves in the production environment, where an error page will
4
+ # be rendered instead.
5
+ #
6
+ # Sometimes we want to override this default behaviour and allow Rails to rescue
7
+ # exceptions and display an error page (just like when the app is running in production).
8
+ # Typical scenarios where you want to do this is when you test your error pages.
9
+ # There are two ways to allow Rails to rescue exceptions:
10
+ #
11
+ # 1) Tag your scenario (or feature) with @allow-rescue
12
+ #
13
+ # 2) Set the value below to true. Beware that doing this globally is not
14
+ # recommended as it will mask a lot of errors for you!
15
+ #
16
+ ActionController::Base.allow_rescue = false
17
+
18
+ # Remove/comment out the lines below if your app doesn't have a database.
19
+ # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
20
+ begin
21
+ DatabaseCleaner.strategy = :transaction
22
+ rescue NameError
23
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
24
+ end
25
+
26
+ # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
27
+ # See the DatabaseCleaner documentation for details. Example:
28
+ #
29
+ # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
30
+ # DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
31
+ # end
32
+ #
33
+ # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
34
+ # DatabaseCleaner.strategy = :transaction
35
+ # end
36
+ #
@@ -0,0 +1 @@
1
+ require 'cucumber/rails'
@@ -0,0 +1,5 @@
1
+ # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
2
+ # order to ease the transition to Capybara we set the default here. If you'd
3
+ # prefer to use XPath just remove this line and adjust any selectors in your
4
+ # steps to use the XPath syntax.
5
+ Capybara.default_selector = :css
@@ -0,0 +1,5 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - 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-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
@@ -0,0 +1,33 @@
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
+ begin
22
+ page_name =~ /^the (.*) page$/
23
+ path_components = $1.split(/\s+/)
24
+ self.send(path_components.push('path').join('_').to_sym)
25
+ rescue NoMethodError, ArgumentError
26
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
27
+ "Now, go and add a mapping in #{__FILE__}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ World(NavigationHelpers)
@@ -0,0 +1,4 @@
1
+ <%= embed_file('support/edit_warning.txt') %>
2
+ <%= embed_template('support/_rails_prefork.rb.erb') %>
3
+ <%= embed_file("support/capybara.rb") %>
4
+ <%= embed_template('support/_rails_each_run.rb.erb') %>
@@ -0,0 +1,13 @@
1
+ <%= embed_file('support/edit_warning.txt') %>
2
+ require 'rubygems'
3
+ require 'spork'
4
+
5
+ Spork.prefork do
6
+ <%= embed_template('support/_rails_prefork.rb.erb', ' ') %>
7
+
8
+ <%= embed_file("support/capybara.rb", ' ') %>
9
+ end
10
+
11
+ Spork.each_run do
12
+ <%= embed_template('support/_rails_each_run.rb.erb', ' ') %>
13
+ end
@@ -0,0 +1,39 @@
1
+ module HtmlSelectorsHelpers
2
+ # Maps a name to a selector. Used primarily by the
3
+ #
4
+ # When /^(.+) within (.+)$/ do |step, scope|
5
+ #
6
+ # step definitions in web_steps.rb
7
+ #
8
+ def selector_for(locator)
9
+ case locator
10
+
11
+ when "the page"
12
+ "html > body"
13
+
14
+ # Add more mappings here.
15
+ # Here is an example that pulls values out of the Regexp:
16
+ #
17
+ # when /^the (notice|error|info) flash$/
18
+ # ".flash.#{$1}"
19
+
20
+ # You can also return an array to use a different selector
21
+ # type, like:
22
+ #
23
+ # when /the header/
24
+ # [:xpath, "//header"]
25
+
26
+ # This allows you to provide a quoted selector as the scope
27
+ # for "within" steps as was previously the default for the
28
+ # web steps:
29
+ when /^"(.+)"$/
30
+ $1
31
+
32
+ else
33
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
34
+ "Now, go and add a mapping in #{__FILE__}"
35
+ end
36
+ end
37
+ end
38
+
39
+ World(HtmlSelectorsHelpers)
@@ -0,0 +1,19 @@
1
+ # TL;DR: YOU SHOULD DELETE THIS FILE
2
+ #
3
+ # This file was generated by Cucumber-Rails and is only here to get you a head start
4
+ # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5
+ # visit pages, interact with widgets and make assertions about page content.
6
+ #
7
+ # If you use these step definitions as basis for your features you will quickly end up
8
+ # with features that are:
9
+ #
10
+ # * Hard to maintain
11
+ # * Verbose to read
12
+ #
13
+ # A much better approach is to write your own higher level step definitions, following
14
+ # the advice in the following blog posts:
15
+ #
16
+ # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17
+ # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18
+ # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19
+ #
@@ -0,0 +1,60 @@
1
+ <%= embed_file('support/edit_warning.txt') %>
2
+
3
+ unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
4
+
5
+ vendored_cucumber_bin = Dir["#{<%= defined?(Rails.root) ? 'Rails.root' : 'RAILS_ROOT' %>}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
6
+ $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
7
+
8
+ begin
9
+ require 'cucumber/rake/task'
10
+
11
+ namespace :cucumber do
12
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
13
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
14
+ t.fork = true # You may get faster startup if you set this to false
15
+ t.profile = 'default'
16
+ end
17
+
18
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
19
+ t.binary = vendored_cucumber_bin
20
+ t.fork = true # You may get faster startup if you set this to false
21
+ t.profile = 'wip'
22
+ end
23
+
24
+ Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
25
+ t.binary = vendored_cucumber_bin
26
+ t.fork = true # You may get faster startup if you set this to false
27
+ t.profile = 'rerun'
28
+ end
29
+
30
+ desc 'Run all features'
31
+ task :all => [:ok, :wip]
32
+
33
+ task :statsetup do
34
+ require 'rails/code_statistics'
35
+ ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
36
+ ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
37
+ end
38
+ end
39
+ desc 'Alias for cucumber:ok'
40
+ task :cucumber => 'cucumber:ok'
41
+
42
+ task :default => :cucumber
43
+
44
+ task :features => :cucumber do
45
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
46
+ end
47
+
48
+ # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
49
+ task 'db:test:prepare' do
50
+ end
51
+
52
+ task :stats => 'cucumber:statsetup'
53
+ rescue LoadError
54
+ desc 'cucumber rake task not available (cucumber not installed)'
55
+ task :cucumber do
56
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,239 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
4
+
5
+ def World(*a); end
6
+ require 'cucumber/web/tableish'
7
+
8
+ module Cucumber
9
+ module Web
10
+ describe Tableish do
11
+ include Tableish
12
+
13
+ unless RUBY_PLATFORM =~ /java/
14
+ it "should convert a table" do
15
+ html = <<-HTML
16
+ <div class="admin-table">
17
+ <table>
18
+ <thead>
19
+ <tr>
20
+ <th>Name</th>
21
+ <th><span>Edit</span></th>
22
+ <th><span>Delete</span></th>
23
+ </tr>
24
+ </thead>
25
+ <tbody>
26
+ <tr>
27
+ <td><strong>Guybrush Threepwood</strong></td>
28
+ <td><a href="/users/1/edit">Edit</a></td>
29
+ <td>
30
+ <form method="post" action="/users/1" class="button-to">
31
+ <div>
32
+ <input type="hidden" name="_method" value="delete" />
33
+ <input value="Delete" type="submit" />
34
+ </div>
35
+ </form>
36
+ </td>
37
+ </tr>
38
+ </tbody>
39
+ </table>
40
+ </div>
41
+ HTML
42
+
43
+ header = _tableish(html, '.admin-table table thead tr', 'th')
44
+
45
+ column_selector = lambda do |tr|
46
+ tds = tr.search('td')
47
+ [
48
+ tds[0].text,
49
+ tds[1].text,
50
+ tds[2].css('input:nth-child(2)').first.attributes['value']
51
+ ]
52
+ end
53
+ body = _tableish(html, '.admin-table table tbody tr', column_selector)
54
+
55
+ (header + body).should == [
56
+ ['Name', 'Edit', 'Delete'],
57
+ ['Guybrush Threepwood', 'Edit', 'Delete']
58
+ ]
59
+ end
60
+
61
+ it "should convert a table" do
62
+ html = <<-HTML
63
+ <table id="tools">
64
+ <tr>
65
+ <th>tool</th>
66
+ <th>dude</th>
67
+ </tr>
68
+ <tr>
69
+ <td>webrat</td>
70
+ <td>bryan</td>
71
+ </tr>
72
+ <tr>
73
+ <td>cucumber</td>
74
+ <td>aslak</td>
75
+ </tr>
76
+ </table>
77
+ HTML
78
+
79
+ _tableish(html, 'table#tools tr', 'td,th').should == [
80
+ %w{tool dude},
81
+ %w{webrat bryan},
82
+ %w{cucumber aslak}
83
+ ]
84
+ end
85
+
86
+ it "should size to the first row" do
87
+ html = <<-HTML
88
+ <table id="tools">
89
+ <tr>
90
+ <th>tool</th>
91
+ <th>dude</th>
92
+ </tr>
93
+ <tr>
94
+ <td>webrat</td>
95
+ <td>bryan</td>
96
+ <td>crapola</td>
97
+ </tr>
98
+ <tr>
99
+ <td>cucumber</td>
100
+ <td>aslak</td>
101
+ <td>gunk</td>
102
+ <td>filth</td>
103
+ </tr>
104
+ </table>
105
+ HTML
106
+
107
+ _tableish(html, 'table#tools tr', 'td,th').should == [
108
+ ['tool', 'dude',],
109
+ ['webrat', 'bryan'],
110
+ ['cucumber', 'aslak']
111
+ ]
112
+ end
113
+
114
+ it "should pad with empty Strings if some rows are shorter" do
115
+ html = <<-HTML
116
+ <table id="tools">
117
+ <tr>
118
+ <th>tool</th>
119
+ <th>dude</th>
120
+ </tr>
121
+ <tr>
122
+ <td>webrat</td>
123
+ <td>bryan</td>
124
+ </tr>
125
+ <tr>
126
+ <td>cucumber</td>
127
+ </tr>
128
+ </table>
129
+ HTML
130
+
131
+ _tableish(html, 'table#tools tr', 'td,th').should == [
132
+ %w{tool dude},
133
+ %w{webrat bryan},
134
+ ['cucumber', '']
135
+ ]
136
+ end
137
+
138
+ it "should handle colspan and rowspan" do
139
+ html = <<-HTML
140
+ <table id="tools">
141
+ <tr>
142
+ <td rowspan="4">a</td>
143
+ <td>b</td>
144
+ <td>c</td>
145
+ <td>d</td>
146
+ </tr>
147
+ <tr>
148
+ <td colspan="3">e</td>
149
+ </tr>
150
+ <tr>
151
+ <td rowspan="2" colspan="2">f</td>
152
+ <td>g</td>
153
+ </tr>
154
+ <tr>
155
+ <td>h</td>
156
+ </tr>
157
+ </table>
158
+ HTML
159
+
160
+ _tableish(html, 'table#tools tr', 'td,th').should == [
161
+ ['a', 'b', 'c', 'd'],
162
+ ['', 'e', '', '' ],
163
+ ['', 'f', '', 'g' ],
164
+ ['', '', '', 'h' ],
165
+ ]
166
+ end
167
+
168
+ it "should convert a dl" do
169
+ html = <<-HTML
170
+ <dl id="tools">
171
+ <dt>webrat</dt>
172
+ <dd>bryan</dd>
173
+ <dt>cucumber</dt>
174
+ <dd>aslak</dd>
175
+ </dl>
176
+ HTML
177
+
178
+ _tableish(html, 'dl#tools dt', lambda{|dt| [dt, dt.next.next]}).should == [
179
+ %w{webrat bryan},
180
+ %w{cucumber aslak}
181
+ ]
182
+ end
183
+
184
+ it "should convert a ul" do
185
+ html = <<-HTML
186
+ <ul id="phony">
187
+ <li>nope</li>
188
+ </ul>
189
+
190
+ <ul id="yes">
191
+ <li>webrat</li>
192
+ <li>bryan</li>
193
+ <li>cucumber</li>
194
+ <li>aslak</li>
195
+ </ul>
196
+ HTML
197
+
198
+ _tableish(html, 'ul#yes li', lambda{|li| [li]}).should == [
199
+ %w{webrat},
200
+ %w{bryan},
201
+ %w{cucumber},
202
+ %w{aslak},
203
+ ]
204
+ end
205
+
206
+ it "should do complex shit" do
207
+ html = <<-HTML
208
+ <form method="post" action="/invoices/10/approve" class="button-to">
209
+ <div>
210
+ <input id="approve_invoice_10" type="submit" value="Approve" />
211
+ <input name="authenticity_token" type="hidden" value="WxKGVy3Y5zcvFEiFe66D/odoc3CicfMdAup4vzQfiZ0=" />
212
+ <span>Hello&nbsp;World<span>
213
+ </div>
214
+ </form>
215
+ <form method="post" action="/invoices/10/delegate" class="button-to">
216
+ <div>
217
+ <input id="delegate_invoice_10" type="submit" value="Delegate" />
218
+ <input name="authenticity_token" type="hidden" value="WxKGVy3Y5zcvFEiFe66D/odoc3CicfMdAup4vzQfiZ0=" />
219
+ <span>Hi There<span>
220
+ </div>
221
+ </form>
222
+ HTML
223
+
224
+ selectors = lambda do |form|
225
+ [
226
+ form.css('div input:nth-child(1)').first.attributes['value'],
227
+ form.css('span').first.text.gsub(/\302\240/, ' ')
228
+ ]
229
+ end
230
+
231
+ _tableish(html, 'form', selectors).should == [
232
+ ['Approve', "Hello World"],
233
+ ['Delegate', 'Hi There']
234
+ ]
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end