我用Rspec包含了一个问题,我不知道为什么,但是如果我在rspec命令中指定了一个测试文件路径,那么它会运行我的所有测试。
rspec spec / path / to / test_spec.rb:28
//它会像忽略我的参数一样运行所有文件
有人可以告诉我我做错了什么吗?感谢。
我的rails_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'shoulda/matchers'
require 'webmock/rspec'
require 'sidekiq/testing'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
config.pattern = "spec/**/*_spec.rb, spec/**/*.feature" unless ENV['UNIT'] == 'true'
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.before(:each) do | example |
stub_request(:post, "https://api.mixpanel.com/track").to_return(:status => 200, :body => "", :headers => {})
@tracker = instance_double(Mixpanel::Tracker)
people = instance_double(Mixpanel::People)
allow(people).to receive(:set)
allow(@tracker).to receive(:track)
allow(@tracker).to receive(:people).and_return(people)
allow_any_instance_of(ApplicationController).to receive(:tracker).and_return(@tracker)
# Clears out the jobs for tests using the fake testing
Sidekiq::Worker.clear_all
if example.metadata[:sidekiq] == :fake
Sidekiq::Testing.fake!
elsif example.metadata[:sidekiq] == :inline
Sidekiq::Testing.inline!
elsif example.metadata[:type] == :feature
Sidekiq::Testing.inline!
else
Sidekiq::Testing.fake!
end
end
end
WebMock.disable_net_connect!(allow_localhost: true)
答案 0 :(得分:0)
所以我删除了config.pattern = "spec/**/*_spec.rb, spec/**/*.feature" unless ENV['UNIT'] == 'true'
,它按预期工作。