Permalink
Browse files

monkeypatch the old rails versions in tests

  • Loading branch information...
1 parent c9b9e67 commit 8213553a708c7f8289f4fd52ec5f236f4640daef @shime shime committed May 20, 2012
Showing with 20 additions and 9 deletions.
  1. +1 −1 Rakefile
  2. +5 −4 features/step_definitions/rails_application_steps.rb
  3. +14 −4 features/support/rails.rb
View
@@ -171,7 +171,7 @@ def run_rails_cucumbr_task(version, additional_cucumber_args)
raise "No Rails version specified - make sure ENV['RAILS_VERSION'] is set, e.g. with `rake cucumber:rails:all`"
end
ENV['RAILS_VERSION'] = version
- cmd = "cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/rails.feature features/rails_with_js_notifier.feature"
+ cmd = "cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/rails.feature features/rails_with_js_notifier.feature"
puts "Running command: #{cmd}"
system(cmd)
end
@@ -3,7 +3,6 @@
When /^I generate a new Rails application$/ do
@terminal.cd(TEMP_DIR)
- version_string = ENV['RAILS_VERSION']
rails3 = version_string =~ /^3/
@@ -15,7 +14,7 @@
load_rails = <<-RUBY
gem 'rails', '#{version_string}'; \
- load Gem.bin_path('#{rails_version_at_least("3.2.0") ? "railties" : "rails"}', 'rails', '#{version_string}')
+ load Gem.bin_path('#{version_string >= "3.2.0" ? "railties" : "rails"}', 'rails', '#{version_string}')
RUBY
@terminal.run(%{ruby -rrubygems -rthread -e "#{load_rails.strip!}" #{rails_create_command} rails_root})
@@ -25,8 +24,10 @@
raise "Unable to generate a Rails application:\n#{@terminal.output}"
end
require_thread
- if rails_version_at_least("3.1.0")
+ if version_string >= "3.1.0"
When %{I configure my application to require the "therubyracer" gem with version "0.10.1"}
+ elsif version_string == "2.3.14"
+ monkeypatch_old_version
end
config_gem_dependencies unless rails3
end
@@ -52,7 +53,7 @@
end
When /^I configure my application to require the "capistrano" gem if necessary$/ do
- When %{I configure my application to require the "capistrano" gem} if rails_version_at_least("3.1.0")
+ When %{I configure my application to require the "capistrano" gem} if version_string >= "3.1.0"
end
When /^I configure my application to require the "([^\"]*)" gem(?: with version "(.+)")?$/ do |gem_name, version|
View
@@ -11,10 +11,6 @@ def rails3?
rails_version =~ /^3/
end
- def rails_version_at_least(ver)
- rails_version >= ver
- end
-
def rails_root
LOCAL_RAILS_ROOT
end
@@ -56,6 +52,10 @@ def rails_finds_generators_in_gems?
rails3? || rails_version =~ /^2\./
end
+ def version_string
+ ENV['RAILS_VERSION']
+ end
+
def environment_path
File.join(rails_root, 'config', 'environment.rb')
end
@@ -183,6 +183,16 @@ def initialize(*args)
@terminal.run("ruby -rthread ./script/runner -e #{environment} request.rb")
end
end
+
+ def monkeypatch_old_version
+ monkeypatchin= <<-MONKEYPATCHIN
+
+ MissingSourceFile::REGEXPS << [/^cannot load such file -- (.+)$/i, 1]
+
+ MONKEYPATCHIN
+
+ File.open(File.join(rails_root,"config","initializers", 'monkeypatchin.rb'), 'w') { |file| file.write(monkeypatchin) }
+ end
end
World(RailsHelpers)

0 comments on commit 8213553

Please sign in to comment.