Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my RSpec specs running twice?

I have the following RSpec (1.3.0) task defined in my Rakefile:

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
  spec.libs << 'lib' << 'spec'
  spec.spec_files = FileList['spec/**/*_spec.rb']
end

I have the following in spec/spec_helper.rb:

require 'rubygems'
require 'spec'
require 'spec/autorun'
require 'rack/test'
require 'webmock/rspec'

include Rack::Test::Methods
include WebMock

require 'omniauth/core'

I have a single spec declared in spec/foo/foo_spec.rb:

require File.dirname(__FILE__) + '/../spec_helper'

describe Foo do
  describe '#bar' do
    it 'be bar-like' do
      Foo.new.bar.should == 'bar'
    end
  end
end

When I run rake spec, the single example runs twice. I can check it by making the example fail, giving me two red "F"s.

One thing I thought was that adding spec to the SpecTask's libs was causing them to be double-defined, but removing that doesn't seem to have any effect.

like image 386
James A. Rosen Avatar asked Jun 12 '10 22:06

James A. Rosen


People also ask

What is a spec in RSpec?

A controller spec is an RSpec wrapper for a Rails functional test. (ActionController::TestCase::Behavior). It allows you to simulate a single http request in each example, and then. specify expected outcomes such as: rendered templates.

Does RSpec clean database?

I use the database_cleaner gem to scrub my test database before each test runs, ensuring a clean slate and stable baseline every time. By default, RSpec will actually do this for you, running every test with a database transaction and then rolling back that transaction after it finishes.

How do I cancel RSpec?

How to stop running tests on the first failed test (fail fast tests in RSpec)? You may add a parameter to tell RSpec to stop running the test suite after N failed tests, for example: --fail-fast=3 . There is a downside to it.


1 Answers

I had this problem using zeus, and removing require 'rails/autorun' from my spec_helper.rb stopped it for me

like image 196
Yossi Shasho Avatar answered Oct 01 '22 15:10

Yossi Shasho