Git Product home page Git Product logo

Comments (4)

geniou avatar geniou commented on July 28, 2024

I think the second one is correct since you wanted to test, that the method is called so the expect should be in the it block. If this fails the it will fail and all other its can pass.

A even better way could be (in my opinion)

describe '#method1' do
  subject { described_class.new.method1 }
  before {allow(SomeClass).to receive(:method2)}

  it 'calls SomeClass.method2' do
    subject
    expect(SomeClass).to have_received(:method2)
  end
end

The benefit would be, that you can have several its and only the the method call it tested in one case.

from betterspecs.

astyagun avatar astyagun commented on July 28, 2024

Thanks @geniou, we've had an argument about this at work and your solution satisfies both sides :)

from betterspecs.

geniou avatar geniou commented on July 28, 2024

@astyagun your welcome. :)

from betterspecs.

onebree avatar onebree commented on July 28, 2024

@astyagun if your issue has been resolved, please close it. Otherwise, I am leaving it open.

In the future, I plan to have a forum or chat for questions like this, as they can be solved soon. (Like this one was.) When we overhaul the site, issues will be general questions on best practice or about the code.... not personal cases of "what's best to do"

from betterspecs.

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.