Git Product home page Git Product logo

Comments (5)

onebree avatar onebree commented on July 28, 2024

Could you link to any/all sources you are referring to?

I am also interested in what others have to say.

from betterspecs.

pedz avatar pedz commented on July 28, 2024

I was surfing for how to remove an expectation from a method, so Google:

rspec how do I remove an expectation

and you will see the list of hits.

One hit is http://stackoverflow.com/questions/25308667/how-to-reset-expectations-on-a-mocked-class-method
The first comment to the question starts the conversation. The answer also implies (to my eyes) that adding expectations in a before hook should not be done.

from betterspecs.

onebree avatar onebree commented on July 28, 2024

IMO, I think before, after, background, etc should be reserved for setting up a scenario. If you are expecting the same thing 10 times, why not make it its own test? You can add a comment where you assume that expectation to be true later one.

Do you have an example from your own work you'd like to share?

from betterspecs.

enricostano avatar enricostano commented on July 28, 2024

before, after, background, etc should be reserved for setting up a scenario

👍

from betterspecs.

pedz avatar pedz commented on July 28, 2024

I'm not sure how much you want to see.

describe "#print" do
  let(:options) { instance_double("Options") } 
  let(:context) { 
    instance_double("Context").tap do |context|
      expect(context).to receive(:done)
      expect(context).to receive(:in_list).and_return(false)
    end
  } 

  context "with no filters" do
    it "should print but produce no output" do
      instance.print(context)
    end
  end
end

The print routine always calls in_list and done in this scenario so I put those expectations inside the let.

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.