cucumber-rails 0.1.1.rc4 → 0.1.1.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/History.txt +3 -0
  2. data/VERSION +1 -1
  3. data/cucumber-rails.gemspec +20 -15
  4. data/generators/cucumber/cucumber_generator.rb +50 -33
  5. data/generators/cucumber/templates/config/cucumber.yml.erb +7 -0
  6. data/generators/cucumber/templates/environments/cucumber.rb.erb +38 -0
  7. data/generators/cucumber/templates/{cucumber → script/cucumber} +0 -0
  8. data/generators/cucumber/templates/{web_steps/capybara_steps.rb → step_definitions/capybara_steps.rb.erb} +1 -4
  9. data/generators/cucumber/templates/{web_steps/web_steps_de.rb → step_definitions/web_steps_de.rb.erb} +1 -4
  10. data/generators/cucumber/templates/{web_steps/web_steps_no.rb → step_definitions/web_steps_no.rb.erb} +1 -4
  11. data/generators/cucumber/templates/{web_steps/web_steps_pt-BR.rb → step_definitions/web_steps_pt-BR.rb.erb} +1 -4
  12. data/generators/cucumber/templates/{web_steps/webrat_steps.rb → step_definitions/webrat_steps.rb.erb} +1 -4
  13. data/generators/cucumber/templates/support/_rails_each_run.rb +29 -0
  14. data/generators/cucumber/templates/support/_rails_prefork.rb.erb +16 -0
  15. data/generators/cucumber/templates/support/capybara.rb +8 -0
  16. data/generators/cucumber/templates/support/edit_warning.txt +4 -0
  17. data/generators/cucumber/templates/{paths.rb → support/paths.rb} +0 -0
  18. data/generators/cucumber/templates/support/rails.rb.erb +4 -0
  19. data/generators/cucumber/templates/support/rails_spork.rb.erb +13 -0
  20. data/generators/cucumber/templates/support/webrat.rb +8 -0
  21. data/generators/cucumber/templates/{cucumber.rake → tasks/cucumber.rake.erb} +2 -2
  22. data/generators/feature/templates/feature.erb +24 -0
  23. data/generators/feature/templates/steps.erb +1 -1
  24. data/lib/cucumber/rails/active_record.rb +6 -2
  25. data/lib/cucumber/rails/capybara_javascript_emulation.rb +47 -0
  26. data/lib/cucumber/rails/world.rb +0 -2
  27. data/lib/cucumber/web/tableish.rb +47 -3
  28. data/spec/cucumber/web/tableish_spec.rb +32 -6
  29. metadata +20 -15
  30. data/generators/cucumber/templates/capybara_env.rb +0 -24
  31. data/generators/cucumber/templates/cucumber_environment.rb +0 -36
  32. data/generators/cucumber/templates/env.rb +0 -26
  33. data/generators/cucumber/templates/spork_env.rb +0 -57
  34. data/generators/cucumber/templates/webrat_env.rb +0 -22
data/History.txt CHANGED
@@ -1,6 +1,9 @@
1
1
  == In Git
2
2
 
3
3
  === New features
4
+ * Added an @emulate_rails_javascript tag that will emulate onclick with Capybara (Aslak Hellesøy, Rob Holland)
5
+ * Added a smart config/cucumber.yml file that will rerun previously failing scenarios (Aslak Hellesøy)
6
+ * Support for Capybara. Run "script/generate --capybara" if you want that. (Rob Holland, Aslak Hellesøy)
4
7
  * New #tableish method to extract table-like data from a HTML page. Pure Nokogiri/CSS3/XPath. (Aslak Hellesøy)
5
8
 
6
9
  === Bugfixes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1.rc4
1
+ 0.1.1.rc5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cucumber-rails}
8
- s.version = "0.1.1.rc4"
8
+ s.version = "0.1.1.rc5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dennis Bl\303\266te", "Aslak Helles\303\270y", "Rob Holland"]
12
- s.date = %q{2009-12-07}
12
+ s.date = %q{2009-12-09}
13
13
  s.description = %q{Cucumber Generators and Runtime for Rails}
14
14
  s.email = %q{cukes@googlegroups.com}
