Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'infer-anonymous-controller-base-class-by-default' of ht…

…tps://github.com/thomas-holmes/rspec-rails into thomas-holmes-infer-anonymous-controller-base-class-by-default
  • Loading branch information...
commit 7b2d363ccfcc9a9b22878e405c3c77281d070eba 2 parents 2fb9dcf + 39b1d43
@alindeman alindeman authored
View
22 features/controller_specs/anonymous_controller.feature
@@ -1,23 +1,23 @@
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 disable base type inference:
- 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`
+ # ^^ creates an anonymous subclass of `ApplicationController`
Scenario: specify error handling in ApplicationController
Given a file named "spec/controllers/application_controller_spec.rb" with:
@@ -97,10 +97,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
View
7 lib/generators/rspec/install/templates/spec/spec_helper.rb.tt
@@ -35,10 +35,9 @@ 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
+ # If false, the base class of anonymous controllers will not be inferred
+ # automatically.
+ # config.infer_base_class_for_anonymous_controllers = true
# 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
View
2  lib/rspec/rails/example/controller_example_group.rb
@@ -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
View
4 spec/rspec/rails/example/controller_example_group_spec.rb
@@ -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 { }
Please sign in to comment.
Something went wrong with that request. Please try again.