Permalink
Browse files

Update matchers for RSpec 3's matcher protocol

Resolves this deprecation message from RSpec 3:

WebMock::WebMockMatcher implements a legacy RSpec matcher
protocol. For the current protocol you should expose the failure messages
via the `failure_message` and `failure_message_when_negated` methods.
  • Loading branch information...
1 parent 90c3bb2 commit a4eb9762fd7f5890fa2c8fa0fc549a61e508334f @robolson robolson committed Mar 2, 2014
View
@@ -71,7 +71,7 @@ def assert_request_requested(request, options = {})
def assert_request_not_requested(request, options = {})
verifier = WebMock::RequestExecutionVerifier.new(request, options.delete(:times))
- WebMock::AssertionFailure.failure(verifier.negative_failure_message) unless verifier.does_not_match?
+ WebMock::AssertionFailure.failure(verifier.failure_message_when_negated) unless verifier.does_not_match?
end
#this is a based on RSpec::Mocks::ArgumentMatchers#anythingize_lonely_keys
@@ -32,7 +32,7 @@ def failure_message
text
end
- def negative_failure_message
+ def failure_message_when_negated
text = if @expected_times_executed
%Q(The request #{request_pattern.to_s} was not expected to execute #{times(expected_times_executed)} but it executed #{times(times_executed)})
else
@@ -34,9 +34,11 @@ def failure_message
@request_execution_verifier.failure_message
end
-
- def negative_failure_message
- @request_execution_verifier.negative_failure_message
+ def failure_message_when_negated
+ @request_execution_verifier.failure_message_when_negated
end
+
+ # RSpec 2 compatibility:
+ alias_method :negative_failure_message, :failure_message_when_negated
end
end
@@ -38,9 +38,11 @@ def failure_message
@request_execution_verifier.failure_message
end
-
- def negative_failure_message
- @request_execution_verifier.negative_failure_message
+ def failure_message_when_negated
+ @request_execution_verifier.failure_message_when_negated
end
+
+ # RSpec 2 compatibility:
+ alias_method :negative_failure_message, :failure_message_when_negated
end
end
@@ -37,14 +37,14 @@
@verifier.expected_times_executed = 2
expected_text = "The request www.example.com was not expected to execute 2 times but it executed 2 times"
expected_text << @executed_requests_info
- @verifier.negative_failure_message.should == expected_text
+ @verifier.failure_message_when_negated.should == expected_text
end
it "should report failure message when not expected request but it executed" do
@verifier.times_executed = 1
expected_text = "The request www.example.com was expected to execute 0 times but it executed 1 time"
expected_text << @executed_requests_info
- @verifier.negative_failure_message.should == expected_text
+ @verifier.failure_message_when_negated.should == expected_text
end
end

0 comments on commit a4eb976

Please sign in to comment.