15
15
  s.extra_rdoc_files = [
@@ -24,25 +24,30 @@ Gem::Specification.new do |s|
24
24
  "cucumber-rails.gemspec",
25
25
  "generators/cucumber/USAGE",
26
26
  "generators/cucumber/cucumber_generator.rb",
27
- "generators/cucumber/templates/capybara_env.rb",
28
- "generators/cucumber/templates/cucumber",
29
- "generators/cucumber/templates/cucumber.rake",
30
- "generators/cucumber/templates/cucumber_environment.rb",
31
- "generators/cucumber/templates/env.rb",
32
- "generators/cucumber/templates/paths.rb",
33
- "generators/cucumber/templates/spork_env.rb",
34
- "generators/cucumber/templates/web_steps/capybara_steps.rb",
35
- "generators/cucumber/templates/web_steps/web_steps_de.rb",
36
- "generators/cucumber/templates/web_steps/web_steps_no.rb",
37
- "generators/cucumber/templates/web_steps/web_steps_pt-BR.rb",
38
- "generators/cucumber/templates/web_steps/webrat_steps.rb",
39
- "generators/cucumber/templates/webrat_env.rb",
27
+ "generators/cucumber/templates/config/cucumber.yml.erb",
28
+ "generators/cucumber/templates/environments/cucumber.rb.erb",
29
+ "generators/cucumber/templates/script/cucumber",
30
+ "generators/cucumber/templates/step_definitions/capybara_steps.rb.erb",
31
+ "generators/cucumber/templates/step_definitions/web_steps_de.rb.erb",
32
+ "generators/cucumber/templates/step_definitions/web_steps_no.rb.erb",
33
+ "generators/cucumber/templates/step_definitions/web_steps_pt-BR.rb.erb",
34
+ "generators/cucumber/templates/step_definitions/webrat_steps.rb.erb",
35
+ "generators/cucumber/templates/support/_rails_each_run.rb",
36
+ "generators/cucumber/templates/support/_rails_prefork.rb.erb",
37
+ "generators/cucumber/templates/support/capybara.rb",
38
+ "generators/cucumber/templates/support/edit_warning.txt",
39
+ "generators/cucumber/templates/support/paths.rb",
40
+ "generators/cucumber/templates/support/rails.rb.erb",
41
+ "generators/cucumber/templates/support/rails_spork.rb.erb",
42
+ "generators/cucumber/templates/support/webrat.rb",
43
+ "generators/cucumber/templates/tasks/cucumber.rake.erb",
40
44
  "generators/feature/USAGE",
41
45
  "generators/feature/feature_generator.rb",
42
46
  "generators/feature/templates/feature.erb",
43
47
  "generators/feature/templates/steps.erb",
44
48
  "lib/cucumber/rails/action_controller.rb",
45
49
  "lib/cucumber/rails/active_record.rb",
50
+ "lib/cucumber/rails/capybara_javascript_emulation.rb",
46
51
  "lib/cucumber/rails/rspec.rb",
47
52
  "lib/cucumber/rails/test_unit.rb",
48
53
  "lib/cucumber/rails/world.rb",
@@ -8,58 +8,68 @@ class CucumberGenerator < Rails::Generator::Base
8
8
 
9
9
  attr_accessor :driver
10
10
  attr_accessor :framework
11
- attr_reader :language
11
+ attr_reader :language, :template_dir
12
12
 
13
13
  def initialize(runtime_args, runtime_options = {})
14
- super
15
- @language = @args.empty? ? 'en' : @args.first
14
+ super
15
+ @language = @args.empty? ? 'en' : @args.first
16
16
  end
17
17
 
18
18
  def manifest
19
19
  record do |m|
20
+ m.template 'config/cucumber.yml.erb', 'config/cucumber.yml'
21
+
22
+ m.template 'environments/cucumber.rb.erb', 'config/environments/cucumber.rb'
23
+
24
+ m.file 'script/cucumber', 'script/cucumber', {
25
+ :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
26
+ }
27
+
20
28
  m.directory 'features/step_definitions'
21
-
22
- m.template "web_steps/#{driver}_steps.rb", 'features/step_definitions/web_steps.rb'
29
+ m.template "step_definitions/#{driver}_steps.rb.erb", 'features/step_definitions/web_steps.rb'
23
30
  if language != 'en'
24
- m.template "web_steps/web_steps_#{language}.rb", "features/step_definitions/web_steps_#{language}.rb"
25
- end
26
- m.template 'cucumber_environment.rb', 'config/environments/cucumber.rb'
27
-
28
- m.gsub_file 'config/database.yml', /test:.*\n/, "test: &TEST\n"
29
- unless File.read('config/database.yml').include? 'cucumber:'
30
- m.gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *TEST"
31
+ m.template "step_definitions/web_steps_#{language}.rb.erb", "features/step_definitions/web_steps_#{language}.rb"
31
32
  end
32
33
 
33
34
  m.directory 'features/support'
34
35
  if spork?
35
- m.template'spork_env.rb', 'features/support/env.rb'
36
+ m.template 'support/rails_spork.rb.erb', 'features/support/env.rb'
36
37
  else
37
- m.template 'env.rb', 'features/support/env.rb'
38
- m.template "#{driver}_env.rb", "features/support/#{driver}.rb"
38
+ m.template 'support/rails.rb.erb', 'features/support/env.rb'
39
39
  end
40
- m.template 'paths.rb', 'features/support/paths.rb'
40
+ m.file 'support/paths.rb', 'features/support/paths.rb'
41
41
 
42
42
  m.directory 'lib/tasks'
43
- m.template'cucumber.rake', 'lib/tasks/cucumber.rake'
43
+ m.template 'tasks/cucumber.rake.erb', 'lib/tasks/cucumber.rake'
44
44
 
45
- m.file 'cucumber', 'script/cucumber', {
46
- :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
47
- }
45
+ m.gsub_file 'config/database.yml', /test:.*\n/, "test: &TEST\n"
46
+ unless File.read('config/database.yml').include? 'cucumber:'
47
+ m.gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *TEST"
48
+ end
48
49
  end
49
50
  end
50
51
 
51
52
  def framework
52
- options[:framework] ||= detect_default_framework!
53
+ options[:framework] ||= detect_current_framework || detect_default_framework
53
54
  end
54
55
 
55
56
  def driver
56
- options[:driver] ||= detect_current_driver! || detect_default_driver!
57
+ options[:driver] ||= detect_current_driver || detect_default_driver
57
58
  end
58
59
 
59
60
  def spork?
60
61
  options[:spork]
61
62
  end
62
63
 
64
+ def embed_file(source, indent='')
65
+ IO.read(File.join(File.dirname(__FILE__), 'templates', source)).gsub(/^/, indent)
66
+ end
67
+
68
+ def embed_template(source, indent='')
69
+ template = File.join(File.dirname(__FILE__), 'templates', source)
70
+ ERB.new(IO.read(template), nil, '-').result(binding).gsub(/^/, indent)
71
+ end
72
+
63
73
  private
64
74
 
65
75
  def first_loadable(libraries)
@@ -74,28 +84,35 @@ private
74
84
  return nil
75
85
  end
76
86
 
77
- def detect_current_driver!
78
- drivers = [['capybara', :capybara], ['webrat', :webrat ]]
79
- drivers.each do |driver|
80
- @current_driver = driver[1] if File.exists?("features/support/#{driver[0]}.rb")
81
- return @current_driver if @current_driver
82
- end
83
- return nil
87
+ def detect_current_driver
88
+ detect_in_env([['capybara', :capybara], ['webrat', :webrat ]])
84
89
  end
85
90
 
86
- def detect_default_driver!
87
- drivers = [['capybara', :capybara], ['webrat', :webrat ]]
88
- @default_driver = first_loadable(drivers)
91
+ def detect_default_driver
92
+ @default_driver = first_loadable([['capybara', :capybara], ['webrat', :webrat ]])
89
93
  raise "I don't know which driver you want. Use --capybara or --webrat, or gem install capybara or webrat." unless @default_driver
90
94
  @default_driver
91
95
  end
92
96
 
93
- def detect_default_framework!
97
+ def detect_current_framework
98
+ detect_in_env([['spec', :rspec], ['test/unit', :testunit]])
99
+ end
100
+
101
+ def detect_default_framework
94
102
  @default_framework = first_loadable([['spec', :rspec], ['test/unit', :testunit]])
95
103
  raise "I don't know what test framework you want. Use --rspec or --testunit, or gem install rspec or test-unit." unless @default_framework
96
104
  @default_framework
97
105
  end
98
106
 
107
+ def detect_in_env(choices)
108
+ env = File.file?("features/support/env.rb") ? IO.read("features/support/env.rb") : ''
109
+ choices.each do |choice|
110
+ detected = choice[1] if env =~ /#{choice[0]}/n
111
+ return detected if detected
112
+ end
113
+ return nil
114
+ end
115
+
99
116
  def banner
100
117
  "Usage: #{$0} cucumber (language)"
101
118
  end
@@ -0,0 +1,7 @@
1
+ <%%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "#{rerun_opts} --format rerun --out rerun.txt --strict --tags ~@wip"
5
+ %>
6
+ default: <%= spork? ? '--drb ' : '' %><%%= std_opts %>
7
+ wip: <%= spork? ? '--drb ' : '' %>--tags @wip:3 --wip features
@@ -0,0 +1,38 @@
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', :lib => false, :version => '>=<%= Cucumber::VERSION %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
25
+ <% if driver == :capybara -%>
26
+ config.gem 'capybara', :lib => false, :version => '>=0.1.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/capybara'))
27
+ <% else -%>
28
+ config.gem 'webrat', :lib => false, :version => '>=0.5.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
29
+ <% end -%>
30
+ <% if framework == :rspec -%>
31
+ config.gem 'rspec', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
32
+ config.gem 'rspec-rails', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
33
+ # If you never turn off transactions you may remove the dependency on database_cleaner.
34
+ config.gem 'database_cleaner', :lib => false, :version => '>=0.2.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner'))
35
+ <% end %>
36
+ <% if spork? -%>
37
+ config.gem 'spork', :lib => false, :version => '>=0.7.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
38
+ <% end %>
@@ -1,7 +1,4 @@
1
- # IMPORTANT: This file was generated.
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.
1
+ <%= embed_file('support/edit_warning.txt') %>
5
2
 
6
3
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
7
4
 
@@ -1,8 +1,5 @@
1
1
  # encoding: utf-8
2
- # IMPORTANT: This file was generated.
3
- # Edit at your own peril - it's recommended to regenerate this file
4
- # in the future when you upgrade to a newer version of Cucumber.
5
- # Consider adding your own code to a new file instead of editing this one.
2
+ <%= embed_file('support/edit_warning.txt') %>
6
3
 
7
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
8
5
 
@@ -1,8 +1,5 @@
1
1
  # encoding: utf-8
2
- # IMPORTANT: This file was generated.
3
- # Edit at your own peril - it's recommended to regenerate this file
4
- # in the future When you upgrade to a newer version of Cucumber.
5
- # Consider adding your own code to a new file instead of editing this one.
2
+ <%= embed_file('support/edit_warning.txt') %>
6
3
 
7
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
8
5
 
@@ -1,8 +1,5 @@
1
1
  # encoding: utf-8
2
- # IMPORTANT: This file was generated.
3
- # Edit at your own peril - it's recommended to regenerate this file
4
- # in the future when you upgrade to a newer version of Cucumber.
5
- # Consider adding your own code to a new file instead of editing this one.
2
+ <%= embed_file('support/edit_warning.txt') %>
6
3
 
7
4
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
8
5
 
