cucumber-rails2 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +4 -0
  2. data/HACKING.rdoc +24 -0
  3. data/History.txt +145 -0
  4. data/LICENSE +22 -0
  5. data/README.rdoc +70 -0
  6. data/Rakefile +24 -0
  7. data/VERSION +1 -0
  8. data/config/.gitignore +1 -0
  9. data/cucumber-rails2.gemspec +111 -0
  10. data/dev_tasks/cucumber.rake +5 -0
  11. data/dev_tasks/rspec.rake +13 -0
  12. data/features/rails2.feature +64 -0
  13. data/features/rails3.feature +97 -0
  14. data/features/rerun_profile.feature +39 -0
  15. data/features/step_definitions/cucumber_rails_steps.rb +35 -0
  16. data/features/support/env.rb +4 -0
  17. data/features/support/matchers/files.rb +17 -0
  18. data/generators/cucumber/USAGE +13 -0
  19. data/generators/cucumber/cucumber_generator.rb +88 -0
  20. data/generators/feature/USAGE +12 -0
  21. data/generators/feature/feature_generator.rb +47 -0
  22. data/lib/cucumber/rails/action_controller.rb +65 -0
  23. data/lib/cucumber/rails/active_record.rb +34 -0
  24. data/lib/cucumber/rails/capybara_javascript_emulation.rb +81 -0
  25. data/lib/cucumber/rails/rspec.rb +22 -0
  26. data/lib/cucumber/rails/test_unit.rb +7 -0
  27. data/lib/cucumber/rails/world.rb +48 -0
  28. data/lib/cucumber/web/tableish.rb +118 -0
  29. data/lib/generators/cucumber/feature/USAGE +16 -0
  30. data/lib/generators/cucumber/feature/feature_base.rb +29 -0
  31. data/lib/generators/cucumber/feature/feature_generator.rb +37 -0
  32. data/lib/generators/cucumber/feature/named_arg.rb +17 -0
  33. data/lib/generators/cucumber/install/USAGE +15 -0
  34. data/lib/generators/cucumber/install/install_base.rb +202 -0
  35. data/lib/generators/cucumber/install/install_generator.rb +64 -0
  36. data/spec/cucumber/web/tableish_spec.rb +192 -0
  37. data/spec/generators/cucumber/install/install_base_spec.rb +84 -0
  38. data/spec/spec.opts +2 -0
  39. data/spec/spec_helper.rb +6 -0
  40. data/templates/feature/feature.erb +63 -0
  41. data/templates/feature/steps.erb +14 -0
  42. data/templates/install/config/cucumber.yml.erb +8 -0
  43. data/templates/install/environments/cucumber.rb.erb +37 -0
  44. data/templates/install/script/cucumber +10 -0
  45. data/templates/install/step_definitions/capybara_steps.rb.erb +214 -0
  46. data/templates/install/step_definitions/web_steps_cs.rb.erb +136 -0
  47. data/templates/install/step_definitions/web_steps_da.rb.erb +114 -0
  48. data/templates/install/step_definitions/web_steps_de.rb.erb +136 -0
  49. data/templates/install/step_definitions/web_steps_es.rb.erb +136 -0
  50. data/templates/install/step_definitions/web_steps_ja.rb.erb +139 -0
  51. data/templates/install/step_definitions/web_steps_ko.rb.erb +141 -0
  52. data/templates/install/step_definitions/web_steps_no.rb.erb +114 -0
  53. data/templates/install/step_definitions/web_steps_pt-BR.rb.erb +140 -0
  54. data/templates/install/step_definitions/webrat_steps.rb.erb +276 -0
  55. data/templates/install/support/_rails_each_run.rb.erb +35 -0
  56. data/templates/install/support/_rails_prefork.rb.erb +12 -0
  57. data/templates/install/support/capybara.rb +9 -0
  58. data/templates/install/support/edit_warning.txt +5 -0
  59. data/templates/install/support/paths.rb +33 -0
  60. data/templates/install/support/rails.rb.erb +4 -0
  61. data/templates/install/support/rails_spork.rb.erb +13 -0
  62. data/templates/install/support/webrat.rb +8 -0
  63. data/templates/install/tasks/cucumber.rake.erb +48 -0
  64. metadata +143 -0
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), 'install_base')
2
+
3
+ module Cucumber
4
+ class InstallGenerator < Rails::Generators::Base
5
+
6
+ include Cucumber::Generators::InstallBase
7
+
8
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
9
+
10
+ argument :language, :type => :string, :banner => "LANG", :optional => true
11
+
12
+ class_option :webrat, :type => :boolean, :desc => "Use Webrat"
13
+ class_option :capybara, :type => :boolean, :desc => "Use Capybara"
14
+ class_option :rspec, :type => :boolean, :desc => "Use RSpec"
15
+ class_option :testunit, :type => :boolean, :desc => "Use Test::Unit"
16
+ class_option :spork, :type => :boolean, :desc => "Use Spork"
17
+ class_option :skip_database, :type => :boolean, :desc => "Skip modification of database.yml", :aliases => '-D', :default => false
18
+
19
+ attr_reader :framework, :driver
20
+
21
+ def configure_defaults
22
+ @language ||= 'en'
23
+ @framework = framework_from_options || detect_current_framework || detect_default_framework
24
+ @driver = driver_from_options || detect_current_driver || detect_default_driver
25
+ end
26
+
27
+ def generate
28
+ check_upgrade_limitations
29
+ create_templates
30
+ create_scripts
31
+ create_step_definitions
32
+ create_feature_support
33
+ create_tasks
34
+ create_database unless options[:skip_database]
35
+ end
36
+
37
+ def self.gem_root
38
+ File.expand_path("../../../../../", __FILE__)
39
+ end
40
+
41
+ def self.source_root
42
+ File.join(gem_root, 'templates/install')
43
+ end
44
+
45
+ def cucumber_rails_env
46
+ 'test'
47
+ end
48
+
49
+ private
50
+
51
+ def framework_from_options
52
+ return :rspec if options[:rspec]
53
+ return :testunit if options[:testunit]
54
+ return nil
55
+ end
56
+
57
+ def driver_from_options
58
+ return :webrat if options[:webrat]
59
+ return :capybara if options[:capybara]
60
+ return nil
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,192 @@
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
+ <table id="tools">
17
+ <tr>
18
+ <th>tool</th>
19
+ <th>dude</th>
20
+ </tr>
21
+ <tr>
22
+ <td>webrat</td>
23
+ <td>bryan</td>
24
+ </tr>
25
+ <tr>
26
+ <td>cucumber</td>
27
+ <td>aslak</td>
28
+ </tr>
29
+ </table>
30
+ HTML
31
+
32
+ _tableish(html, 'table#tools tr', 'td,th').should == [
33
+ %w{tool dude},
34
+ %w{webrat bryan},
35
+ %w{cucumber aslak}
36
+ ]
37
+ end
38
+
39
+ it "should size to the first row" do
40
+ html = <<-HTML
41
+ <table id="tools">
42
+ <tr>
43
+ <th>tool</th>
44
+ <th>dude</th>
45
+ </tr>
46
+ <tr>
47
+ <td>webrat</td>
48
+ <td>bryan</td>
49
+ <td>crapola</td>
50
+ </tr>
51
+ <tr>
52
+ <td>cucumber</td>
53
+ <td>aslak</td>
54
+ <td>gunk</td>
55
+ <td>filth</td>
56
+ </tr>
57
+ </table>
58
+ HTML
59
+
60
+ _tableish(html, 'table#tools tr', 'td,th').should == [
61
+ ['tool', 'dude',],
62
+ ['webrat', 'bryan'],
63
+ ['cucumber', 'aslak']
64
+ ]
65
+ end
66
+
67
+ it "should pad with empty Strings if some rows are shorter" do
68
+ html = <<-HTML
69
+ <table id="tools">
70
+ <tr>
71
+ <th>tool</th>
72
+ <th>dude</th>
73
+ </tr>
74
+ <tr>
75
+ <td>webrat</td>
76
+ <td>bryan</td>
77
+ </tr>
78
+ <tr>
79
+ <td>cucumber</td>
80
+ </tr>
81
+ </table>
82
+ HTML
83
+
84
+ _tableish(html, 'table#tools tr', 'td,th').should == [
85
+ %w{tool dude},
86
+ %w{webrat bryan},
87
+ ['cucumber', '']
88
+ ]
89
+ end
90
+
91
+ it "should handle colspan and rowspan" do
92
+ html = <<-HTML
93
+ <table id="tools">
94
+ <tr>
95
+ <td rowspan="4">a</td>
96
+ <td>b</td>
97
+ <td>c</td>
98
+ <td>d</td>
99
+ </tr>
100
+ <tr>
101
+ <td colspan="3">e</td>
102
+ </tr>
103
+ <tr>
104
+ <td rowspan="2" colspan="2">f</td>
105
+ <td>g</td>
106
+ </tr>
107
+ <tr>
108
+ <td>h</td>
109
+ </tr>
110
+ </table>
111
+ HTML
112
+
113
+ _tableish(html, 'table#tools tr', 'td,th').should == [
114
+ ['a', 'b', 'c', 'd'],
115
+ ['', 'e', '', '' ],
116
+ ['', 'f', '', 'g' ],
117
+ ['', '', '', 'h' ],
118
+ ]
119
+ end
120
+
121
+ it "should convert a dl" do
122
+ html = <<-HTML
123
+ <dl id="tools">
124
+ <dt>webrat</dt>
125
+ <dd>bryan</dd>
126
+ <dt>cucumber</dt>
127
+ <dd>aslak</dd>
128
+ </dl>
129
+ HTML
130
+
131
+ _tableish(html, 'dl#tools dt', lambda{|dt| [dt, dt.next.next]}).should == [
132
+ %w{webrat bryan},
133
+ %w{cucumber aslak}
134
+ ]
135
+ end
136
+
137
+ it "should convert a ul" do
138
+ html = <<-HTML
139
+ <ul id="phony">
140
+ <li>nope</li>
141
+ </ul>
142
+
143
+ <ul id="yes">
144
+ <li>webrat</li>
145
+ <li>bryan</li>
146
+ <li>cucumber</li>
147
+ <li>aslak</li>
148
+ </ul>
149
+ HTML
150
+
151
+ _tableish(html, 'ul#yes li', lambda{|li| [li]}).should == [
152
+ %w{webrat},
153
+ %w{bryan},
154
+ %w{cucumber},
155
+ %w{aslak},
156
+ ]
157
+ end
158
+
159
+ it "should do complex shit" do
160
+ html = <<-HTML
161
+ <form method="post" action="/invoices/10/approve" class="button-to">
162
+ <div>
163
+ <input id="approve_invoice_10" type="submit" value="Approve" />
164
+ <input name="authenticity_token" type="hidden" value="WxKGVy3Y5zcvFEiFe66D/odoc3CicfMdAup4vzQfiZ0=" />
165
+ <span>Hello&nbsp;World<span>
166
+ </div>
167
+ </form>
168
+ <form method="post" action="/invoices/10/delegate" class="button-to">
169
+ <div>
170
+ <input id="delegate_invoice_10" type="submit" value="Delegate" />
171
+ <input name="authenticity_token" type="hidden" value="WxKGVy3Y5zcvFEiFe66D/odoc3CicfMdAup4vzQfiZ0=" />
172
+ <span>Hi There<span>
173
+ </div>
174
+ </form>
175
+ HTML
176
+
177
+ selectors = lambda do |form|
178
+ [
179
+ form.css('div input:nth-child(1)').first.attributes['value'],
180
+ form.css('span').first.text.gsub(/\302\240/, ' ')
181
+ ]
182
+ end
183
+
184
+ _tableish(html, 'form', selectors).should == [
185
+ ['Approve', "Hello World"],
186
+ ['Delegate', 'Hi There']
187
+ ]
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,84 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
2
+
3
+ # TODO using this seam as an interim way to get the file to load
4
+ module Config
5
+ CONFIG = {
6
+ 'bindir' => 'foo',
7
+ 'ruby_install_name' => 'bar'
8
+ }
9
+ end
10
+ require 'generators/cucumber/install/install_base'
11
+
12
+ module Cucumber
13
+ module Generators
14
+ describe InstallBase do
15
+ def instance_of_class_including(mixin)
16
+ Class.new do
17
+ include mixin
18
+ end.new
19
+ end
20
+
21
+ before(:each) do
22
+ Kernel.stub(:require => nil)
23
+
24
+ @generator = instance_of_class_including(Cucumber::Generators::InstallBase)
25
+ end
26
+
27
+ # This is a private method, but there was a bug in it where it
28
+ # defaulted to :testunit (the framework) when called to identify
29
+ # the driver
30
+ describe "#first_loadable" do
31
+ it "detects loadable libraries" do
32
+ Gem.should_receive(:available?).with('capybara').and_return(true)
33
+ @generator.send(:first_loadable, [['capybara', :capybara], ['webrat', :webrat ]]).should == :capybara
34
+ end
35
+
36
+ it "tries the given libraries in order" do
37
+ Gem.stub(:available?).with('capybara').and_return(false)
38
+ Gem.should_receive(:available?).with('webrat').and_return(true)
39
+ @generator.send(:first_loadable, [['capybara', :capybara], ['webrat', :webrat ]]).should == :webrat
40
+ end
41
+
42
+ it "returns nil if no libraries are available" do
43
+ Gem.stub(:available? => false)
44
+ @generator.send(:first_loadable, [['capybara', :capybara], ['webrat', :webrat ]]).should be_nil
45
+ end
46
+ end
47
+
48
+ # This is a private method, but there may have been a bug in it where
49
+ # it defaulted to :testunit (the framework) when called to identify
50
+ # the driver
51
+ describe "#detect_in_env" do
52
+ describe "when env.rb doesn't exist" do
53
+ it "returns nil" do
54
+ File.should_receive(:file?).with("features/support/env.rb").and_return(false)
55
+ @generator.send(:detect_in_env, [['capybara', :capybara], ['webrat', :webrat]]).should be_nil
56
+ end
57
+ end
58
+
59
+ describe "when env.rb exists" do
60
+ before(:each) do
61
+ File.stub(:file => true)
62
+ end
63
+
64
+ it "detects loadable libraries, choosing the first in the argument list" do
65
+ IO.should_receive(:read).with("features/support/env.rb").and_return("blah webrat capybara blah")
66
+ @generator.send(:detect_in_env, [['capybara', :capybara], ['webrat', :webrat]]).should == :capybara
67
+ end
68
+
69
+ it "tries the given libraries in order" do
70
+ IO.should_receive(:read).with("features/support/env.rb").and_return("blah webrat blah")
71
+ @generator.send(:detect_in_env, [['capybara', :capybara], ['webrat', :webrat]]).should == :webrat
72
+ end
73
+
74
+ it "returns nil if no libraries are available" do
75
+ IO.should_receive(:read).with("features/support/env.rb").and_return("blah blah")
76
+ @generator.send(:detect_in_env, [['capybara', :capybara], ['webrat', :webrat]]).should be_nil
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+ end
84
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --colour
@@ -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,63 @@
1
+ Feature: Manage <%= plural_name %>
2
+ In order to [goal]
3
+ [stakeholder]
4
+ wants [behaviour]
5
+
6
+ Scenario: Register new <%= singular_name %>
7
+ Given I am on the new <%= singular_name %> page
8
+ <% keyword = 'When' -%>
9
+ <% named_args.each do |arg| -%>
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 -%>
15
+ <% keyword = 'And' -%>
16
+ <% end -%>
17
+ And I press "Create"
18
+ <% keyword = 'Then' -%>
19
+ <% named_args.each do |arg| -%>
20
+ <%= keyword %> I should see "<%= arg.value(1) %>"
21
+ <% keyword = 'And' -%>
22
+ <% end -%>
23
+
24
+ <% if IO.read('features/support/env.rb') =~ /capybara/n -%>
25
+ # Rails generates Delete links that use Javascript to pop up a confirmation
26
+ # dialog and then do a HTTP POST request (emulated DELETE request).
27
+ #
28
+ # Capybara must use Culerity/Celerity or Selenium2 (webdriver) when pages rely
29
+ # on Javascript events. Only Culerity/Celerity supports clicking on confirmation
30
+ # dialogs.
31
+ #
32
+ # Since Culerity/Celerity and Selenium2 has some overhead, Cucumber-Rails will
33
+ # detect the presence of Javascript behind Delete links and issue a DELETE request
34
+ # instead of a GET request.
35
+ #
36
+ # You can turn this emulation off by tagging your scenario with @no-js-emulation.
37
+ # Turning on browser testing with @selenium, @culerity, @celerity or @javascript
38
+ # will also turn off the emulation. (See the Capybara documentation for
39
+ # details about those tags). If any of the browser tags are present, Cucumber-Rails
40
+ # will also turn off transactions and clean the database with DatabaseCleaner
41
+ # after the scenario has finished. This is to prevent data from leaking into
42
+ # the next scenario.
43
+ #
44
+ # Another way to avoid Cucumber-Rails' javascript emulation without using any
45
+ # of the tags above is to modify your views to use <button> instead. You can
46
+ # see how in http://github.com/jnicklas/capybara/issues#issue/12
47
+ #
48
+ <% if options[:capybara] -%>
49
+ @<%= options[:capybara] %>
50
+ <% end -%>
51
+ <% end -%>
52
+ Scenario: Delete <%= singular_name %>
53
+ Given the following <%= plural_name %>:
54
+ |<%= named_args.map(&:name).join('|') %>|
55
+ <% (1..4).each do |n| -%>
56
+ |<%= named_args.map{|arg| arg.value(n)}.join('|') %>|
57
+ <% end -%>
58
+ When I delete the 3rd <%= singular_name %>
59
+ Then I should see the following <%= plural_name %>:
60
+ |<%= named_args.map{|arg| arg.name.humanize}.join('|') %>|
61
+ <% [1,2,4].each do |n| -%>
62
+ |<%= named_args.map{|arg| arg.value(n)}.join('|') %>|
63
+ <% end -%>
@@ -0,0 +1,14 @@
1
+ Given /^the following <%= plural_name %>:$/ do |<%= plural_name %>|
2
+ <%= class_name %>.create!(<%= plural_name %>.hashes)
3
+ end
4
+
5
+ When /^I delete the (\d+)(?:st|nd|rd|th) <%= singular_name %>$/ do |pos|
6
+ visit <%= plural_name %>_path
7
+ within("table tr:nth-child(#{pos.to_i+1})") do
8
+ click_link "Destroy"
9
+ end
10
+ end
11
+
12
+ Then /^I should see the following <%= plural_name %>:$/ do |expected_<%= plural_name %>_table|
13
+ expected_<%= plural_name %>_table.diff!(tableish('table tr', 'td,th'))
14
+ end
@@ -0,0 +1,8 @@
1
+ <%%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
5
+ %>
6
+ default: <%= spork? ? '--drb ' : '' %><%%= std_opts %> features
7
+ wip: <%= spork? ? '--drb ' : '' %>--tags @wip:3 --wip features
8
+ rerun: <%= spork? ? '--drb ' : '' %><%%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -0,0 +1,37 @@
1
+ # Edit at your own peril - it's recommended to regenerate this file
2
+ # in the future when you upgrade to a newer version of Cucumber.
3
+
4
+ # IMPORTANT: Setting config.cache_classes to false is known to
5
+ # break Cucumber's use_transactional_fixtures method.
6
+ # For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Disable request forgery protection in test environment
17
+ config.action_controller.allow_forgery_protection = false
18
+
19
+ # Tell Action Mailer not to deliver emails to the real world.
20
+ # The :test delivery method accumulates sent emails in the
21
+ # ActionMailer::Base.deliveries array.
22
+ config.action_mailer.delivery_method = :test
23
+
24
+ config.gem 'cucumber-rails', :lib => false, :version => '>=<%= version %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails'))
25
+ config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner'))
26
+ <% if driver == :capybara -%>
27
+ config.gem 'capybara', :lib => false, :version => '>=0.3.5' unless File.directory?(File.join(Rails.root, 'vendor/plugins/capybara'))
28
+ <% else -%>
29
+ config.gem 'webrat', :lib => false, :version => '>=0.7.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
30
+ <% end -%>
31
+ <% if framework == :rspec -%>
32
+ config.gem 'rspec', :lib => false, :version => '>=1.3.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
33
+ config.gem 'rspec-rails', :lib => false, :version => '>=1.3.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
34
+ <% end %>
35
+ <% if spork? -%>
36
+ config.gem 'spork', :lib => false, :version => '>=0.7.5' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
37
+ <% end %>