Open inkstak opened 9 months ago
This is not how you chain matchers. There’s the and/or mechanism built-in http://rspec.info/features/3-12/rspec-expectations/compound-expectations/
Thanks, but I dont want to chain matcher with the same subject.
Matchers chained to have_html_body.to
receive a transformed subject.
~Your example is not indicative of that: you pass @actual
to the other matcher.~ Sorry, my bad, I’ve missed the parse_body part.
I understand what you are trying to work around. This will be solved in this pr https://github.com/rspec/rspec-expectations/pull/1319, but it’s a breaking change, so only in RSpec 4.
Sounds nice but it seems to me that the PR you've linked will only change the output diff on test failures. Am I wrong ? Maybe this is part of larger changes for RSpec 4 ?
In the matcher above, I have no problem to output a good failure message of chained matchers ... except for the description part.
matcher :have_html_body do
chain :to, :other_matcher
chain :not_to, :other_negative_matcher
failure_message do
message = "expected to #{description}"
message += "\n#{other_matcher&.failure_message}" if other_matcher
message += "\n#{other_negative_matcher&.failure_message_when_negated}" if other_negative_matcher
message
end
end
Do you have any issue with printed example descriptions of chained matchers built using the built-in compound mechanism?
Confusingly, chain
is not to chain matchers, but rather to add qualifiers to the same matcher. Think be_within/of. See http://rspec.info/documentation/3.12/rspec-expectations/RSpec/Matchers/DSL/Macros.html#chain-instance_method
i can’t tell if dsl-defined matchers are compoundable by default.
Subject of the issue
I've created a custom matcher which allows to chain other matchers against a computed value :
I can then chain any matchers to match the parsed body :
It works fine, but descriptions are cumbersome :
Expected behavior
It should generate a readable description :
Your environment
config.include_chain_clauses_in_custom_matcher_descriptions
is already set totrue
Investigation
There are 3 methods involved to generate chained description :
RSpec::Matchers::DSL#chained_method_clause_sentences
RSpec::Matchers::EnglishPhrasing#list
RSpec::Support::ObjectFormatter.format
I'm not sure which one is the most relevant to fix the issue but my guess is EnglishPhrasing. Something like :