@@ -1,7 +1,4 @@
1
- # IMPORTANT: This file was generated.
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.
1
+ <%= embed_file('support/edit_warning.txt') %>
5
2
 
6
3
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
7
4
 
@@ -0,0 +1,29 @@
1
+ # If you set this to false, any error raised from within your app will bubble
2
+ # up to your step definition and out to cucumber unless you catch it somewhere
3
+ # on the way. You can make Rails rescue errors and render error pages on a
4
+ # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
5
+ #
6
+ # If you set this to true, Rails will rescue all errors and render error
7
+ # pages, more or less in the same way your application would behave in the
8
+ # default production environment. It's not recommended to do this for all
9
+ # of your scenarios, as this makes it hard to discover errors in your application.
10
+ ActionController::Base.allow_rescue = false
11
+
12
+ # If you set this to true, each scenario will run in a database transaction.
13
+ # You can still turn off transactions on a per-scenario basis, simply tagging
14
+ # a feature or scenario with the @no-txn tag. If you are using Capybara,
15
+ # tagging with @culerity or @javascript will also turn transactions off.
16
+ #
17
+ # If you set this to false, transactions will be off for all scenarios,
18
+ # regardless of whether you use @no-txn or not.
19
+ #
20
+ # Beware that turning transactions off will leave data in your database
21
+ # after each scenario, which can lead to hard-to-debug failures in
22
+ # subsequent scenarios. If you do this, we recommend you create a Before
23
+ # block that will explicitly put your database in a known state.
24
+ Cucumber::Rails::World.use_transactional_fixtures = true
25
+
26
+ # How to clean your database when transactions are turned off. See
27
+ # http://github.com/bmabey/database_cleaner for more info.
28
+ require 'database_cleaner'
29
+ DatabaseCleaner.strategy = :truncation
@@ -0,0 +1,16 @@
1
+ ENV["RAILS_ENV"] ||= "cucumber"
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
3
+
4
+ require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
5
+ <% if framework == :rspec -%>
6
+ require 'cucumber/rails/rspec'
7
+ <% end -%>
8
+ require 'cucumber/rails/world'
9
+ require 'cucumber/rails/active_record'
10
+ require 'cucumber/web/tableish'
11
+ <% if driver == :webrat -%>
12
+ require 'cucumber/webrat/element_locator' # Deprecated in favor of #tableish - remove this line if you don't use #element_at or #table_at
13
+ <% end -%>
14
+ <% if driver == :capybara -%>
15
+ require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
16
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ require 'capybara/rails'
2
+ require 'capybara/cucumber'
3
+ require 'capybara/session'
4
+ # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
5
+ # order to ease the transition to Capybara we set the default here. If you'd
6
+ # prefer to use XPath just remove this line and adjust any selectors in your
7
+ # steps to use the XPath syntax.
8
+ Capybara.default_selector = :css
@@ -0,0 +1,4 @@
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.
@@ -0,0 +1,4 @@
1
+ <%= embed_file('support/edit_warning.txt') %>
2
+ <%= embed_template('support/_rails_prefork.rb.erb') %>
3
+ <%= embed_file("support/#{driver}.rb") %>
4
+ <%= embed_file('support/_rails_each_run.rb') %>
@@ -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/#{driver}.rb", ' ') %>
9
+ end
10
+
11
+ Spork.each_run do
12
+ <%= embed_file('support/_rails_each_run.rb', ' ') %>
13
+ end
@@ -0,0 +1,8 @@
1
+ require 'webrat'
2
+ require 'webrat/core/matchers'
3
+
4
+ Webrat.configure do |config|
5
+ config.mode = :rails
6
+ config.open_error_files = false # Set to true if you want error pages to pop up in the browser
7
+ end
8
+
@@ -16,13 +16,13 @@ begin
16
16
  Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
