some request specs fail when run under Spork and prevent proper output from RSpec #147

Open
kjvarga opened this Issue Oct 7, 2011 · 0 comments

Comments

Projects
None yet
1 participant

kjvarga commented Oct 7, 2011

I couldn't figure out why when running my tests under Spork sometimes I would get no summary output from RSpec.

I would see output like the following:
$ rake spec
............F......$

No summary output at all, and no exceptions in the logs.

I initially thought it was an RSpec issue, but after working through all the possible scenarios, it has been determined to be a Spork issue i.e. it only happens when running RSpec with Spork running.

I isolated the specs that were causing problems out of hundreds of examples and they are all Request specs (in spec/requests/) and I can't see anything wrong with the specs or the code they are testing. What is even more perplexing is that other specs in the same describe block, which are almost identical, work fine. The problem seems to be in the specs which fall through to the app - as opposed to testing redirects in the middleware which return before the Rails app.

I got around the issue by not running those specs when under Spork. Here is some code:

describe Middleware::MaintenanceModeRedirect do
  # Spork bombs on the get call
  unless Spork.using_spork?
    it "should not redirect to maintenance page unless enabled" do
      MaintenanceHelper.expects(:in_maintenance_mode?).returns(false)
      get('/', {})
      response.status.should == 200
    end
  end

  it "should redirect when maintenance mode is enabled" do
    MaintenanceHelper.expects(:in_maintenance_mode?).returns(true)
    get('/', {})
    response.status.should == 302
  end
end

describe Middleware::SetCookieDomain do
  # Spork bombs on the get call
  unless Spork.using_spork?
    describe "when accessing site at example.org" do
      it "should set cookie_domain to .example.org" do
        host! 'example.org'
        get '/'
        Rails.application.config.session_options[:domain].should == '.example.org'
      end
    end

    describe "when accessing site at site.example.org" do
      it "should set cookie_domain to .example.org" do
        host! 'site.example.org'
        get '/'
        Rails.application.config.session_options[:domain].should == '.example.org'
      end
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment