bogdanvlviv / minitest-mock_expectations Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hi, great job on this gem!
I found a pretty serious bug though :(
If you try to assert a call to a method that takes an array as its argument:
assert_called_with(Tempfile, :new, [['hello', '.jpg']]) do
file = Tempfile.new(['hello', '.jpg'])
end
Running the above code will result in:
ArgumentError: mocked method :call expects 2 arguments, got 1
from .../ruby-2.6.3/gems/minitest-5.14.0/lib/minitest/mock.rb:150:in `method_missing'
This happens due to a collision with the feature of being able to pass an array of different sets of arguments that the method can be called with.
I suggest changing the interface of the multiple arguments feature to the following (which will also allow providing a different return value for each set of arguments):
expectations = [
{
expected_args: ["Thanks for sharing this."],
return_value: mocked_comment_1
},
{
expected_args: ["Thanks!"],
return_value: mocked_comment_2
}
]
assert_called_with(@post, :add_comment, expectations: expectations) do
@post.add_comment("Thanks for sharing this.")
@post.add_comment("Thanks!")
end
Shall I open a PR for this?
The initial idea of this looks like:
expectations = [
{
expected_args: ["Thanks for sharing this."],
return_value: mocked_comment_1
},
{
expected_args: ["Thanks!"],
return_value: mocked_comment_2
}
]
assert_called_with(@post, :add_comment, expectations: expectations) do
@post.add_comment("Thanks for sharing this.")
@post.add_comment("Thanks!")
end
Hey, this is a great life saving gem. It brings the nice RSpec expectations easily and intuitively into my Rails projects, so thanks for that.
One thing I noticed - it is hard to find this gem. Searching "minitest mock expectations" does not show this repo anywhere in the first pages, and I don't remember even how I did find it - perhaps changing the README H1 to "Minitest Mock Expectations" will help Google?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.