Coder Social home page Coder Social logo

Unstubbing about mocha HOT 7 CLOSED

freerange avatar freerange commented on May 21, 2024
Unstubbing

from mocha.

Comments (7)

floehopper avatar floehopper commented on May 21, 2024

I think I've only ever had one other request for this feature and even that was a long time ago. I just had a quick look at the code and unfortunately it's not as easy to add as I'd like, but I might have go at refactoring the code to make it easier. I'd be interested to know why you need to do it...? Thanks, James.

from mocha.

mattkanwisher avatar mattkanwisher commented on May 21, 2024

We have a set of rspec tests an one of them stubs methods on Time, to test out how pages look on different days. Then some other test comes along an uses Time to parse a date and the parsing is always wrong.

from mocha.

floehopper avatar floehopper commented on May 21, 2024

Methods should be un-stubbed automatically at the end of a test, so you shouldn't need to manually un-stub. It sounds like there might be a problem with the integration between Mocha and Rspec. Would you be able to put together a simplified test which exhibits the problem?

from mocha.

pathsny avatar pathsny commented on May 21, 2024

I have to unstub occassionally in my codebase for a couple of fairly complicated tests
This is the implementation I use
def unstub(object, method)
Mocha::Mockery.instance.stubba.stubba_methods.delete_if do |meth|
meth.stubbee == object && meth.method == method.to_s && true.tap { meth.unstub }
end
end

when unstubbing an "any_instance" stub, I pass in the class

from mocha.

floehopper avatar floehopper commented on May 21, 2024

I've just added an unstub method. It would be great if you could try it out and let me know what you think. Please close this issue if you're happy. Thanks, James.

from mocha.

floehopper avatar floehopper commented on May 21, 2024

I've just release a new version of Mocha including this change. I'm marking this issue as closed.

from mocha.

pathsny avatar pathsny commented on May 21, 2024

oh sorry I didnt see this. Let me try it out :)

from mocha.

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.