[rspec-devel] confusion with rspec mocks
David Chelimsky
dchelimsky at gmail.com
Wed Aug 15 16:41:36 EDT 2007
On 8/15/07, Dan North <dan at tastapod.com> wrote:
> Hi folks.
>
> I'm nearly there with the initial cut of Spec::Story. I have one example
> failing with an odd error from the rspec mock framework.
>
> I moved #with from MessageExpectation into BaseExpectation so I could
> stub!(:something).with(args).
That was a deliberate design choice - I don't believe stubs should
care about args - if you care about args, then you want should_receive
(because it's an expectation).
> I have:
>
>
> story_runner.stub!(:add_listener).with(an_instance_of(Reporter::PlainTextReporter))
> ...
>
> story_runner.should_receive(:add_listener).with(an_instance_of(Documenter::PlainTextDocumenter))
>
> The example fails with:
>
> Mock 'scenario runner' expected :add_listener with (no args) but
> received it with (#<Spec::Story::Reporter::PlainTextReporter:0xb777a83c
> @pending=[], @succeeded=0, @failed=[], @out=#<IO:0xb77823c0>>)
> ./spec/spec/story/runner_spec.rb:61:
>
> If I change the stub!(...) to should_receive(...) it fails with:
>
> Mock 'story runner' expected :add_listener with (no args) once, but
> received it 0 times
> ./spec/spec/story/runner_spec.rb:57:
>
> In both cases it seems the args checking is being lost somewhere.
I can't explain this off-hand, but if you move :with back, does it
work w/ should_receive?
>
> Can anyone shed any light?
>
> Thanks,
> Dan
>
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>
More information about the rspec-devel
mailing list