[rspec-users] Problems with mock assigned to a constant
mailing_lists at railsnewbie.com
Fri Jul 25 00:00:04 EDT 2008
On Jul 24, 2008, at 11:49 PM, Matt Lins wrote:
> Hi all,
> Initially I thought this was a bug in the built-in mocking
> framework(and it still may be), but I better hash it out on the
> mailing list before I file/reopen the ticket:
> I thought my example illustrated my problem, but obviously I was
> passing the wrong arguments to the mock. I revised my example to
> more clearly state my problem:
> This is a snip of a some code from a library I'm writing. When I
> run this spec I get the following:
> # spec migration_spec.rb
> Spec::Mocks::MockExpectationError in 'Migration should find the
> Mock 'MyModel Class' received unexpected message :count with (no args)
> ./migration.rb:14:in `run'
> Finished in 0.009164 seconds
> 2 examples, 1 failure
> I want to mock out MyModel completely because it's an ActiveRecord
> object. As suggested, if I define the MyModel class, this whole
> spec will pass. But, I don't think I should need to do that, should
> I? So it seems to only occur when I assign the mock to a constant.
> So, even though MyModel.count is stubbed in the before block, the
> mock reports an unexpected message. Note however the first example
The first example passes because "should_receive" acts as a stub, too.
The second example fails, because in the second example there is no
stub for the count method. I'd suggest adding this line to
before(:each) (or to the start of each test case):
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users