Browse files

refactor matchers to conform to internal changes in rspec-expectations

  • Loading branch information...
1 parent 0677052 commit 1cd9a3c927934bcf7637ba7f4877484c84174598 @dchelimsky dchelimsky committed May 21, 2012
View
6 lib/rspec/rails/matchers/be_a_new.rb
@@ -2,9 +2,13 @@ module RSpec::Rails::Matchers
class BeANew
include RSpec::Matchers::BuiltIn::BaseMatcher
+ def initialize(expected)
+ @expected = expected
+ end
+
# @api private
def matches?(actual)
- super
+ @actual = actual
actual.is_a?(expected) && actual.new_record? && attributes_match?(actual)
end
View
8 lib/rspec/rails/matchers/redirect_to.rb
@@ -4,14 +4,14 @@ class RedirectTo
include RSpec::Matchers::BuiltIn::BaseMatcher
def initialize(scope, expected)
- super(expected)
+ @expected = expected
@scope = scope
end
# @api private
- def matches?(actual)
+ def matches?(_)
match_unless_raises ActiveSupport::TestCase::Assertion do
- @scope.assert_redirected_to(expected)
+ @scope.assert_redirected_to(@expected)
end
end
@@ -22,7 +22,7 @@ def failure_message_for_should
# @api private
def failure_message_for_should_not
- "expected not to redirect to #{expected.inspect}, but did"
+ "expected not to redirect to #{@expected.inspect}, but did"
end
end
View
2 lib/rspec/rails/matchers/render_template.rb
@@ -4,7 +4,7 @@ class RenderTemplateMatcher
include RSpec::Matchers::BuiltIn::BaseMatcher
def initialize(scope, expected, message=nil)
- super(Symbol === expected ? expected.to_s : expected)
+ @expected = Symbol === expected ? expected.to_s : expected
@message = message
@scope = scope
end
View
27 lib/rspec/rails/matchers/routing_matchers.rb
@@ -7,28 +7,24 @@ class RouteToMatcher
def initialize(scope, *expected)
@scope = scope
- @expected_options = expected[1] || {}
+ @expected = expected[1] || {}
if Hash === expected[0]
- @expected_options.merge!(expected[0])
+ @expected.merge!(expected[0])
else
controller, action = expected[0].split('#')
- @expected_options.merge!(:controller => controller, :action => action)
+ @expected.merge!(:controller => controller, :action => action)
end
end
- def description
- "route #{@verb_to_path_map.inspect} to #{@expected_options.inspect}"
- end
-
# @api private
def matches?(verb_to_path_map)
- @verb_to_path_map = verb_to_path_map
+ @actual = @verb_to_path_map = verb_to_path_map
# assert_recognizes does not consider ActionController::RoutingError an
# assertion failure, so we have to capture that and Assertion here.
match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
path, query = *verb_to_path_map.values.first.split('?')
@scope.assert_recognizes(
- @expected_options,
+ @expected,
{:method => verb_to_path_map.keys.first, :path => path},
Rack::Utils::parse_query(query)
)
@@ -39,6 +35,10 @@ def matches?(verb_to_path_map)
def failure_message_for_should
rescued_exception.message
end
+
+ def description
+ "route #{@actual.inspect} to #{@expected.inspect}"
+ end
end
# Delegates to `assert_recognizes`. Supports short-hand controller/action
@@ -67,17 +67,20 @@ def initialize(scope)
# @api private
def matches?(path)
- super(path)
+ @actual = path
match_unless_raises ActionController::RoutingError do
@routing_options = @scope.routes.recognize_path(
path.values.first, :method => path.keys.first
)
end
end
- # @api private
+ def failure_message_for_should
+ "expected #{@actual.inspect} to be routable"
+ end
+
def failure_message_for_should_not
- "expected #{actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
+ "expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
end
end

0 comments on commit 1cd9a3c

Please sign in to comment.