Permalink
Browse files

Merge branch 'thomas-holmes-infer-anonymous-controller-base-class-by-…

…default'
  • Loading branch information...
2 parents 2fb9dcf + 66c1f78 commit 3300d78ddd8343efacb496655d3fb01634773672 @alindeman alindeman committed Dec 27, 2013
@@ -1,23 +1,27 @@
Feature: anonymous controller
- Use the `controller` method to define an anonymous controller derived from
- `ApplicationController`. This is useful for specifying behavior like global
- error handling.
+ Use the `controller` method to define an anonymous controller
+ that will inherit from the described class. This is useful for
+ specifying behavior like global error handling.
- To specify a different base class, you can pass the class explicitly to the
- controller method:
+ To specify a different base class you can pass the class explicitly
+ to the controller method:
controller(BaseController)
- You can also configure RSpec to use the described class:
+ You can also disable base type inference, in which case anonymous
+ controllers will inherit from `ApplicationController` instead of
+ the described class by default:
- RSpec.configure do |c|
- c.infer_base_class_for_anonymous_controllers = true
+ Rspec.configure do |c|
+ c.infer_base_class_for_anonymous_controllers = false
end
describe BaseController do
controller { ... }
- # ^^ creates an anonymous subclass of `BaseController`
+ # ^^ would normally create an anonymous subclass of `BaseController`,
+ # but since `infer_base_class_for_anonymous_controllers` is disabled,
+ # it creates a subclass of `ApplicationController` instead
Scenario: specify error handling in ApplicationController
Given a file named "spec/controllers/application_controller_spec.rb" with:
@@ -97,10 +101,6 @@ Feature: anonymous controller
"""ruby
require "spec_helper"
- RSpec.configure do |c|
- c.infer_base_class_for_anonymous_controllers = true
- end
-
class ApplicationController < ActionController::Base; end
class ApplicationControllerSubclass < ApplicationController; end
@@ -35,11 +35,6 @@ RSpec.configure do |config|
# instead of true.
config.use_transactional_fixtures = true
- # If true, the base class of anonymous controllers will be inferred
- # automatically. This will be the default behavior in future versions of
- # rspec-rails.
- config.infer_base_class_for_anonymous_controllers = false
-
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
@@ -1,5 +1,5 @@
RSpec.configure do |config|
- config.add_setting :infer_base_class_for_anonymous_controllers, :default => false
+ config.add_setting :infer_base_class_for_anonymous_controllers, :default => true
end
module RSpec::Rails
@@ -80,6 +80,10 @@ module RSpec::Rails
allow(group).to receive(:controller_class).and_return(Class.new)
end
+ it "defaults to inferring anonymous controller class" do
+ expect(RSpec.configuration.infer_base_class_for_anonymous_controllers).to be_truthy
+ end
+
it "infers the anonymous controller class when infer_base_class_for_anonymous_controllers is true" do
allow(RSpec.configuration).to receive(:infer_base_class_for_anonymous_controllers?).and_return(true)
group.controller { }

0 comments on commit 3300d78

Please sign in to comment.