这是我的设置:
airbrake.rb
require 'airbrake'
Airbrake.configure do |c|
c.ignore_environments = [:test, :development]
c.project_id = ENV['PROJECT_ID']
c.project_key = ENV['PROJECT_KEY']
end
use Airbrake::Rack::Middlewarespec_helper.rb
RSpec.configure do |config|
config.before(:suite) do
FactoryGirl.reload
FactoryGirl.define do
to_create { |instance| instance.save }
end
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
Airbrake.configure(:test) do |c|
c.project_id = ENV['PROJECT_ID']
c.project_key = ENV['PROJECT_KEY']
end
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
config.include FactoryGirl::Syntax::Methods
endworker_test_spec.rb
require 'spec_helper'
RSpec.describe NotificationWorker do
it "perform should call Airbrake#notify" do
anotification_worker = LNotificationWorker.new
airbrake_notification_worker.perform("some error message"))
expect(Airbrake).to receive(:notify).with("some error message")
end
end我在其他(非Sidekiq)测试中调用Airbrake#notify,它们可以找到合适的ENV变量。
但是,如果使用上述设置运行上述Sidekiq测试,则会得到以下错误:
Airbrake::Error:
the 'default' notifier isn't configured但是,如果我将spec_helper.rb中的Airbrake配置更改为:
Airbrake.configure do |c|
c.project_id = ENV['PROJECT_ID']
c.project_key = ENV['PROJECT_KEY']
endENV键可以在测试中找到。为什么会这样呢?
发布于 2016-02-22 16:24:51
当你说Airbrake.configure(:test)时,这并不意味着“为test RAILS_ENV配置空气制动器”。相反,:test创建了一个非默认的命名通知器。然后,您可以通过声明Airbrake.notify("oops", {time: Time.now}, :test)向该通知程序发送特定通知。但这不是关于开发/测试/生产,而是对通知进行分类。
所以问题是,您已经配置了一个名为test的通知程序,但是您还没有配置一个名为default的通知器,而当您不告诉它时,default是它想要使用的。这就是为什么当您简单地说是Airbrake.configure { ... }时,您的规范就通过了。
https://stackoverflow.com/questions/34623599
复制相似问题