<div dir="ltr">Hi all,<br><br>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:<br><br><a href="http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6">http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6</a><br>
<br>I thought my example illustrated my problem, but obviously I was passing the wrong arguments to the mock.&nbsp; I revised my example to more clearly state my problem:<br><br><a href="http://gist.github.com/2372">http://gist.github.com/2372</a><br>
<br>This is a snip of a some code from a library I&#39;m writing.&nbsp; When I run this spec I get the following:<br><br># spec migration_spec.rb <br>.F<br><br>1)<br>Spec::Mocks::MockExpectationError in &#39;Migration should find the records&#39;<br>
Mock &#39;MyModel Class&#39; received unexpected message :count with (no args)<br>./migration.rb:14:in `run&#39;<br>./migration_spec.rb:19:<br><br>Finished in 0.009164 seconds<br><br>2 examples, 1 failure<br><br>------------------------------------------<br>
<br>I want to mock out MyModel completely because it&#39;s an ActiveRecord object.&nbsp; As suggested, if I define the MyModel class, this whole spec will pass.&nbsp; But, I don&#39;t think I should need to do that, should I?&nbsp; So it seems to only occur when I assign the mock to a constant.<br>
<br>So, even though MyModel.count is stubbed in the before block, the mock reports an unexpected message.&nbsp; Note however the first example passes.&nbsp; <br><br>I had difficulty figuring out the cause of this, so I just gave FlexMock a shot (since it&#39;s so easy to swap out).&nbsp; FlexMock passed both examples(not that, that alone signifies a bug in rSpec).<br>
<br>So, my question: Is this a bug in the built in mocking framework, or am I doing it wrong? :)<br><br>-Matt<br><br><br></div>