On Friday, August 15, 2014 9:49:47 AM UTC-7, Kris Leech wrote:
>
> Is it possible to chain two matchers and not have to yield the block given
> to expect twice?
>
> The problem is yielding the block twice changes the test.
>
> class FirstMatcher
> def matches?(block)
> @result = record_something do
> block.call # block called for first time
> end
> return true
> end
>
> def supports_block_expectations?
> true
> end
>
> def second_matcher?
> SecondMatcher.new
> end
> end
>
> class SecondMatcher
> def matches?(block)
> @result = record_something do
> block.call # block called for second time, can I get the original
> @result somehow?
> end
> return true
> end
>
> def supports_block_expectations?
> true
> end
> end
>
>
> # usage
>
> expect { something }.to first_matcher.second_matcher
>
> Many thanks, Kris.
>
In RSpec 3.0, there's not. In 3.1, there will be:
https://github.com/rspec/rspec-expectations/pull/567
Use the `and` chaining:
expect { }.to first_matcher.and second_matcher
...and it should just work.
Myron
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/fe5d7193-ce3a-4b85-8a3c-099a25c9ffbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.