17
17
  t.binary = vendored_cucumber_binary
18
18
  t.fork = true # You may get faster startup if you set this to false
19
- t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}<%= spork? ? ' --drb' : '' %>"
19
+ t.profile = 'default'
20
20
  end
21
21
 
22
22
  Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
23
23
  t.binary = vendored_cucumber_binary
24
24
  t.fork = true # You may get faster startup if you set this to false
25
- t.cucumber_opts = "--color --tags @wip:2 --wip --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}<%= spork? ? ' --drb' : '' %>"
25
+ t.profile = 'wip'
26
26
  end
27
27
 
28
28
  desc 'Run all features'
@@ -21,6 +21,30 @@ Feature: Manage <%= plural_name %>
21
21
  <% keyword = 'And' -%>
22
22
  <% end -%>
23
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 or Selenium2 (webdriver) when pages rely on
29
+ # Javascript events. Only Culerity supports confirmation dialogs.
30
+ #
31
+ # cucumber-rails will turn off transactions for scenarios tagged with
32
+ # @culerity, @javascript or @no-txn and clean the database with DatabaseCleaner.
33
+ # after the scenario has finished. This is to prevent data from leaking into
34
+ # the next scenario.
35
+ #
36
+ # Culerity has some performance overhead, and there are two alternatives to using
37
+ # Culerity:
38
+ #
39
+ # a) You can remove the @culerity tag and run everything in-process, but then you
40
+ # also have to modify your views to use <button> instead: http://github.com/jnicklas/capybara/issues#issue/12
41
+ #
42
+ # b) Replace the @culerity tag with @emulate_rails_javascript. This will detect
43
+ # the onclick javascript and emulate its behaviour without a real Javascript
44
+ # interpreter.
45
+ #
46
+ @culerity
47
+ <% end -%>
24
48
  Scenario: Delete <%= singular_name %>
25
49
  Given the following <%= plural_name %>:
26
50
  |<%= named_args.map(&:name).join('|') %>|
@@ -4,7 +4,7 @@ end
4
4
 
5
5
  When /^I delete the (\d+)(?:st|nd|rd|th) <%= singular_name %>$/ do |pos|
6
6
  visit <%= plural_name %>_url
7
- within("table > tr:nth-child(#{pos.to_i+1})") do
7
+ within("table tr:nth-child(#{pos.to_i+1})") do
8
8
  click_link "Destroy"
9
9
  end
10
10
  end
@@ -3,17 +3,19 @@ if defined?(ActiveRecord::Base)
3
3
  $__cucumber_global_use_txn = !!Cucumber::Rails::World.use_transactional_fixtures if $__cucumber_global_use_txn.nil?
4
4
  end
5
5
 
6
- Before('~@no-txn') do
6
+ Before('~@no-txn', '~@culerity', '~@javascript') do
7
7
  Cucumber::Rails::World.use_transactional_fixtures = $__cucumber_global_use_txn
8
8
  end
9
9
 
10
- Before('@no-txn') do
10
+ Before('@no-txn', '@culerity', '@javascript') do
11
11
  Cucumber::Rails::World.use_transactional_fixtures = false
12
12
  end
13
13
 
14
14
  Before do
15
15
  if Cucumber::Rails::World.use_transactional_fixtures
16
16
  run_callbacks :setup if respond_to?(:run_callbacks)
17
+ else
18
+ DatabaseCleaner.start
17
19
  end
18
20
  ActionMailer::Base.deliveries = [] if defined?(ActionMailer::Base)
19
21
  end
@@ -21,6 +23,8 @@ if defined?(ActiveRecord::Base)
21
23
  After do
22
24
  if Cucumber::Rails::World.use_transactional_fixtures
23
25
  run_callbacks :teardown if respond_to?(:run_callbacks)
26
+ else
27
+ DatabaseCleaner.clean
24
28
  end
25
29
  end
26
30
  else
@@ -0,0 +1,47 @@
1
+ module Cucumber
2
+ module Rails
3
+ module CapybaraJavascriptEmulation
4
+ def self.included(base)
5
+ base.class_eval do
6
+ alias_method :click_without_rails_javascript_emulation, :click
7
+ end
8
+ end
9
+
10
+ def click_with_rails_javascript_emulation
11
+ if tag_name == 'a' and node['onclick'] =~ /m\.setAttribute\('name', '_method'\)/
12
+ method = node['onclick'].match(/m\.setAttribute\('value', '([^']*)'\)/)[1]
13
+
14
+ js_form = node.document.create_element('form')
15
+ js_form['action'] = self[:href]
16
+ js_form['method'] = 'POST'
17
+
18
+ input = node.document.create_element('input')
19
+ input['type'] = 'hidden'
20
+ input['name'] = '_method'
21
+ input['value'] = method
22
+ js_form.add_child(input)
23
+
24
+ Capybara::Driver::RackTest::Form.new(driver, js_form).submit(self)
25
+ else
26
+ click_without_rails_javascript_emulation
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ class Capybara::Driver::RackTest::Node
34
+ include Cucumber::Rails::CapybaraJavascriptEmulation
35
+ end
36
+
37
+ Before('@emulate_rails_javascript') do
38
+ Capybara::Driver::RackTest::Node.class_eval do
39
+ alias_method :click, :click_with_rails_javascript_emulation
40
+ end
41
+ end
42
+
43
+ After('@emulate_rails_javascript') do
44
+ Capybara::Driver::RackTest::Node.class_eval do
45
+ alias_method :click, :click_without_rails_javascript_emulation
46
+ end
47
+ end
@@ -23,8 +23,6 @@ module Cucumber #:nodoc:
23
23
  end
