Giter VIP home page Giter VIP logo

Comments (2)

zenspider avatar zenspider commented on May 27, 2024

Minitest has never had a plural stubs method. Nor has it ever had a returns method. So upgrading must have gotten rid of some dependency you were using.

Minitest documentation is here: https://docs.seattlerb.org/minitest/README_rdoc.html#label-Stubs which says:

Minitest’s stub method overrides a single method for the duration of the block.

and is kinda the whole point. If you need to stub that much out of the gate to test something, that should be considered a smell. You're probably testing at the wrong level or your code isn't designed to be easily testable.

from minitest.

abatko avatar abatko commented on May 27, 2024

As this is an integration test, I am not convinced that it's a code smell, since there are a bunch of external services that need to be stubbed.

As for the Minitest docs, I'm not sure if there's more to the docs regarding stubs - the only thing I see is a single statement and example, which suggests that the only way to stub is indeed with a block.

  # Minitest’s stub method overrides a single method for the duration of the block

  Time.stub :now, Time.at(0) do   # stub goes away once the block is done
    assert obj_under_test.stale?
  end

I appreciate your response nonetheless, as you saying "upgrading must have gotten rid of some dependency you were using" got me thinking, and I realized that no, upgrading did not do that. I looked harder, and ended up figuring out what the plural stubs is - it's Mocha's stubs. I realize that I misled you by saying that "I upgraded and now there's an error" - and I am sorry for that (in retrospect, I didn't realize exactly what was happening).

The problem was that when I was running this single test on its own, it was failing with undefined method 'stubs' because there was no require 'mocha/minitest' in that file (I guess the test wasn't failing when the entire test suite was run because mocha/minitest was require'd elsewhere in the test suite). Anyway, I added require 'mocha/minitest' and now the test is passing when run on its own, and it looks much nicer than the nested way:

Users::ContactBuilderJob.stubs(:call).returns(true)
AnotherModel::JobOne.stubs(:call).returns(true)
AnotherModel::JobTwo.stubs(:call).returns(true)
AnotherModel::JobThree.stubs(:call).returns(true)
# assertions

Note that until I figured this out I had temporarily used the nested stubbing way of native Minitest, and indeed it worked just the same. The only difference is aesthetic.

I appreciate that stub goes away once the block is done. This is a noteworthy feature.

from minitest.

Related Issues (20)

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.