Skip to content

before hooks and its(:method) { should == 'foo' } #593

Closed
ahawkins opened this Issue Mar 29, 2012 · 4 comments

4 participants

@ahawkins

I have a spec like this:

describe "Parsing the results" do
    before(:each) do
      stub_request(:get, "#{config.url}?#{request}").
        to_return(:body => load_fixture(:usps_success_response))
    end

    subject { Trackerific::USPS.new(package_id).track.events.first }

    its(:time) { should == "May 29 9:55 am" }

    it "should handle the location"

    it "should handle the description"
  end

It requires that webmock sets up the stub for each example. However, the before(:each) block is not being called before the its(:time).

The block is called if I move that example into a it "should handle the time" do format.

This is on 2.9.

@dchelimsky
RSpec member

What's the failure message you get?

@ahawkins

webmock throughs an error that the stub hasn't been setup yet. When subject is called for its, it attempts to make a real http connection which is blocked in my test suite.

You can see my entire test suite here: https://github.com/threadedlabs/trackerific

There are very obvious places where it could use its(:foo), but can't.

@myronmarston
RSpec member

Given the error, it could be a bug in WebMock or simply that the URL you are stubbing in WebMock doesn't match the request being made. Can you try something like this to definitively demonstrate a bug (or not) in rspec?

describe "Parsing the results" do
    order = []
    before(:each) do
      order << :before
      stub_request(:get, "#{config.url}?#{request}").
        to_return(:body => load_fixture(:usps_success_response))
    end

    subject do
      order.should == [:before]
      order << :subject
      Trackerific::USPS.new(package_id).track.events.first
    end

    its(:time) { order.should == [:before, :subject]; should == "May 29 9:55 am" }

    it "should handle the location"

    it "should handle the description"
  end

If you get failures from the order.should == lines then it looks like it is indeed a bug in RSpec.

@ahawkins

@myronmarston ok, I'll give it go a little later.

@justinko justinko closed this May 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.