24
24
  end
25
25
 
26
- require 'cucumber/rails/active_record'
27
-
28
26
  World do
29
27
  Cucumber::Rails::World.new
30
28
  end
@@ -2,12 +2,53 @@ require 'nokogiri'
2
2
 
3
3
  module Cucumber
4
4
  module Tableish
5
+ # This method returns an Array of Array of String, using CSS3 selectors.
6
+ # This is particularly handy when using Cucumber's Table#diff! method.
7
+ #
8
+ # The +row_selector+ argument must be a String, and picks out all the rows
9
+ # from the web page's DOM. If the number of cells in each row differs, it
10
+ # will be constrained by (or padded with) the number of cells in the first row
11
+ #
12
+ # The +column_selectors+ argument must be a String or a Proc, picking out
13
+ # cells from each row. If you pass a Proc, it will be yielded an instance
14
+ # of Nokogiri::HTML::Element.
15
+ #
16
+ # == Example with a table
17
+ #
18
+ # <table id="tools">
19
+ # <tr>
20
+ # <th>tool</th>
21
+ # <th>dude</th>
22
+ # </tr>
23
+ # <tr>
24
+ # <td>webrat</td>
25
+ # <td>bryan</td>
26
+ # </tr>
27
+ # <tr>
28
+ # <td>cucumber</td>
29
+ # <td>aslak</td>
30
+ # </tr>
31
+ # </table>
32
+ #
33
+ # t = tableish('table#tools tr', 'td,th')
34
+ #
35
+ # == Example with a dl
36
+ #
37
+ # <dl id="tools">
38
+ # <dt>webrat</dt>
39
+ # <dd>bryan</dd>
40
+ # <dt>cucumber</dt>
41
+ # <dd>aslak</dd>
42
+ # </dl>
43
+ #
44
+ # t = tableish('dl#tools dt', lambda{|dt| [dt, dt.next.next]})
45
+ #
5
46
  def tableish(row_selector, column_selectors)
6
47
  html = defined?(Capybara) ? body : response_body
7
48
  _tableish(html, row_selector, column_selectors)
8
49
  end
9
50
 
10
- def _tableish(html, row_selector, column_selectors)
51
+ def _tableish(html, row_selector, column_selectors) #:nodoc
11
52
  doc = Nokogiri::HTML(html)
12
53
  column_count = nil
13
54
  doc.search(row_selector).map do |row|
@@ -18,10 +59,13 @@ module Cucumber
18
59
  column_selectors.call(row)
19
60
  end
20
61
  column_count ||= cells.length
21
- cells[0...column_count].map do |cell|
22
- cell.text.strip
62
+ (0...column_count).map do |n|
63
+ cell = cells[n]
64
+ cell ? cell.text.strip : ''
23
65
  end
24
66
  end
25
67
  end
26
68
  end
27
69
  end
70
+
71
+ World(Cucumber::Tableish)
@@ -1,4 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
+
3
+ def World(*a); end
2
4
  require 'cucumber/web/tableish'
3
5
 
4
6
  module Cucumber
@@ -9,7 +11,7 @@ module Cucumber
9
11
  unless RUBY_PLATFORM =~ /java/
10
12
  it "should convert a table" do
11
13
  html = <<-HTML
12
- <table>
14
+ <table id="tools">
13
15
  <tr>
14
16
  <th>tool</th>
15
17
  <th>dude</th>
@@ -25,7 +27,7 @@ module Cucumber
25
27
  </table>
26
28
  HTML
27
29
 
