Comments (5)
Hi Alexander,
How are you requiring rspec? It looks to me as if the mocha teardown hook is not being fired. This might be a load order issue or it might be a problem with rspec in Ruby 1.9.2. I don't know much about rspec, but the following code works for me in Ruby 1.9.2 :-
# my_test.rb
require "test/unit"
require "rubygems"
require "mocha"
class MyTest < Test::Unit::TestCase
def test_should_pass
object = mock()
object.expects(:expected_method).at_least_once
object.expected_method
end
def test_should_fail
object = mock()
object.expects(:expected_method).at_least_once
end
end
Here's what happens when I run it as a standalone file :-
$ ruby my_test.rb
Loaded suite my_test
Started
F.
Finished in 0.007384 seconds.
1) Failure:
test_should_fail(MyTest) [my_test.rb:13]:
not all expectations were satisfied
unsatisfied expectations:
- expected at least once, not yet invoked: #<Mock:0x1008434f0>.expected_method(any_parameters)
2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
Test run options: --seed 60283
Regards, James.
from mocha.
Can you give me your equivalent standalone file i.e. including all require
statements so I can see if I can reproduce your problem?
from mocha.
I just run this file from command line.
If I add:
RSpec.configure do |config| config.mock_with :mocha end
it solves. Copied it from a Rails site.
from mocha.
Ok. I still don't see how you are loading rspec itself, but I'm glad you've solved your problem. I'm going to mark this as closed. I hope that's ok.
from mocha.
I type:
# rspec ./at_spec.rb
and it runs. No framework, no includes. Thanks anyway. I agree to close issue.
from mocha.
Related Issues (20)
- Upgraded from 1.0 to 2.0. HOT 7
- Config option for blocking mocks/stubs on specific methods or classes HOT 1
- Mocha is incompatible with minitest v5.19 and later HOT 16
- Replace references to `MiniTest` with `Minitest` and generally tidy this stuff up HOT 1
- Consider adding an option to disable backtrack filtering
- Unstub in the `then` clause
- Stub by id
- Mocha::StateMachine states method stomps on states fixture HOT 8
- Stubs on instances of DelegateClass do not behave as expected HOT 9
- Add docs about issues & workarounds for using Mocha with BasicObject & the various Delegator classes
- YARD docs for Mock#method_missing is broken HOT 1
- Update Ruby Hash syntax in docs
- Drop support for Ruby v2.0
- Drop support for Ruby v2.1
- Document some of the history of Mocha
- Improve failure message
- sometimes method fails to be mocked HOT 8
- Sign releases
- Stubbed methods not cleaned up post spec completion HOT 1
- Consider using GitHub-flavoured markdown notes, warnings, etc in README
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mocha.