--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: simple_matcher makes it easy for you to create your own custom matchers in just a few lines of code when you don't need all the power of a completely custom matcher object.
- !ruby/struct:SM::Flow::P 
  body: The <tt>description</tt> argument will appear as part of any failure message, and is also the source for auto-generated descriptions.
- !ruby/struct:SM::Flow::P 
  body: The <tt>match_block</tt> can have an arity of 1 or 2. The first block argument will be the given value. The second, if the block accepts it will be the matcher itself, giving you access to set custom failure messages in favor of the defaults.
- !ruby/struct:SM::Flow::P 
  body: "The <tt>match_block</tt> should return a boolean: <tt>true</tt> indicates a match, which will pass if you use <tt>should</tt> and fail if you use <tt>should_not</tt>. false (or nil) indicates no match, which will do the reverse: fail if you use <tt>should</tt> and pass if you use <tt>should_not</tt>."
- !ruby/struct:SM::Flow::P 
  body: An error in the <tt>match_block</tt> will bubble up, resulting in a failure.
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Example with default messages
- !ruby/struct:SM::Flow::VERB 
  body: "  def be_even\n    simple_matcher(&quot;an even number&quot;) { |given| given % 2 == 0 }\n  end\n\n  describe 2 do\n    it &quot;should be even&quot; do\n      2.should be_even\n    end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: "Given an odd number, this example would produce an error message stating: expected &quot;an even number&quot;, got 3."
- !ruby/struct:SM::Flow::P 
  body: "Unfortunately, if you're a fan of auto-generated descriptions, this will produce &quot;should an even number.&quot; Not the most desirable result. You can control that using custom messages:"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Example with custom messages
- !ruby/struct:SM::Flow::VERB 
  body: "  def rhyme_with(expected)\n    simple_matcher(&quot;rhyme with #{expected.inspect}&quot;) do |given, matcher|\n      matcher.failure_message = &quot;expected #{given.inspect} to rhyme with #{expected.inspect}&quot;\n      matcher.negative_failure_message = &quot;expected #{given.inspect} not to rhyme with #{expected.inspect}&quot;\n      given.rhymes_with? expected\n    end\n  end\n\n  # OR\n\n  def rhyme_with(expected)\n    simple_matcher do |given, matcher|\n      matcher.description = &quot;rhyme with #{expected.inspect}&quot;\n      matcher.failure_message = &quot;expected #{given.inspect} to rhyme with #{expected.inspect}&quot;\n      matcher.negative_failure_message = &quot;expected #{given.inspect} not to rhyme with #{expected.inspect}&quot;\n      given.rhymes_with? expected\n    end\n  end\n\n  describe &quot;pecan&quot; do\n    it &quot;should rhyme with 'be gone'&quot; do\n      nut = &quot;pecan&quot;\n      nut.extend Rhymer\n      nut.should rhyme_with(&quot;be gone&quot;)\n    end\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: "The resulting messages would be:"
- !ruby/struct:SM::Flow::VERB 
  body: "  description:              rhyme with &quot;be gone&quot;\n  failure_message:          expected &quot;pecan&quot; to rhyme with &quot;be gone&quot;\n  negative failure_message: expected &quot;pecan&quot; not to rhyme with &quot;be gone&quot;\n"
- !ruby/struct:SM::Flow::H 
  level: 2
  text: Wrapped Expectations
- !ruby/struct:SM::Flow::P 
  body: Because errors will bubble up, it is possible to wrap other expectations in a SimpleMatcher.
- !ruby/struct:SM::Flow::VERB 
  body: "  def be_even\n    simple_matcher(&quot;an even number&quot;) { |given| (given % 2).should == 0 }\n  end\n"
- !ruby/struct:SM::Flow::P 
  body: BE VERY CAREFUL when you do this. Only use wrapped expectations for matchers that will always be used in only the positive (<tt>should</tt>) or negative (<tt>should_not</tt>), but not both. The reason is that is you wrap a <tt>should</tt> and call the wrapper with <tt>should_not</tt>, the correct result (the <tt>should</tt> failing), will fail when you want it to pass.
full_name: Spec::Matchers#simple_matcher
is_singleton: false
name: simple_matcher
params: (description=nil, &match_block)
visibility: public
