Comments (5)
Thanks for reporting this. Just to clarify, is this problem specific to stubbing the #class method on a concrete class? Or just stubbing any method...?
@floehopper Sorry, I should have been clearer. The example reflects my particular use case however, testing further, it seems that stubbing anything will trigger the error e.g. foo_mocks.stubs(:bar)
.
I've updated my example. 🙇
from mocha.
I've just tried reproducing this. I can only reproduce it by incorrectly using the Mocha::Mock#initialize
method like you do in your example code:
require "bundler/setup"
require "minitest/autorun"
require 'mocha/minitest'
require 'mocha/mock'
class Foo; end
class FooTest < Minitest::Test
def test_foo
foo = Mocha::Mock.new(Foo)
foo.stubs(:bar) # => NoMethodError: undefined method `sequences' for Foo:Class
end
end
However, Mocha::Mock#initialize
is not part of the public API, so you shouldn't be using it / relying on its behaviour. Also the first argument to Mocha::Mock#initialize
is an instance of the internal Mocha::Mockery
class and not the class the mock is replacing. Is the code you have posted representative of your actual code?
Changing the test to something more idiomatic works fine (no errors/failures):
def test_foo
foo = mock('Foo')
foo.stubs(:bar)
end
Note that the first argument to Mocha::API#mock
must be a String
or a Symbol
(not a class).
Maybe you want something like Mocha::Mock#responds_like_instance_of
?
I'm not really sure what you're trying to do and/or why it was working before the upgrade!
from mocha.
@tim-wovn Thanks for reporting this. Just to clarify, is this problem specific to stubbing the #class
method on a concrete class? Or just stubbing any method...?
from mocha.
@floehopper Thank you for the investigation. After reading your explanation, I think we can close this issue as "user error". 🙇
For this particular use case, we've defined the mocks in some mock helper classes that are not tests themselves but are later used inside of our tests. Because of that, mock() is not defined, although extending the helper class with extend Mocha::API
seems to do the trick.
(I do get some test failures but the failures seem legitimate--I'm not sure why the tests were passing before! 😨 )
Sorry for taking your time. Thank you again for investigating!
from mocha.
@tim-wovn No worries - thanks for getting back to me!
from mocha.
Related Issues (20)
- 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
- Mocha and Rails 7.0+ and controller tests HOT 3
- Run CI build with `--enable-frozen-string-literal` Ruby command line option HOT 1
- Fix Circle CI builds for Ruby v2.0 or discontinue support
- Better error message if `Mockery.teardown` is called when `Mockery.setup` has not been called successfully
- Parameter matching fails on keyword arguments HOT 5
- Consider using Ruby v1.9 hash syntax in `Hash#mocha_inspect`
- A "targeted" version of #any_instance HOT 5
- Since #648 `has_entry` no longer matches by exact value HOT 3
- Error on `expects.with` with empty hash argument HOT 10
- Rename variables & parameters in matchers to use `actual`& `expected`
- Regression after upgrading to `2.4.3` HOT 14
- Expectations with extra arguments are now "unexpected invocations" HOT 6
- Optional hash parameters are now required in `.expects.with` HOT 1
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.