问题描述
我在我的 Rakefile
中定义了以下 RSpec (1.3.0) 任务:
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
我在 spec/spec_helper.rb
中有以下内容:
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'
我在 spec/foo/foo_spec.rb
中声明了一个规范:
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
当我运行 rake spec
时,单个示例运行了两次.我可以通过使示例失败来检查它,给我两个红色的F".
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.
我认为的一件事是将 spec
添加到 SpecTask
的 libs
会导致它们被双重定义,但删除它好像没什么效果.
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.
推荐答案
我在使用 zeus 时遇到了这个问题,并从我的 require 'rails/autorun'
>spec_helper.rb 为我停止了
I had this problem using zeus, and removing require 'rails/autorun'
from my spec_helper.rb
stopped it for me
这篇关于为什么我的 RSpec 规格运行两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!