Code Monkey home page Code Monkey logo

Comments (6)

dchelimsky avatar dchelimsky commented on June 18, 2024

before(:all) should not work, but before(:each) should.

from rspec-mocks.

thhermansen avatar thhermansen commented on June 18, 2024

Thanks, confirming that before(:each) do work. Have no idea how I managed to being able to make it fail with the code I pasted above. Maybe I didn't manage to save file after changing before(:all) to :each or something stupid. Oh my fault. Thanks again! :-)

from rspec-mocks.

jaredbeck avatar jaredbeck commented on June 18, 2024

If it is possible to support before(:all), I think this issue should be re-opened. If it's just not possible, please add a runtime warning, or add a note to that effect in the docs.

https://www.relishapp.com/rspec/rspec-mocks/v/2-9/docs/method-stubs/stub-on-any-instance-of-a-class

from rspec-mocks.

andrusha avatar andrusha commented on June 18, 2024

👍
I agree, this is very confusing, there should be a warning.

from rspec-mocks.

alindeman avatar alindeman commented on June 18, 2024

Nothing mocking related should be done in a before(:all). These docs cover it: https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/scope

from rspec-mocks.

myronmarston avatar myronmarston commented on June 18, 2024

A random thought I just had: if we can come up with good solutions for both rspec/rspec-core#573 and #153, we can get things to a point where users aren't even allowed to try to setup a mock or stub in before(:all), which would help reduce the confusion here. Consider that if we replace before(:all) with a new construct (e.g. before(:group)) which doesn't share state, it's fairly intuitive that before(:group) blocks aren't eval'd in the same context as examples. Combine that with a new syntax for mocking that doesn't globally add methods to objects that allow them to be mocked or stubbed from anywhere but rather only makes mocking available by wrapping an object with on, allow, expect or something similar...and we can make those methods only available in the example and before(:each) contexts, but not the before(:group) context.

It's something to consider, at least.

from rspec-mocks.

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.