[rspec-users] Question: Define custom matcher like raise_error, by Matchers.define

白井 薫 pub at kaorukobo.net
Thu Nov 25 00:09:00 EST 2010


I have a question about the custom matcher using Matcher#define.

My intention is given by the following code:

========================================================================
Spec::Matchers.define :be_done do
   match do |block|
     block.call
     true
   end

   failure_message_for_should do
     "be_done failed."
   end
end

describe "The expectation failure in block called from the custom  
matcher" do
   example "should be reported." do
     lambda {
       lambda {
         1.should == 2
       }.should be_done
     }.should_not raise_error(/be_done failed/)   # should 'expected:  
2, got: 1 (using ==)'
   end
end
========================================================================

I want to define the custom matcher that it calls the block given as  
the actual value, like raise_error.
But if the expectation in the given block failed,
it is not reported, but it reports the custom matcher's failure.

Is there some misuse about Matchers.define in my code?

Best Regards.
--
Kaoru Kobo



More information about the rspec-users mailing list