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

David Chelimsky dchelimsky at gmail.com
Sun Nov 28 16:23:12 EST 2010


On Nov 25, 2010, at 7:16 PM, Kaoru Kobo wrote:

> Then I found this page:
> 
> ”Upgrade to 1.3.0 - Matcher DSL"
> Upgrade.rdoc at master from dchelimsky's rspec - GitHub
> http://github.com/dchelimsky/rspec/blob/master/Upgrade.rdoc
> 
> 
> and, I found the tentative solution:
> (Is there the better way?)

Actually, match_unless_raises is probably the best solution for your issue.

> 
> ========================================================================
> Spec::Matchers.define :be_done do
> -  match do |block|
> +  # Do not turn any exceptions to false.
> +  match_unless_raises(Class.new(Exception)) do |block|
>     block.call
>     true
>   end
> ========================================================================
> 
> Best Regards.
> --
> Kaoru Kobo



More information about the rspec-users mailing list