How to initialize a custom matcher in rspec 3

40 views
Skip to first unread message

Kris Leech

unread,
Jul 11, 2014, 7:13:11 PM7/11/14
to rs...@googlegroups.com
I'm writing a custom matcher to allow testing of the exit status of code.

I've written the matcher as an object using the bits of information I could find.

I'm using `config.include(Rspec::ExitMatchers)` to include a module which has one method which creates an instance of my matcher, however this method receives the expected value, not the block passed to `expect`, so how do I create an instance of my matcher since the initializer needs the block (actual), not the expected value which should be passed to `matches?`...



Any helps/pointers would be great. Thanks, Kris.


Myron Marston

unread,
Jul 14, 2014, 4:00:16 PM7/14/14
to rs...@googlegroups.com
I've put a gist together showing you how to do this:


The key is that your `exit_with_status` method receives a `status` argument, not a block, and forwards that on to your class's `initialize`.  `matches?` is then passed the `expect` block.

HTH,
Myron 

Kris Leech

unread,
Aug 12, 2014, 5:48:31 PM8/12/14
to rs...@googlegroups.com
Myron - thanks very much. I didn't think my post actually posted, hence my delay.
Reply all
Reply to author
Forward
0 new messages