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

Enhance AllowValueMatcher to take multiple arguments #80

Closed
wants to merge 4 commits into from
Closed

Enhance AllowValueMatcher to take multiple arguments #80

wants to merge 4 commits into from

Conversation

sigi
Copy link
Contributor

@sigi sigi commented Mar 19, 2012

With the deprecation of "should_allow_values_for", specifying multiple good (or bad) values has become quite noisy (array literal + iterator or roll-your-own macro).

Since it is completely downward compatible, I've enhanced the matcher with the ability to take multiple value arguments.

With the deprecation of "should_allow_values_for" there is currently no clean
way to specify multiple allowed (or forbidden) values for an attribute in a
single assertion. This can make test cases unnecessarily verbose.

This patch gives AllowValueMatcher the ability to take multiple values. The new
matcher is fully downward compatible (i.e. given a single argument it behaves
identically to the old matcher).

This matcher will stop checking for bad values when the first bad value is
encountered.
…to shoulda-matchers

In this merge, we also adjust the spec to RSpec syntax.

Conflicts:
	spec/shoulda/active_model/allow_value_matcher_spec.rb
@sigi
Copy link
Contributor Author

sigi commented Mar 19, 2012

This was a pull request to the old (now meta-) repository "shoulda". The merge commit contains the adjustments that were necessary (all in the test suite, the patch itself applied cleanly).

@expected_message ? (errors_match_regexp? || errors_match_string?) : (@errors.compact.any?)
if ! @instance.valid?
@errors = errors_for_attribute(@instance, @attribute)
@errors = [@errors] unless @errors.is_a?(Array)
Copy link

Choose a reason for hiding this comment

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

A cleaner way to do this is to do @errors = Array.wrap(@errors).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neat.

@gabebw
Copy link

gabebw commented Mar 23, 2012

Thanks! Merged.

@gabebw gabebw closed this Mar 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants