Skip to content
Browse files

Raise error for Rails 3.0

Adds an override of Rails.configuration.application=(*) setter to
raise an error when Rails.configuration.application is set in Rails
3.0. Also moves at_least_rails_3_1? method to the RSpec::Rails module
as a public module method.
  • Loading branch information...
1 parent 1c451f8 commit b694543c858796f1ab2fb2e71288f55f233c946c @danrasband danrasband committed Jun 22, 2012
Showing with 22 additions and 11 deletions.
  1. +4 −0 lib/rspec-rails.rb
  2. +0 −4 lib/rspec/rails.rb
  3. +10 −5 lib/rspec/rails/application.rb
  4. +4 −0 spec/rspec/rails/configuration_spec.rb
  5. +4 −2 spec/spec_helper.rb
View
4 lib/rspec-rails.rb
@@ -1,5 +1,9 @@
module RSpec
module Rails
+ def self.at_least_rails_3_1?
+ Gem::Version.new(::Rails.version) >= Gem::Version.new('3.1.0')
+ end
+
class Railtie < ::Rails::Railtie
# Rails-3.0.1 requires config.app_generators instead of 3.0.0's config.generators
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
View
4 lib/rspec/rails.rb
@@ -5,10 +5,6 @@
c.backtrace_clean_patterns << /lib\/rspec\/rails/
end
-def at_least_rails_3_1?
- Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0')
-end
-
require 'rspec/rails/extensions'
require 'rspec/rails/view_rendering'
require 'rspec/rails/adapters'
View
15 lib/rspec/rails/application.rb
@@ -1,13 +1,18 @@
+require 'rspec-rails'
module RSpec
module Rails
module Application
RSpec.configuration.add_setting :application, :default => ::Rails.application
- # unless at_least_rails_3_1?
- # # def RSpec.configuration.application=(*)
- # # raise "Setting the application is only supported on Rails 3.1 and above."
- # # end
- # end
+ # Raise an error when setting application in Rails < 3.1
+ unless RSpec::Rails.at_least_rails_3_1?
+ class << RSpec.configuration
+ def application=(*)
+ raise "Setting the application is only supported on Rails 3.1 and above."
+ end
+ end
+ end
+
end
end
end
View
4 spec/rspec/rails/configuration_spec.rb
@@ -32,6 +32,10 @@
RSpec.configuration.application.should eq(::Rails.application)
end
+ it "should raise an error for Rails 3.0", :not_at_least_rails_3_1 do
+ expect { RSpec.configuration.application = ::Rails.application }.should raise_error
+ end
+
end
context "custom rack application", :at_least_rails_3_1 do
View
6 spec/spec_helper.rb
@@ -16,7 +16,7 @@ def self.run_all(reporter=nil)
end
end
-if at_least_rails_3_1?
+if RSpec::Rails.at_least_rails_3_1?
RSpec::EngineExample.routes.draw do
root :to => "foo#index"
resources :bars
@@ -26,7 +26,9 @@ def self.run_all(reporter=nil)
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus
- unless at_least_rails_3_1?
+ if RSpec::Rails.at_least_rails_3_1?
+ config.filter_run_excluding :not_at_least_rails_3_1
+ else
config.filter_run_excluding :at_least_rails_3_1
end
config.run_all_when_everything_filtered = true

0 comments on commit b694543

Please sign in to comment.
Something went wrong with that request. Please try again.