psyho / bogus

Fake library for Ruby
Other
359 stars 14 forks source link

RSpec expectation compatibility #40

Closed DivineDominion closed 10 years ago

DivineDominion commented 11 years ago

The spy-syntax is:

expect(obj).to have_received.foo(any_args)

RSpec's spies on the other hand work with

expect(obj).to have_received(:foo)

Keeping the latter in place after setting up bogus basically breaks spy-expectations without warning or any helpful message. What I did get was this:

ArgumentError:
       tried to stub foo(bar) with arguments: 

Didn't know what was wrong. So there are two issues, basically:

  1. add RSpec spy compatible expectation syntax,
  2. throw more meaningful messages.

It took some guesswork and granular comparison between examples is the GitHub README and my code to find out the error was on my side in the first place. Relishapp.com examples sport should syntax only.

DivineDominion commented 11 years ago

Cf. #41: I found out the syntax is have_received(:foo, any_args).

Let me rephrase this issue, though: please make this the default or use with(any_args) to clarify the intent. That'll make adapting to bogus easier at least.

psyho commented 10 years ago

The mocking/expectation syntax we use is based on RR, not RSpec.

# bogus / RR syntax
expect(foo).to have_received.bar("hello")

# RSpec
expect(foo).to have_received(:bar).with("hello")

Adding an RSpec-syntax adapter is something we would like to add in the future - there's even some preliminary work done around that already, but at the moment it's a nice-to-have kind of thing. Check out issue #30 for more details.