28
- _tableish(html, 'table tr', 'td,th').should == [
30
+ _tableish(html, 'table#tools tr', 'td,th').should == [
29
31
  %w{tool dude},
30
32
  %w{webrat bryan},
31
33
  %w{cucumber aslak}
@@ -34,7 +36,7 @@ module Cucumber
34
36
 
35
37
  it "should size to the first row" do
36
38
  html = <<-HTML
37
- <table>
39
+ <table id="tools">
38
40
  <tr>
39
41
  <th>tool</th>
40
42
  <th>dude</th>
@@ -53,16 +55,40 @@ module Cucumber
53
55
  </table>
54
56
  HTML
55
57
 
56
- _tableish(html, 'table tr', 'td,th').should == [
58
+ _tableish(html, 'table#tools tr', 'td,th').should == [
57
59
  %w{tool dude},
58
60
  %w{webrat bryan},
59
61
  %w{cucumber aslak}
60
62
  ]
61
63
  end
62
64
 
65
+ it "should pad with empty Strings if some rows are shorter" do
66
+ html = <<-HTML
67
+ <table id="tools">
68
+ <tr>
69
+ <th>tool</th>
70
+ <th>dude</th>
71
+ </tr>
72
+ <tr>
73
+ <td>webrat</td>
74
+ <td>bryan</td>
75
+ </tr>
76
+ <tr>
77
+ <td>cucumber</td>
78
+ </tr>
79
+ </table>
80
+ HTML
81
+
82
+ _tableish(html, 'table#tools tr', 'td,th').should == [
83
+ %w{tool dude},
84
+ %w{webrat bryan},
85
+ ['cucumber', '']
86
+ ]
87
+ end
88
+
63
89
  it "should convert a dl" do
64
90
  html = <<-HTML
65
- <dl>
91
+ <dl id="tools">
66
92
  <dt>webrat</dt>
67
93
  <dd>bryan</dd>
68
94
  <dt>cucumber</dt>
@@ -70,7 +96,7 @@ module Cucumber
70
96
  </dl>
71
97
  HTML
72
98
 
73
- _tableish(html, 'dl dt', lambda{|dt| [dt, dt.next.next]}).should == [
99
+ _tableish(html, 'dl#tools dt', lambda{|dt| [dt, dt.next.next]}).should == [
74
100
  %w{webrat bryan},
75
101
  %w{cucumber aslak}
76
102
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.rc4
4
+ version: 0.1.1.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Dennis Bl\xC3\xB6te"
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-12-07 00:00:00 +01:00
14
+ date: 2009-12-09 00:00:00 +01:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -41,25 +41,30 @@ files:
41
41
  - cucumber-rails.gemspec
42
42
  - generators/cucumber/USAGE
43
43
  - generators/cucumber/cucumber_generator.rb
44
- - generators/cucumber/templates/capybara_env.rb
45
- - generators/cucumber/templates/cucumber
46
- - generators/cucumber/templates/cucumber.rake
47
- - generators/cucumber/templates/cucumber_environment.rb
48
- - generators/cucumber/templates/env.rb
49
- - generators/cucumber/templates/paths.rb
50
- - generators/cucumber/templates/spork_env.rb
51
- - generators/cucumber/templates/web_steps/capybara_steps.rb
52
- - generators/cucumber/templates/web_steps/web_steps_de.rb
53
- - generators/cucumber/templates/web_steps/web_steps_no.rb
54
- - generators/cucumber/templates/web_steps/web_steps_pt-BR.rb
55
- - generators/cucumber/templates/web_steps/webrat_steps.rb
56
- - generators/cucumber/templates/webrat_env.rb
44
+ - generators/cucumber/templates/config/cucumber.yml.erb
45
+ - generators/cucumber/templates/environments/cucumber.rb.erb
46
+ - generators/cucumber/templates/script/cucumber
47
+ - generators/cucumber/templates/step_definitions/capybara_steps.rb.erb
48
+ - generators/cucumber/templates/step_definitions/web_steps_de.rb.erb
49
+ - generators/cucumber/templates/step_definitions/web_steps_no.rb.erb
50
+ - generators/cucumber/templates/step_definitions/web_steps_pt-BR.rb.erb
51
+ - generators/cucumber/templates/step_definitions/webrat_steps.rb.erb
52
+ - generators/cucumber/templates/support/_rails_each_run.rb
53
+ - generators/cucumber/templates/support/_rails_prefork.rb.erb
54
+ - generators/cucumber/templates/support/capybara.rb
55
+ - generators/cucumber/templates/support/edit_warning.txt
56
+ - generators/cucumber/templates/support/paths.rb
57
+ - generators/cucumber/templates/support/rails.rb.erb
58
+ - generators/cucumber/templates/support/rails_spork.rb.erb
59
+ - generators/cucumber/templates/support/webrat.rb
60
+ - generators/cucumber/templates/tasks/cucumber.rake.erb
57
61
  - generators/feature/USAGE
58
62
  - generators/feature/feature_generator.rb
59
63
  - generators/feature/templates/feature.erb
60
64
  - generators/feature/templates/steps.erb
61
65
  - lib/cucumber/rails/action_controller.rb
62
66
  - lib/cucumber/rails/active_record.rb
67
+ - lib/cucumber/rails/capybara_javascript_emulation.rb
63
68
  - lib/cucumber/rails/rspec.rb
64
69
  - lib/cucumber/rails/test_unit.rb
65
70
  - lib/cucumber/rails/world.rb
@@ -1,24 +0,0 @@
1
- require 'capybara/rails'
2
- require 'capybara/cucumber'
3
- require 'cucumber/web/tableish'
4
- World(Cucumber::Tableish)
5
-
6
- # If you set this to true, each scenario will run in a database transaction.
7
- # You can still turn off transactions on a per-scenario basis, simply tagging
8
- # a feature or scenario with the @no-txn tag.
9
- #
10
- # If you set this to false, transactions will be off for all scenarios,
11
- # regardless of whether you use @no-txn or not.
12
- #
13
- # Beware that turning transactions off will leave data in your database after
14
- # each scenario, which can lead to hard-to-debug failures in subsequent
15
- # scenarios. If you do this, we recommend you create a Before block that will
16
- # explicitly put your database in a known state.
17
- #
18
- Cucumber::Rails::World.use_transactional_fixtures = true
19
-
20
- # Capybara defaults to XPATH selectors rather than Webrat's default of CSS. In
21
- # order to ease the transition to Capybara we set the default here. If you'd
22
- # prefer to use XPATH just remove this line and adjust any selectors in your
23
- # steps to use the XPATH syntax.
24
- Capybara.default_selector = :css
@@ -1,36 +0,0 @@
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', :lib => false, :version => '>=<%= Cucumber::VERSION %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
25
- <% if driver == :capybara -%>
26
- config.gem 'capybara', :lib => false, :version => '>=0.1.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/capybara'))
27
- <% else -%>
28
- config.gem 'webrat', :lib => false, :version => '>=0.5.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
29
- <% end -%>
30
- <% if framework == :rspec -%>
31
- config.gem 'rspec', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
32
- config.gem 'rspec-rails', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
33
- <% end %>
34
- <% if spork? -%>
35
- config.gem 'spork', :lib => false, :version => '>=0.7.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
36
- <% end %>
@@ -1,26 +0,0 @@
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
- # Consider adding your own code to a new file instead of editing this one.
4
-
5
- # Sets up the Rails environment for Cucumber
6
- ENV["RAILS_ENV"] ||= "cucumber"
7
- require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
8
- require 'cucumber/rails/world'
9
-
10
- # If you set this to false, any error raised from within your app will bubble
11
- # up to your step definition and out to cucumber unless you catch it somewhere
12
- # on the way. You can make Rails rescue errors and render error pages on a
13
- # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
14
- #
15
- # If you set this to true, Rails will rescue all errors and render error
16
- # pages, more or less in the same way your application would behave in the
17
- # default production environment. It's not recommended to do this for all
18
- # of your scenarios, as this makes it hard to discover errors in your application.
19
- ActionController::Base.allow_rescue = false
20
-
21
- require 'cucumber'
22
- # Comment out the next line if you don't want Cucumber Unicode support
23
- require 'cucumber/formatter/unicode'
24
- <% if framework == :rspec -%>
25
- require 'cucumber/rails/rspec'
26
- <% end -%>
@@ -1,57 +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 'rubygems'
7
- require 'spork'
8
-
9
- Spork.prefork do
10
- # Sets up the Rails environment for Cucumber
11
- ENV["RAILS_ENV"] = "cucumber"
12
- require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
13
- require 'cucumber/rails/world'
14
-
15
- require 'cucumber'
16
- # Comment out the next line if you don't want Cucumber Unicode support
17
- require 'cucumber/formatter/unicode'
18
- require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table)
19
- <% if framework == :rspec -%>
20
- require 'cucumber/rails/rspec'
21
- <% end -%>
22
-
23
- require 'webrat'
24
- require 'webrat/core/matchers'
25
- Webrat.configure do |config|
26
- config.mode = :rails
27
- config.open_error_files = false # Set to true if you want error pages to pop up in the browser
28
- end
29
- end
30
-
31
- Spork.each_run do
32
- # This code will be run each time you start cucumber.
33
-
34
- # If you set this to true, each scenario will run in a database transaction.
35
- # You can still turn off transactions on a per-scenario basis, simply tagging
36
- # a feature or scenario with the @no-txn tag.
37
- #
38
- # If you set this to false, transactions will be off for all scenarios,
39
- # regardless of whether you use @no-txn or not.
40
- #
41
- # Beware that turning transactions off will leave data in your database
42
- # after each scenario, which can lead to hard-to-debug failures in
43
- # subsequent scenarios. If you do this, we recommend you create a Before
44
- # block that will explicitly put your database in a known state.
45
- Cucumber::Rails::World.use_transactional_fixtures = true
46
-
47
- # If you set this to false, any error raised from within your app will bubble
48
- # up to your step definition and out to cucumber unless you catch it somewhere
49
- # on the way. You can make Rails rescue errors and render error pages on a
50
- # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
51
- #
52
- # If you set this to true, Rails will rescue all errors and render error
53
- # pages, more or less in the same way your application would behave in the
54
- # default production environment. It's not recommended to do this for all
55
- # of your scenarions, as this makes it hard to discover errors in your application.
56
- ActionController::Base.allow_rescue = false
57
- end
@@ -1,22 +0,0 @@
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