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
Update allow_value matcher document #1381
Update allow_value matcher document #1381
Conversation
Hi, @hanachin, thank you for your contribution. Can you please tell me what motivated you to create this PR? At first I thought that the actual example was incorrect and you're sugestion the correction of it. To be sure about that I created a simple project using both examples. Both pass - but you opened my eyes to a strange behavior when using invalid values. I'll take a look on that later. What I would like to know, please, is whether this PR would be a personal opinion of what the example should be to make its use clearer? Or is there another reason? Thanks! |
I ran the example of document of I tried some patterns. Original example passed, because it's valid value for the # RSpec
RSpec.describe UserProfile, type: :model do
it do
should allow_value('Broncos', 'Titans').
for(:sports_team).
with_message('Must be either a Broncos or Titans fan',
against: :chosen_sports_team
)
end
end I changed the value that pass to the # RSpec
RSpec.describe UserProfile, type: :model do
it do
should allow_value('foo', 'bar').
for(:sports_team).
with_message('Must be either a Broncos or Titans fan',
against: :chosen_sports_team
)
end
end I updated the expected message to actual one, then example failed. # RSpec
RSpec.describe UserProfile, type: :model do
it do
should allow_value('foo', 'bar').
for(:sports_team).
with_message('Must be either a Broncos fan or a Titans fan',
against: :chosen_sports_team
)
end
end In my personal opinion, use
For testing the valid value, I want to specify the it do
should allow_value('foo', 'bar').for(:sports_team).against(:chosen_sports_team)
end Currently I do the following. it do
should allow_value('foo', 'bar').for(:sports_team).with_message(/.*/, against: :chosen_sports_team)
end |
A few thoughts here:
|
Thank you, @hanachin, for all these details. Helps a lot.
For me, this is unexpected behavior. I expected the matcher to fail. If we agree that this behavior is wrong, I am willing to investigate the cause and see if I can find a solution.
I agree. |
I'd say we can close this PR. I tested a couple of scenarios and couldn't reproduce the matcher passing when an expected message with a typo. Feel free to re-open it if you see fit. |
No description provided.