Skip to content
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

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

@myronmarston myronmarston commented Apr 17, 2014

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

myronmarston commented Apr 17, 2014

/cc @JonRowe @cupakromer

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

@JonRowe JonRowe Apr 18, 2014

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

myronmarston commented Apr 18, 2014

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

@myronmarston
Copy link
Member Author

myronmarston commented Apr 18, 2014

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

cupakromer commented Apr 18, 2014

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

myronmarston commented Apr 18, 2014

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 Apr 20, 2014
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 join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants