test/configuration_test.rb in airbrake-3.1.12 vs test/configuration_test.rb in airbrake-3.1.13

- old
+ new

@@ -159,10 +159,22 @@ should "allow ignored exceptions to be replaced" do assert_replaces(:ignore, :ignore_only=) end + should "allow ignored rake exceptions to be appended" do + config = Airbrake::Configuration.new + original_filters = config.ignore_rake.dup + new_filter = 'hello' + config.ignore_rake << new_filter + assert_same_elements original_filters + [new_filter], config.ignore_rake + end + + should "allow ignored rake exceptions to be replaced" do + assert_replaces(:ignore_rake, :ignore_rake_only=) + end + should "allow ignored user agents to be replaced" do assert_replaces(:ignore_user_agent, :ignore_user_agent_only=) end should "use development and test as development environments by default" do @@ -198,10 +210,26 @@ should 'give a new instance if non defined' do Airbrake.configuration = nil assert_kind_of Airbrake::Configuration, Airbrake.configuration end + should 'reject invalid user attributes' do + silence_warnings + config = Airbrake::Configuration.new + config.user_attributes = %w(id foo) + assert_equal %w(id), config.user_attributes + end + + should "warn about invalid attributes" do + stub_warnings + config = Airbrake::Configuration.new + config.user_attributes = %w(id foo bar baz) + %w(foo bar baz).each do |attr| + assert_match(/Unsupported user attribute: '#{attr}'/, Kernel.warnings) + end + end + def assert_config_default(option, default_value, config = nil) config ||= Airbrake::Configuration.new assert_equal default_value, config.send(option) end @@ -212,13 +240,13 @@ end def assert_appends_value(option, &block) config = Airbrake::Configuration.new original_values = config.send(option).dup - block ||= lambda do |config| + block ||= lambda do |conf| new_value = 'hello' - config.send(option) << new_value + conf.send(option) << new_value new_value end new_value = block.call(config) assert_same_elements original_values + [new_value], config.send(option) end @@ -230,6 +258,25 @@ assert_equal [new_value], config.send(option) config.send(setter, new_value) assert_equal [new_value], config.send(option) end + # monkeypatches Kernel.warn so we can read warnings from + # Kernel.warnings + def stub_warnings + Kernel.class_eval do + @@warnings = [] + + def warn(*messages) + @@warnings += messages + end + + def self.warnings + @@warnings.join("\n") + end + end + end + + def silence_warnings + Kernel.class_eval { def warn(*args); end } + end end