Giter Site home page Giter Site logo

minitest-mock_expectations's People

Contributors

bogdanvlviv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

thatguysimon

minitest-mock_expectations's Issues

Asserting call to method with array argument fails

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?

Thanks and minor suggestion

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.