floehopper/mocha — Issue #62: Mocking Random unexpected behaviour
Author: hardipe
Created: 2012-02-02 12:30:48+00:00
State: open

I am using Ruby 1.9.3-p0, Rails 3.2.1, RSpec 2.8.0, Mocha 0.10.3

```ruby
describe 'weird behaviour'
describe 'mocha' do
it 'sets some expectations and satisfies them' do
random_generator = Random.new
random_generator.expects(:rand).with(15..30)
Random.expects(:new).returns(random_generator)
Random.new.rand(15..30)
end
end
describe 'mocha again' do
it 'sets an expectation but an error is never raised if left uninvoked' do
Random.expects(:new)
end
end
end
```

When I run the specs in the listed order they will both pass. When the order is switched, the test in the 'mocha again' block will fail as expected.

This doesn't seem to be the expected behaviour, or am I doing it all wrong?