-
-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent block-only matchers from being used with value expectation target #1125
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,11 @@ def supports_block_expectations? | |
true | ||
end | ||
|
||
# @private | ||
def supports_value_expectations? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible to tell if a matcher supports block expectations, but it's not possible to detect that it doesn't support value expectations, and will be sending There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems reasonable! |
||
false | ||
end | ||
|
||
private | ||
|
||
def initialize(receiver=nil, message=nil, &block) | ||
|
@@ -107,12 +112,10 @@ def raise_block_syntax_error | |
end | ||
|
||
def positive_failure_reason | ||
return "was not given a block" unless Proc === @event_proc | ||
"is still #{@actual_before_description}" | ||
end | ||
|
||
def negative_failure_reason | ||
return "was not given a block" unless Proc === @event_proc | ||
"did change from #{@actual_before_description} " \ | ||
"to #{description_of change_details.actual_after}" | ||
end | ||
|
@@ -158,10 +161,14 @@ def supports_block_expectations? | |
true | ||
end | ||
|
||
# @private | ||
def supports_value_expectations? | ||
false | ||
end | ||
|
||
private | ||
|
||
def failure_reason | ||
return "was not given a block" unless Proc === @event_proc | ||
"was changed by #{description_of @change_details.actual_delta}" | ||
end | ||
end | ||
|
@@ -190,7 +197,6 @@ def description | |
|
||
# @private | ||
def failure_message | ||
return not_given_a_block_failure unless Proc === @event_proc | ||
return before_value_failure unless @matches_before | ||
return did_not_change_failure unless @change_details.changed? | ||
after_value_failure | ||
|
@@ -201,6 +207,11 @@ def supports_block_expectations? | |
true | ||
end | ||
|
||
# @private | ||
def supports_value_expectations? | ||
false | ||
end | ||
|
||
private | ||
|
||
def perform_change(event_proc) | ||
|
@@ -242,11 +253,6 @@ def did_change_failure | |
"did change from #{@actual_before_description} " \ | ||
"to #{description_of @change_details.actual_after}" | ||
end | ||
|
||
def not_given_a_block_failure | ||
"expected #{@change_details.value_representation} to have changed " \ | ||
"#{change_description}, but was not given a block" | ||
end | ||
end | ||
|
||
# @api private | ||
|
@@ -278,7 +284,6 @@ def does_not_match?(event_proc) | |
|
||
# @private | ||
def failure_message_when_negated | ||
return not_given_a_block_failure unless Proc === @event_proc | ||
return before_value_failure unless @matches_before | ||
did_change_failure | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is due to
have
matcher fromrspec-collection_matchers
that is sensitive to methods called on it, i.e. if we callsupports_value_expectations?
onhave(3).players
, it starts to think that it should matchsupports_value_expectations?
association, notplayers
.The problem is with
supports_value_expectations?
, changingsupports_block_expectations?
for consistency.