views:

209

answers:

1

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.

A: 

Don't know if this fixes the problem, but you can use require 'spec_helper' instead of require File.dirname(__FILE__) + '/../spec_helper'

Also, 'spec/autorun' will require 'spec' for you.

The only other thing I can think of is that you have two spec tasks defined in your system. Is this a rails app? If so, make sure you're not duplicating a rake task that already exists in lib/rake/tasks.

HTH, David

David Chelimsky
It's not a Rails app, so that's not the problem. I can only do `require 'spec_helper'` if my `$LOAD_PATH` is already set up, but if I want to run a single spec, `$LOAD_PATH` won't get set until inside `spec_helper.rb`.
James A. Rosen