Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move instance methods from InstanceMethods modules to stop deprecation

warnings from ActiveSupport-3.2
  • Loading branch information...
commit 2085462f864a7dc63b7999722050d07260000cba 1 parent 0e6b185
@dchelimsky dchelimsky authored
View
22 lib/rspec/rails/adapters.rb
@@ -24,11 +24,9 @@ def teardown(*methods)
end
end
- module InstanceMethods
- # @api private
- def method_name
- @example
- end
+ # @api private
+ def method_name
+ @example
end
end
@@ -58,15 +56,13 @@ def #{m}(*args, &block)
end
end
- module InstanceMethods
- class AssertionDelegator
- include Test::Unit::Assertions
- end
+ class AssertionDelegator
+ include Test::Unit::Assertions
+ end
- # @api private
- def assertion_delegator
- @assertion_delegator ||= AssertionDelegator.new
- end
+ # @api private
+ def assertion_delegator
+ @assertion_delegator ||= AssertionDelegator.new
end
included do
View
68 lib/rspec/rails/example/controller_example_group.rb
@@ -74,45 +74,43 @@ def name; "AnonymousController" end
end
end
- module InstanceMethods
- attr_reader :controller, :routes
+ attr_reader :controller, :routes
- module BypassRescue
- def rescue_with_handler(exception)
- raise exception
- end
+ module BypassRescue
+ def rescue_with_handler(exception)
+ raise exception
end
+ end
- # Extends the controller with a module that overrides
- # `rescue_with_handler` to raise the exception passed to it. Use this to
- # specify that an action _should_ raise an exception given appropriate
- # conditions.
- #
- # @example
- #
- # describe ProfilesController do
- # it "raises a 403 when a non-admin user tries to view another user's profile" do
- # profile = create_profile
- # login_as profile.user
- #
- # expect do
- # bypass_rescue
- # get :show, :id => profile.id + 1
- # end.to raise_error(/403 Forbidden/)
- # end
- # end
- def bypass_rescue
- controller.extend(BypassRescue)
- end
+ # Extends the controller with a module that overrides
+ # `rescue_with_handler` to raise the exception passed to it. Use this to
+ # specify that an action _should_ raise an exception given appropriate
+ # conditions.
+ #
+ # @example
+ #
+ # describe ProfilesController do
+ # it "raises a 403 when a non-admin user tries to view another user's profile" do
+ # profile = create_profile
+ # login_as profile.user
+ #
+ # expect do
+ # bypass_rescue
+ # get :show, :id => profile.id + 1
+ # end.to raise_error(/403 Forbidden/)
+ # end
+ # end
+ def bypass_rescue
+ controller.extend(BypassRescue)
+ end
- # If method is a named_route, delegates to the RouteSet associated with
- # this controller.
- def method_missing(method, *args, &block)
- if @orig_routes && @orig_routes.named_routes.helpers.include?(method)
- controller.send(method, *args, &block)
- else
- super
- end
+ # If method is a named_route, delegates to the RouteSet associated with
+ # this controller.
+ def method_missing(method, *args, &block)
+ if @orig_routes && @orig_routes.named_routes.helpers.include?(method)
+ controller.send(method, *args, &block)
+ else
+ super
end
end
View
20 lib/rspec/rails/example/helper_example_group.rb
@@ -14,21 +14,19 @@ def determine_default_helper_class(ignore)
end
end
- module InstanceMethods
- # Returns an instance of ActionView::Base with the helper being specified
- # mixed in, along with any of the built-in rails helpers.
- def helper
- _view.tap do |v|
- v.extend(ApplicationHelper) if defined?(ApplicationHelper)
- v.assign(view_assigns)
- end
+ # Returns an instance of ActionView::Base with the helper being specified
+ # mixed in, along with any of the built-in rails helpers.
+ def helper
+ _view.tap do |v|
+ v.extend(ApplicationHelper) if defined?(ApplicationHelper)
+ v.assign(view_assigns)
end
+ end
private
- def _controller_path
- example.example_group.described_class.to_s.sub(/Helper/,'').underscore
- end
+ def _controller_path
+ example.example_group.described_class.to_s.sub(/Helper/,'').underscore
end
included do
View
11 lib/rspec/rails/example/request_example_group.rb
@@ -4,17 +4,14 @@ module RequestExampleGroup
include RSpec::Rails::RailsExampleGroup
include ActionDispatch::Integration::Runner
include ActionDispatch::Assertions
-
- module InstanceMethods
- def app
- ::Rails.application
- end
- end
-
include RSpec::Rails::Matchers::RedirectTo
include RSpec::Rails::Matchers::RenderTemplate
include ActionController::TemplateAssertions
+ def app
+ ::Rails.application
+ end
+
included do
metadata[:type] = :request
View
18 lib/rspec/rails/example/routing_example_group.rb
@@ -8,16 +8,6 @@ module RoutingExampleGroup
include RSpec::Rails::Matchers::RoutingMatchers
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
- module InstanceMethods
- attr_reader :routes
-
- private
-
- def method_missing(m, *args, &block)
- routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
- end
- end
-
included do
metadata[:type] = :routing
@@ -25,5 +15,13 @@ def method_missing(m, *args, &block)
@routes = ::Rails.application.routes
end
end
+
+ attr_reader :routes
+
+ private
+
+ def method_missing(m, *args, &block)
+ routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
+ end
end
end
View
4 lib/rspec/rails/example/view_example_group.rb
@@ -23,7 +23,7 @@ def _default_helpers
end
end
- module InstanceMethods
+ module ExampleMethods
# @overload render
# @overload render({:partial => path_to_file})
# @overload render({:partial => path_to_file}, {... locals ...})
@@ -119,6 +119,8 @@ def _include_controller_helpers
end
included do
+ include ExampleMethods
+
metadata[:type] = :view
helper *_default_helpers
View
66 lib/rspec/rails/view_assigns.rb
@@ -1,47 +1,43 @@
module RSpec
module Rails
module ViewAssigns
- extend ActiveSupport::Concern
-
- module InstanceMethods
- # Assigns a value to an instance variable in the scope of the
- # view being rendered.
- #
- # @example
- #
- # assign(:widget, stub_model(Widget))
- def assign(key, value)
- _encapsulated_assigns[key] = value
- end
-
- def view_assigns
- begin
- # TODO: _assigns was deprecated in favor of view_assigns after
- # Rails-3.0.0 was released. Since we are not able to predict when
- # the _assigns/view_assigns patch will be released (I thought it
- # would have been in 3.0.1, but 3.0.1 bypassed this change for a
- # security fix), this bit ensures that we do the right thing without
- # knowing anything about the Rails version we are dealing with.
- #
- # Once that change _is_ released, this can be changed to something
- # that checks for the Rails version when the module is being
- # interpreted, as it was before commit dd0095.
- super.merge(_encapsulated_assigns)
- rescue
- _assigns
- end
- end
+ # Assigns a value to an instance variable in the scope of the
+ # view being rendered.
+ #
+ # @example
+ #
+ # assign(:widget, stub_model(Widget))
+ def assign(key, value)
+ _encapsulated_assigns[key] = value
+ end
- # @api private
- def _assigns
+ def view_assigns
+ begin
+ # TODO: _assigns was deprecated in favor of view_assigns after
+ # Rails-3.0.0 was released. Since we are not able to predict when
+ # the _assigns/view_assigns patch will be released (I thought it
+ # would have been in 3.0.1, but 3.0.1 bypassed this change for a
+ # security fix), this bit ensures that we do the right thing without
+ # knowing anything about the Rails version we are dealing with.
+ #
+ # Once that change _is_ released, this can be changed to something
+ # that checks for the Rails version when the module is being
+ # interpreted, as it was before commit dd0095.
super.merge(_encapsulated_assigns)
+ rescue
+ _assigns
end
+ end
+
+ # @api private
+ def _assigns
+ super.merge(_encapsulated_assigns)
+ end
private
- def _encapsulated_assigns
- @_encapsulated_assigns ||= {}
- end
+ def _encapsulated_assigns
+ @_encapsulated_assigns ||= {}
end
end
View
8 lib/rspec/rails/view_rendering.rb
@@ -51,11 +51,9 @@ def render_views?
end
end
- module InstanceMethods
- # @api private
- def render_views?
- self.class.render_views? || !controller.class.respond_to?(:view_paths)
- end
+ # @api private
+ def render_views?
+ self.class.render_views? || !controller.class.respond_to?(:view_paths)
end
# Delegates find_all to the submitted path set and then returns templates
View
6 spec/rspec/rails/example/helper_example_group_spec.rb
@@ -1,7 +1,7 @@
require "spec_helper"
module RSpec::Rails
- describe HelperExampleGroup::InstanceMethods do
+ describe HelperExampleGroup do
module ::FoosHelper; end
subject { HelperExampleGroup }
@@ -9,7 +9,7 @@ module ::FoosHelper; end
it { should be_included_in_files_in('.\\spec\\helpers\\') }
it "provides a controller_path based on the helper module's name" do
- helper_spec = Object.new.extend HelperExampleGroup::InstanceMethods
+ helper_spec = Object.new.extend HelperExampleGroup
helper_spec.stub_chain(:example, :example_group, :described_class).and_return(FoosHelper)
helper_spec.__send__(:_controller_path).should == "foos"
end
@@ -23,7 +23,7 @@ module ::FoosHelper; end
describe "#helper" do
it "returns the instance of AV::Base provided by AV::TC::Behavior" do
- helper_spec = Object.new.extend HelperExampleGroup::InstanceMethods
+ helper_spec = Object.new.extend HelperExampleGroup
helper_spec.should_receive(:view_assigns)
av_tc_b_view = double('_view')
av_tc_b_view.should_receive(:assign)
View
10 spec/rspec/rails/example/view_example_group_spec.rb
@@ -94,7 +94,7 @@ def _assigns
end
end
include Local
- include ViewExampleGroup::InstanceMethods
+ include ViewExampleGroup::ExampleMethods
end.new
end
@@ -124,7 +124,7 @@ def _assigns
describe '#params' do
let(:view_spec) do
Class.new do
- include ViewExampleGroup::InstanceMethods
+ include ViewExampleGroup::ExampleMethods
def controller
@controller ||= Object.new
end
@@ -140,7 +140,7 @@ def controller
describe "#_controller_path" do
let(:view_spec) do
Class.new do
- include ViewExampleGroup::InstanceMethods
+ include ViewExampleGroup::ExampleMethods
end.new
end
context "with a common _default_file_to_render" do
@@ -165,7 +165,7 @@ def controller
describe "#view" do
let(:view_spec) do
Class.new do
- include ViewExampleGroup::InstanceMethods
+ include ViewExampleGroup::ExampleMethods
end.new
end
@@ -179,7 +179,7 @@ def controller
describe "#template" do
let(:view_spec) do
Class.new do
- include ViewExampleGroup::InstanceMethods
+ include ViewExampleGroup::ExampleMethods
def _view; end
end.new
end
Please sign in to comment.
Something went wrong with that request. Please try again.