[rspec-users] How do I get additional information from the Matcher?

Gary Lin glin at employees.org
Wed May 20 18:32:46 EDT 2009


I am trying to implement my own matcher which use a special algorithm to 
do the semantics diff-ing between two proprietary configuration file.  
When come to the report, I would like my formatter to be able to have 
access to the original configuration file content as well as the 
diff-ing result.  By digging through the code, looks like all formatter 
can get is an ExpectationNotMetError with a string-based message 
embedded inside.  How do I make the matcher pass additional information 
to my formatter?  I see there is a class level variable called 
::Spec::Matchers.last_matcher which allows me to access the last 
matcher.  Is that the right away to implement this?  Or if there is any 
better way for me to add additional information into the 
ExpectationNotMetError exception?



More information about the rspec-users mailing list