Skip to content

Commit

Permalink
Update matchers for RSpec 3's matcher protocol
Browse files Browse the repository at this point in the history
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
robolson committed Mar 2, 2014
1 parent 90c3bb2 commit a4eb976
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/webmock/api.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/webmock/request_execution_verifier.rb
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/webmock/rspec/matchers/request_pattern_matcher.rb
Expand Up @@ -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
8 changes: 5 additions & 3 deletions lib/webmock/rspec/matchers/webmock_matcher.rb
Expand Up @@ -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
4 changes: 2 additions & 2 deletions spec/unit/request_execution_verifier_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit a4eb976

Please sign in to comment.