cucumber-rails 0.3.2 → 0.4.0.beta.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 (47) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +2 -0
  5. data/History.txt +7 -0
  6. data/README.rdoc +2 -2
  7. data/Rakefile +3 -19
  8. data/cucumber-rails.gemspec +25 -106
  9. data/dev_tasks/rspec.rake +6 -11
  10. data/features/rails2.feature +5 -24
  11. data/features/rails3.feature +82 -56
  12. data/features/step_definitions/cucumber_rails_steps.rb +3 -25
  13. data/features/support/env.rb +3 -1
  14. data/generators/cucumber/cucumber_generator.rb +1 -17
  15. data/lib/cucumber/rails.rb +29 -0
  16. data/lib/cucumber/rails/capybara/javascript_emulation.rb +83 -0
  17. data/lib/cucumber/rails/capybara/select_dates_and_times.rb +43 -0
  18. data/lib/cucumber/rails/hooks/allow_rescue.rb +8 -0
  19. data/lib/cucumber/rails/hooks/database_cleaner.rb +25 -0
  20. data/lib/cucumber/rails/hooks/mail.rb +5 -0
  21. data/lib/cucumber/rails/rspec.rb +0 -3
  22. data/lib/cucumber/rails/version.rb +15 -0
  23. data/lib/cucumber/rails/world.rb +2 -36
  24. data/lib/cucumber/rails2.rb +16 -0
  25. data/lib/cucumber/rails2/action_controller.rb +29 -0
  26. data/lib/cucumber/rails3.rb +16 -0
  27. data/lib/cucumber/rails3/action_controller.rb +12 -0
  28. data/lib/cucumber/rails3/application.rb +17 -0
  29. data/lib/generators/cucumber/feature/feature_generator.rb +1 -1
  30. data/lib/generators/cucumber/install/install_base.rb +40 -53
  31. data/lib/generators/cucumber/install/install_generator.rb +10 -22
  32. data/spec/cucumber/web/tableish_spec.rb +47 -0
  33. data/spec/generators/cucumber/install/install_base_spec.rb +0 -9
  34. data/spec/spec_helper.rb +1 -4
  35. data/templates/install/step_definitions/capybara_steps.rb.erb +1 -1
  36. data/templates/install/step_definitions/web_steps_da.rb.erb +1 -1
  37. data/templates/install/step_definitions/web_steps_no.rb.erb +1 -1
  38. data/templates/install/step_definitions/web_steps_pt-BR.rb.erb +2 -1
  39. data/templates/install/support/_rails_each_run.rb.erb +16 -15
  40. data/templates/install/support/_rails_prefork.rb.erb +1 -12
  41. data/templates/install/support/capybara.rb +0 -4
  42. metadata +137 -30
  43. data/lib/cucumber/rails/action_controller.rb +0 -65
  44. data/lib/cucumber/rails/active_record.rb +0 -34
  45. data/lib/cucumber/rails/capybara_javascript_emulation.rb +0 -72
  46. data/lib/cucumber/rails/test_unit.rb +0 -7
  47. data/spec/spec.opts +0 -2
@@ -1,4 +1,6 @@
1
+ ENV['CUCUMBER_RAILS_TEST'] = 'yeah baby'
1
2
  $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
3
  require 'rubygems'
4
+ require 'bundler/setup'
3
5
  require 'rspec/expectations'
4
- require 'aruba'
6
+ require 'aruba/cucumber'
@@ -1,9 +1,7 @@
1
- require 'rbconfig'
2
1
  require File.expand_path(File.join(File.dirname(__FILE__), '../../lib/generators/cucumber/install/install_base'))
3
2
 
4
3
  # This generator bootstraps a Rails project for use with Cucumber
5
4
  class CucumberGenerator < Rails::Generator::Base
6
-
7
5
  include Cucumber::Generators::InstallBase
8
6
 
9
7
  attr_accessor :driver
@@ -17,13 +15,7 @@ class CucumberGenerator < Rails::Generator::Base
17
15
 
18
16
  def manifest
19
17
  record do |m|
20
- check_upgrade_limitations
21
- create_templates(m, true)
22
- create_scripts(m, true)
23
- create_step_definitions(m, true)
24
- create_feature_support(m, true)
25
- create_tasks(m, true)
26
- create_database(m, true)
18
+ install_cucumber_rails(m)
27
19
  end
28
20
  end
29
21
 
@@ -35,10 +27,6 @@ class CucumberGenerator < Rails::Generator::Base
35
27
  options[:driver] ||= detect_current_driver || detect_default_driver
36
28
  end
37
29
 
38
- def cucumber_rails_env
39
- 'cucumber'
40
- end
41
-
42
30
  def self.gem_root
43
31
  File.expand_path('../../../', __FILE__)
44
32
  end
@@ -57,10 +45,6 @@ class CucumberGenerator < Rails::Generator::Base
57
45
  "Usage: #{$0} cucumber (language)"
58
46
  end
59
47
 
60
- def after_generate
61
- print_instructions
62
- end
63
-
64
48
  def add_options!(opt)
65
49
  opt.separator ''
66
50
  opt.separator 'Options:'
@@ -0,0 +1,29 @@
1
+ require 'rails'
2
+ if Rails.version.to_f < 3.0
3
+ require 'cucumber/rails2'
4
+ else
5
+ require 'cucumber/rails3'
6
+ end
7
+
8
+ require 'cucumber/rails/world'
9
+ require 'cucumber/rails/hooks/database_cleaner'
10
+ require 'cucumber/rails/hooks/allow_rescue'
11
+
12
+ if defined?(Capybara)
13
+ require 'capybara/rails'
14
+ require 'capybara/cucumber'
15
+ require 'capybara/session'
16
+ require 'cucumber/rails/capybara/javascript_emulation'
17
+ require 'cucumber/rails/capybara/select_dates_and_times'
18
+ end
19
+
20
+ if defined?(Webrat)
21
+ end
22
+
23
+ require 'cucumber/web/tableish'
24
+
25
+ if !defined?(ActiveRecord::Base)
26
+ module Cucumber::Rails
27
+ def World.fixture_table_names; []; end # Workaround for projects that don't use ActiveRecord
28
+ end
29
+ end
@@ -0,0 +1,83 @@
1
+ module Cucumber
2
+ module Rails
3
+ module Capybara
4
+ module JavascriptEmulation
5
+ def self.included(base)
6
+ base.class_eval do
7
+ alias_method :click_without_javascript_emulation, :click
8
+ alias_method :click, :click_with_javascript_emulation
9
+ end
10
+ end
11
+
12
+ def click_with_javascript_emulation
13
+ if link_with_non_get_http_method?
14
+ ::Capybara::Driver::RackTest::Form.new(driver, js_form(element_node.document, self[:href], emulated_method)).submit(self)
15
+ else
16
+ click_without_javascript_emulation
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def js_form(document, action, emulated_method, method = 'POST')
23
+ js_form = document.create_element('form')
24
+ js_form['action'] = action
25
+ js_form['method'] = method
26
+
27
+ if emulated_method and emulated_method.downcase != method.downcase
28
+ input = document.create_element('input')
29
+ input['type'] = 'hidden'
30
+ input['name'] = '_method'
31
+ input['value'] = emulated_method
32
+ js_form.add_child(input)
33
+ end
34
+
35
+ js_form
36
+ end
37
+
38
+ def link_with_non_get_http_method?
39
+ if ::Rails.version.to_f >= 3.0
40
+ tag_name == 'a' && element_node['data-method'] && element_node['data-method'] =~ /(?:delete|put|post)/
41
+ else
42
+ tag_name == 'a' && element_node['onclick'] && element_node['onclick'] =~ /var f = document\.createElement\('form'\); f\.style\.display = 'none';/
43
+ end
44
+ end
45
+
46
+ def emulated_method
47
+ if ::Rails.version.to_f >= 3.0
48
+ element_node['data-method']
49
+ else
50
+ element_node['onclick'][/m\.setAttribute\('value', '([^']*)'\)/, 1]
51
+ end
52
+ end
53
+
54
+ def element_node
55
+ if self.respond_to? :native
56
+ self.native
57
+ else
58
+ warn "DEPRECATED: cucumber-rails loves you, just not your version of Capybara. Please update Capybara to >= 0.4.0"
59
+ self.node
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ class Capybara::Driver::RackTest::Node
68
+ include ::Cucumber::Rails::Capybara::JavascriptEmulation
69
+ end
70
+
71
+ Before('~@no-js-emulation') do
72
+ # Enable javascript emulation
73
+ ::Capybara::Driver::RackTest::Node.class_eval do
74
+ alias_method :click, :click_with_javascript_emulation
75
+ end
76
+ end
77
+
78
+ Before('@no-js-emulation') do
79
+ # Disable javascript emulation
80
+ ::Capybara::Driver::RackTest::Node.class_eval do
81
+ alias_method :click, :click_without_javascript_emulation
82
+ end
83
+ end
@@ -0,0 +1,43 @@
1
+ module Cucumber
2
+ module Rails
3
+ module Capybara
4
+ module SelectDatesAndTimes
5
+ def select_date(field, options = {})
6
+ date = Date.parse(options[:with])
7
+ within(:xpath, ::Capybara::XPath.fieldset(field).append(%Q{//p[label[contains(., "#{field}")]]})) do
8
+ find(:xpath, '//select[contains(@id, "_1i")]').select(date.year)
9
+ find(:xpath, '//select[contains(@id, "_2i")]').select(date.strftime('%B'))
10
+ find(:xpath, '//select[contains(@id, "_3i")]').select(date.day)
11
+ end
12
+ end
13
+
14
+ def select_time(field, options = {})
15
+ time = Time.parse(options[:with])
16
+ within(:xpath, ::Capybara::XPath.fieldset(field).append(%Q{//p[label[contains(., "#{field}")]]})) do
17
+ find(:xpath, '//select[contains(@id, "_4i")]').select(time.hour.to_s.rjust(2,'0'))
18
+ find(:xpath, '//select[contains(@id, "_5i")]').select(time.min.to_s.rjust(2,'0'))
19
+ end
20
+ end
21
+
22
+ def select_datetime(field, options = {})
23
+ select_date(field, options)
24
+ select_time(field, options)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ World(::Cucumber::Rails::Capybara::SelectDatesAndTimes)
32
+
33
+ When /^(?:|I )select "([^"]*)" as the "([^"]*)" time$/ do |time, selector|
34
+ select_time(selector, :with => time)
35
+ end
36
+
37
+ When /^(?:|I )select "([^"]*)" as the "([^"]*)" date$/ do |date, selector|
38
+ select_date(selector, :with => date)
39
+ end
40
+
41
+ When /^(?:|I )select "([^"]*)" as the "([^"]*)" date and time$/ do |datetime, selector|
42
+ select_datetime(selector, :with => datetime)
43
+ end
@@ -0,0 +1,8 @@
1
+ Before('@allow-rescue') do
2
+ @__orig_allow_rescue = ActionController::Base.allow_rescue
3
+ ActionController::Base.allow_rescue = true
4
+ end
5
+
6
+ After('@allow-rescue') do
7
+ ActionController::Base.allow_rescue = @__orig_allow_rescue
8
+ end
@@ -0,0 +1,25 @@
1
+ begin
2
+ require 'database_cleaner'
3
+
4
+ Before do
5
+ $__cucumber_global_use_txn = !!Cucumber::Rails::World.use_transactional_fixtures if $__cucumber_global_use_txn.nil?
6
+ end
7
+
8
+ Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
9
+ Cucumber::Rails::World.use_transactional_fixtures = $__cucumber_global_use_txn
10
+ end
11
+
12
+ Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
13
+ Cucumber::Rails::World.use_transactional_fixtures = false
14
+ end
15
+
16
+ Before do
17
+ DatabaseCleaner.start
18
+ end
19
+
20
+ After do
21
+ DatabaseCleaner.clean
22
+ end
23
+
24
+ rescue LoadError => ignore_if_database_cleaner_not_present
25
+ end
@@ -0,0 +1,5 @@
1
+ if defined?(ActionMailer::Base)
2
+ Before do
3
+ ActionMailer::Base.deliveries = []
4
+ end
5
+ end
@@ -1,6 +1,3 @@
1
- # TODO: Not even sure is this is necessary anymore, since we're doing this in Cucumber's rb_world.rb...
2
- require 'cucumber/rails/world'
3
-
4
1
  begin
5
2
  require 'rspec/rails/matchers'
6
3
 
@@ -0,0 +1,15 @@
1
+ module Cucumber
2
+ module Rails
3
+ VERSION = '0.4.0.beta.1'
4
+ DEPS = {
5
+ 'cucumber' => '~> 0.10.0',
6
+ 'rails' => '~> 3.0.3',
7
+ 'capybara' => '~> 0.4.0',
8
+ 'webrat' => '~> 0.7.2',
9
+ 'rspec-rails' => '~> 2.2.0',
10
+ 'database_cleaner' => '~> 0.6.0',
11
+ 'sqlite3-ruby' => '~> 1.3.2',
12
+ 'aruba' => '~> 0.2.7'
13
+ }
14
+ end
15
+ end
@@ -1,40 +1,6 @@
1
- unless defined?(Test)
2
- begin
3
- require 'spec/test/unit'
4
- rescue LoadError => ignore_if_rspec_not_installed
5
- end
6
- end
7
-
8
- if defined?(ActiveRecord::Base)
9
- if Rails.version.to_f >= 3.0
10
- require 'rails/test_help'
11
- else
12
- require 'test_help'
13
- end
14
- else
15
- # I can't do rescue LoadError because in this files could be loaded
16
- # from rails gem (ie. load actionpack 2.3.5 if rubygems are not disabled)
17
- if Rails.version.to_f < 3.0
18
- require 'action_controller/test_process'
19
- require 'action_controller/integration'
20
- else
21
- require 'action_dispatch/testing/test_process'
22
- require 'action_dispatch/testing/integration'
23
- end
24
- end
25
-
26
- require 'cucumber/rails/test_unit'
27
- require 'cucumber/rails/action_controller'
28
-
29
-
30
- if (::Rails.respond_to?(:application) && !(::Rails.application.config.cache_classes)) ||
31
- (!(::Rails.respond_to?(:application)) && ::Rails.respond_to?(:configuration) && !(::Rails.configuration.cache_classes))
32
- warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb). This setting is known to break Cucumber's use_transactional_fixtures method. Set config.cache_classes to true if you want to use transactional fixtures. For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
33
- end
34
-
35
1
  module Cucumber #:nodoc:
36
- module Rails
37
- class World < ActionController::IntegrationTest
2
+ module Rails #:nodoc:
3
+ class World < ActionController::IntegrationTest #:nodoc:
38
4
  include ActiveSupport::Testing::SetupAndTeardown if ActiveSupport::Testing.const_defined?("SetupAndTeardown")
39
5
  def initialize #:nodoc:
40
6
  @_result = Test::Unit::TestResult.new if defined?(Test::Unit::TestResult)
@@ -0,0 +1,16 @@
1
+ require 'cucumber/rails2/action_controller'
2
+ ENV["RAILS_ENV"] ||= "cucumber"
3
+ env = caller.detect{|f| f =~ /\/env\.rb:/}
4
+ require File.expand_path(File.dirname(env) + '/../../config/environment')
5
+
6
+
7
+ if defined?(ActiveRecord::Base)
8
+ require 'test_help'
9
+ else
10
+ require 'action_dispatch/testing/test_process'
11
+ require 'action_dispatch/testing/integration'
12
+ end
13
+
14
+ if !Rails.configuration.cache_classes
15
+ warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb). This setting is known to break Cucumber's use_transactional_fixtures method. Set config.cache_classes to true if you want to use transactional fixtures. For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
16
+ end
@@ -0,0 +1,29 @@
1
+ ActionController::Base.class_eval do
2
+ cattr_accessor :allow_rescue
3
+
4
+ alias_method :rescue_action_without_bypass, :rescue_action
5
+
6
+ def rescue_action(exception)
7
+ if ActionController::Base.allow_rescue
8
+ rescue_action_without_bypass(exception)
9
+ else
10
+ raise exception
11
+ end
12
+ end
13
+ end
14
+
15
+ begin
16
+ ActionController::Failsafe.class_eval do
17
+ alias_method :failsafe_response_without_bypass, :failsafe_response
18
+
19
+ def failsafe_response(exception)
20
+ raise exception
21
+ end
22
+ end
23
+ rescue NameError # Failsafe was introduced in Rails 2.3.2
24
+ ActionController::Dispatcher.class_eval do
25
+ def self.failsafe_response(output, status, exception = nil)
26
+ raise exception
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ require 'cucumber/rails3/application'
2
+ ENV["RAILS_ENV"] ||= "test"
3
+ env = caller.detect{|f| f =~ /\/env\.rb:/}
4
+ require File.expand_path(File.dirname(env) + '/../../config/environment')
5
+ require 'cucumber/rails3/action_controller'
6
+
7
+ if defined?(ActiveRecord::Base)
8
+ require 'rails/test_help'
9
+ else
10
+ require 'action_controller/test_process'
11
+ require 'action_controller/integration'
12
+ end
13
+
14
+ if !Rails.application.config.cache_classes
15
+ warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/test.rb). This setting is known to break Cucumber's use_transactional_fixtures method. Set config.cache_classes to true if you want to use transactional fixtures. For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
16
+ end
@@ -0,0 +1,12 @@
1
+ ActionController::Base.class_eval do
2
+ cattr_accessor :allow_rescue
3
+ end
4
+
5
+ class ActionDispatch::ShowExceptions
6
+ alias __cucumber_orig_call__ call
7
+
8
+ def call(env)
9
+ env['action_dispatch.show_exceptions'] = !!ActionController::Base.allow_rescue
10
+ __cucumber_orig_call__(env)
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails/application'
2
+
3
+ # Make sure the ActionDispatch::ShowExceptions middleware is always enabled,
4
+ # regardless of what is in config/environments/test.rb
5
+ # Instead we are overriding ActionDispatch::ShowExceptions to be able to
6
+ # toggle whether or not exceptions are raised.
7
+ class Rails::Application
8
+ alias __cucumber_orig_initialize__ initialize!
9
+
10
+ def initialize!
11
+ ad = config.action_dispatch
12
+ def ad.show_exceptions
13
+ true
14
+ end
15
+ __cucumber_orig_initialize__
16
+ end
17
+ end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'named_arg')
2
2
  require File.join(File.dirname(__FILE__), 'feature_base')
3
3
 
4
4
  module Cucumber
5
- class FeatureGenerator < Rails::Generators::NamedBase
5
+ class FeatureGenerator < ::Rails::Generators::NamedBase
6
6
 
7
7
  include Cucumber::Generators::FeatureBase
8
8
 
@@ -1,9 +1,28 @@
1
+ require 'rbconfig'
2
+ #require 'cucumber/rails/version'
3
+
1
4
  module Cucumber
2
5
  module Generators
3
6
  module InstallBase
4
-
5
7
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
6
8
 
9
+ def install_cucumber_rails(m)
10
+ check_upgrade_limitations
11
+ create_templates(m)
12
+ create_scripts(m)
13
+ create_step_definitions(m)
14
+ create_feature_support(m)
15
+ create_tasks(m)
16
+ create_database(m) unless options[:skip_database]
17
+
18
+ cucumber_rails_options = {:group => :test}
19
+ cucumber_rails_options[:path] = '../../..' if ENV['CUCUMBER_RAILS_TEST']
20
+ add_gem('cucumber-rails', Cucumber::Rails::VERSION, cucumber_rails_options)
21
+ add_gem(driver_from_options.to_s, Cucumber::Rails::DEPS[driver_from_options.to_s], :group => :test)
22
+ add_gem(framework_from_options.to_s, Cucumber::Rails::DEPS[framework_from_options.to_s], :group => :test)
23
+ add_gem('database_cleaner', Cucumber::Rails::DEPS['database_cleaner'], :group => :test)
24
+ end
25
+
7
26
  # Checks and prints the limitations
8
27
  def check_upgrade_limitations
9
28
  if File.exist?('features/step_definitions/webrat_steps.rb')
@@ -20,37 +39,15 @@ module Cucumber
20
39
  end
21
40
 
22
41
  # Creates templates
23
- def create_templates(m = self, rails2 = false)
42
+ def create_templates(m)
24
43
  m.template 'config/cucumber.yml.erb', 'config/cucumber.yml'
25
- if rails2
44
+ if rails2?
26
45
  m.template 'environments/cucumber.rb.erb', 'config/environments/cucumber.rb'
27
46
  end
28
47
  end
29
48
 
30
- def configure_gemfile(m = self, rails2 = false)
31
- require 'thor-ext'
32
- unless rails2
33
- puts "Update Rails 3 Gemfile for cucumber"
34
- gsub_file 'Gemfile', /('|")gem/, "\1\ngem"
35
- add_gem('database_cleaner', '>=0.5.2') unless has_plugin? 'database_cleaner'
36
- if driver == :capybara
37
- add_gem('capybara', '>=0.3.7')
38
- else
39
- add_gem('webrat', '>=0.7.0') unless has_plugin? 'webrat'
40
- end
41
- if framework == :rspec
42
- add_gem('rspec', '>=1.3.0') unless has_plugin? 'rspec'
43
- add_gem('rspec-rails', '>=1.3.2') unless has_plugin? 'rspec-rails'
44
- end
45
- if spork?
46
- add_gem('spork''>=0.7.5') unless has_plugin? 'spork'
47
- end
48
- add_gems(%w{cucumber cucumber-rails})
49
- end
50
- end
51
-
52
- def create_scripts(m = self, rails2 = false)
53
- if rails2
49
+ def create_scripts(m)
50
+ if rails2?
54
51
  m.file 'script/cucumber', 'script/cucumber', {
55
52
  :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
56
53
  }
@@ -60,8 +57,8 @@ module Cucumber
60
57
  end
61
58
  end
62
59
 
63
- def create_step_definitions(m = self, rails2 = false)
64
- if rails2
60
+ def create_step_definitions(m)
61
+ if rails2?
65
62
  m.directory 'features/step_definitions'
66
63
  else
67
64
  m.empty_directory 'features/step_definitions'
@@ -73,8 +70,8 @@ module Cucumber
73
70
  end
74
71
  end
75
72
 
76
- def create_feature_support(m = self, rails2 = false)
77
- if rails2
73
+ def create_feature_support(m)
74
+ if rails2?
78
75
  m.directory 'features/support'
79
76
  m.file 'support/paths.rb', 'features/support/paths.rb'
80
77
 
@@ -95,8 +92,8 @@ module Cucumber
95
92
  end
96
93
  end
97
94
 
98
- def create_tasks(m = self, rails2 = false)
99
- if rails2
95
+ def create_tasks(m)
96
+ if rails2?
100
97
  m.directory 'lib/tasks'
101
98
  else
102
99
  m.empty_directory 'lib/tasks'
@@ -105,7 +102,7 @@ module Cucumber
105
102
  m.template 'tasks/cucumber.rake.erb', 'lib/tasks/cucumber.rake'
106
103
  end
107
104
 
108
- def create_database(m = self, rails2 = false)
105
+ def create_database(m)
109
106
  unless File.read('config/database.yml').include? 'cucumber:'
110
107
  m.gsub_file 'config/database.yml', /^test:.*\n/, "test: &test\n"
111
108
  m.gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *test"
@@ -115,29 +112,15 @@ module Cucumber
115
112
  end
116
113
  end
117
114
 
118
- def print_instructions
119
- require 'cucumber/formatter/ansicolor'
120
- extend Cucumber::Formatter::ANSIColor
121
-
122
- if @default_driver
123
- puts <<-WARNING
124
-
125
- #{yellow_cukes(15)}
126
-
127
- #{yellow_cukes(1)} D R I V E R A L E R T #{yellow_cukes(1)}
128
-
129
- You didn't explicitly generate with --capybara or --webrat, so I looked at
130
- your gems and saw that you had #{green(@default_driver.to_s)} installed, so I went with that.
131
- If you want something else, be specific about it. Otherwise, relax.
132
-
133
- #{yellow_cukes(15)}
115
+ protected
134
116
 
135
- WARNING
117
+ def add_gem(*args)
118
+ if rails2?
119
+ else
120
+ self.gem(*args)
136
121
  end
137
122
  end
138
123
 
139
- protected
140
-
141
124
  def detect_current_driver
142
125
  detect_in_env([['capybara', :capybara], ['webrat', :webrat]])
143
126
  end
@@ -162,6 +145,10 @@ module Cucumber
162
145
  options[:spork]
163
146
  end
164
147
 
148
+ def rails2?
149
+ defined?(Rails::Generator::Base) # In Rails3 it's Rails::Generators::Base (plural s)
150
+ end
151
+
165
152
  def embed_file(source, indent='')
166
153
  IO.read(File.join(self.class.source_root, source)).gsub(/^/, indent)
167
154
  end