Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Default infer_base_class_for_anonymous_controllers to true #893

Merged
merged 1 commit into from

3 participants

@thomas-holmes

For RSpec 3 this option should now default to true. Updated
the config value setting and the spec_helper generator template
to instead indicate the default value with the line to set it
commented out.

Fixes #869

@thomas-holmes thomas-holmes Default infer_base_class_for_anonymous_controllers to true
For RSpec 3 this option should now default to true. Updated
the config value setting and the spec_helper generator template
to instead indicate the default value with the line to set it
commented out.

Fixes #869
39b1d43
@thomas-holmes

Should I also port this to 2.99?

@JonRowe
Owner

No, 2.99 must behave as 2.14. You would need to port a deprecation warning for when someone uses the old behaviour though.

@JonRowe
Owner

Also was there some background discussion to changing this for 3.0? I'm not familiar enough with this, I leave this to @alindeman to sort out though.

@alindeman alindeman was assigned
@alindeman
Collaborator

The original discussion resides around #421 (comment)

This looks good! Since I think it's pretty much always what folks want (though it was technically a breaking change in 2.x), I am thinking about removing it from the generated spec_helper.rb too. Thoughts?

@alindeman alindeman referenced this pull request from a commit
@alindeman alindeman Changelog for #869, #893 d66d178
@alindeman alindeman merged commit 39b1d43 into rspec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 24, 2013
  1. @thomas-holmes

    Default infer_base_class_for_anonymous_controllers to true

    thomas-holmes authored
    For RSpec 3 this option should now default to true. Updated
    the config value setting and the spec_helper generator template
    to instead indicate the default value with the line to set it
    commented out.
    
    Fixes #869
This page is out of date. Refresh to see the latest.
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 { }
Something went wrong with that request. Please try again.