diff --git a/lib/raven/configuration.rb b/lib/raven/configuration.rb index fa1aaa5d6..ea344090b 100644 --- a/lib/raven/configuration.rb +++ b/lib/raven/configuration.rb @@ -160,11 +160,7 @@ def current_environment=(environment) end def send_in_current_environment? - if environments - environments.include?(current_environment) - else - true - end + !!server && (!environments || environments.include?(current_environment)) end def log_excluded_environment_message diff --git a/lib/raven/event.rb b/lib/raven/event.rb index 464f32464..3cfb0e792 100644 --- a/lib/raven/event.rb +++ b/lib/raven/event.rb @@ -59,11 +59,9 @@ def initialize(options = {}, &block) block.call(self) if block - if @configuration.send_in_current_environment? - if !self[:http] && context.rack_env - self.interface :http do |int| - int.from_rack(context.rack_env) - end + if !self[:http] && context.rack_env + self.interface :http do |int| + int.from_rack(context.rack_env) end end diff --git a/spec/raven/configuration_spec.rb b/spec/raven/configuration_spec.rb index 493d7e0a2..46507b8c1 100644 --- a/spec/raven/configuration_spec.rb +++ b/spec/raven/configuration_spec.rb @@ -55,6 +55,17 @@ end end + context 'being initialized without server configuration' do + before do + subject.environments = %w[ test ] + end + + it 'should not send events' do + expect(subject[:server]).to eq(nil) + expect(subject.send_in_current_environment?).to eq(false) + end + end + context 'being initialized with a server string' do before do subject.server = 'http://12345:67890@sentry.localdomain/sentry/42' @@ -87,11 +98,7 @@ it_should_behave_like 'a complete configuration' end - context 'being initialized in a non-test environment' do - it 'should send events' do - expect(subject.send_in_current_environment?).to eq(true) - end - + context 'configuring for async' do it 'should be configurable to send events async' do subject.async = lambda { |_e| :ok } expect(subject.async.respond_to?(:call)).to eq(true) @@ -104,31 +111,22 @@ expect { subject.async = false }.to_not raise_error expect { subject.async = true }.to raise_error(ArgumentError) end - end - context 'being initialized in a test environment' do + context 'being initialized with a current environment' do before(:each) do subject.current_environment = 'test' - end - - it 'should send events' do - expect(subject.send_in_current_environment?).to eq(true) + subject.server = 'http://sentry.localdomain/sentry' end it 'should send events if test is whitelisted' do subject.environments = %w[ test ] expect(subject.send_in_current_environment?).to eq(true) end - end - context 'being initialized in a development environment' do - before(:each) do - subject.current_environment = 'development' - end - - it 'should send events' do - expect(subject.send_in_current_environment?).to eq(true) + it 'should not send events if test is not whitelisted' do + subject.environments = %w[ not_test ] + expect(subject.send_in_current_environment?).to eq(false) end end diff --git a/spec/support/Rakefile b/spec/support/Rakefile index 811742eae..17d336c0e 100644 --- a/spec/support/Rakefile +++ b/spec/support/Rakefile @@ -2,6 +2,10 @@ require 'rake' require 'rubygems' require 'raven' +Raven.configure do |config| + config.dsn = 'http://12345:67890@sentry.localdomain/sentry/42' +end + task :raise_exception do 1 / 0 -end \ No newline at end of file +end