ruby - Why can't RSpec find the Airbrake env keys in a test involving Sidekiq when I specify environment? -


here setup:

airbrake.rb

require 'airbrake'  airbrake.configure |c|   c.ignore_environments = [:test, :development]   c.project_id = env['project_id']   c.project_key = env['project_key'] end  use airbrake::rack::middleware 

spec_helper.rb

rspec.configure |config|   config.before(:suite)     factorygirl.reload     factorygirl.define       to_create { |instance| instance.save }     end     databasecleaner.strategy = :transaction     databasecleaner.clean_with(:truncation)     airbrake.configure(:test) |c|       c.project_id = env['project_id']       c.project_key = env['project_key']     end   end    config.around(:each) |example|     databasecleaner.cleaning       example.run     end   end    config.include factorygirl::syntax::methods end 

worker_test_spec.rb

require 'spec_helper'  rspec.describe notificationworker   "perform should call airbrake#notify"     anotification_worker = lnotificationworker.new     airbrake_notification_worker.perform("some error message"))     expect(airbrake).to receive(:notify).with("some error message")   end end 

i call airbrake#notify in other (non-sidekiq) tests, , find appropriate env variables fine.

yet if run above sidekiq test above setup, following error:

airbrake::error:        'default' notifier isn't configured 

but if change airbrake config in spec_helper.rb to:

airbrake.configure |c|   c.project_id = env['project_id']   c.project_key = env['project_key'] end 

the env keys able found in tests. why this?

when airbrake.configure(:test), not mean "configure airbrake test rails_env". rather :test creates non-default named notifier. can send specific notifications notifier saying airbrake.notify("oops", {time: time.now}, :test). not development/test/production, categorizing notifications.

so problem have configured notifier named test, have not yet configured 1 named default, , default airbrake wants use when don't tell otherwise. that's why spec passes when airbrake.configure { ... }.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -