Comments (5)
@floehopper Yeah, I meant to mock Foo#bar
there. Thanks for catching that.
Your example does demonstrate the issue I ran into though, so I think you've got it spot on in the replication.
from mocha.
Released in v2.3.0.
from mocha.
Thanks for reporting this. It looks as if you've made a mistake in your examples - I imagine you intended to mock & call Foo.bar
from the testx, but instead you are mocking and calling Mock#bar
. Anyway, that doesn't take away from the fact that there seems to be an issue with the nested is_a
parameter matcher - "nested", because I believe the kwargs are treated as a Hash
internally. I've tried to more clearly illustrate the problem below - let me know if I've missed the mark:
require "bundler/setup"
require "minitest/autorun"
require "mocha/minitest"
require "mocha/mock"
class FooTest < Minitest::Test
def setup
@mock = mock("foo")
end
def test_mocking_positional_args
@mock.expects(:bar).with(1, 2, 3)
@mock.bar(1, 2, 3)
end
def test_mocking_positional_args_with_nested_matcher
@mock.expects(:bar).with(1, 2, is_a(Integer))
@mock.bar(1, 2, 3)
end
def test_mocha_mocking_kw_args
@mock.expects(:bar).with(a: 1, b: 2, c: 3)
@mock.bar(a: 1, b: 2, c: 3)
end
def test_mocha_mocking_kw_args_with_nested_matcher
@mock.expects(:bar).with(a: 1, b: 2, c: is_a(Integer))
@mock.bar(a: 1, b: 2, c: 3)
# unexpected invocation: #<Mock:foo>.bar(:a => 1, :b => 2, :c => 3)
# unsatisfied expectations:
# - expected exactly once, invoked never: #<Mock:foo>.bar(:a => 1, :b => 2, :c => is_a(Integer))
end
end
from mocha.
I think I've worked out what the problem is. I'm in a bit of a rush (on a train!), but I've pushed up a tentative fix in this branch. If you're in a position to try this out, that would be brilliant. I'm in meetings most of today, but I'll try to work up a full fix as soon as I can. Thanks so much for reporting the problem - I'm somewhat surprised nobody has spotted it sooner!
from mocha.
I just opened this PR to fix this: #648
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
- undefined method `sequences' HOT 5
- Better error message if `Mockery.teardown` is called when `Mockery.setup` has not been called successfully
- 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.