Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Give users an error when they use a value matcher in a block expectation expression #530

Merged
merged 5 commits into from
Apr 20, 2014

Conversation

myronmarston
Copy link
Member

Start of fix for #526.

  • Fix the block matchers to give a clear error when given a value rather than a block arg.
  • Add a deprecation warning to 2.99.

@myronmarston
Copy link
Member Author

/cc @JonRowe @cupakromer

class ExpectationTarget
# @private
# Used as a sentinel value to be able to tell when the user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never heard the term "sentinel value" before, I like it.

@myronmarston
Copy link
Member Author

OK, I refactored based on @JonRowe's suggestion. Still have a couple more TODOs (see above).

@myronmarston
Copy link
Member Author

Hmm, I'm actually wondering if supports_block_expectations? is better than block_matcher?. I think in the custom matcher DSL it reads better:

RSpec::Matchers.define :match_a_block do
  match { ... }
  supports_block_expectations
end

Also, block_matcher? makes it sound like a matcher that returns true from that can't also work with values, but @cupakromer had a case where it could support either.

Any preference?

@JonRowe
Copy link
Member

JonRowe commented Apr 18, 2014

I'm ok with supports_block_expectations?

@cupakromer
Copy link
Member

Agree, 👍 for supports_block_expectations

This is used to give users a clear error when they
wrongly use a value matcher against a block, expecting
it to match against the return value of the block:

expect { 3 }.to eq(3)
@myronmarston
Copy link
Member Author

OK, I think this is ready to go (except for the 2.99 deprecation)....care to rereview?

@JonRowe
Copy link
Member

JonRowe commented Apr 20, 2014

LGTM

myronmarston added a commit that referenced this pull request Apr 20, 2014
Give users an error when they use a value matcher in a block expectation expression
@myronmarston myronmarston merged commit 1603a39 into master Apr 20, 2014
@myronmarston myronmarston deleted the block-matcher-clarification branch April 20, 2014 14:27
HoneyryderChuck pushed a commit to HoneyryderChuck/rspec-html-matchers that referenced this pull request May 24, 2014
@myronmarston myronmarston mentioned this pull request Jun 19, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants