diff --git a/.rubocop.yml b/.rubocop.yml index cd8329c6e..57b3f2ada 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,27 @@ -inherit_from: .rubocop_todo.yml - AllCops: Exclude: - 'examples/**/*' - 'lib/raven/utils/deep_merge.rb' +Metrics/ClassLength: + Max: 225 + CountComments: false + +Metrics/AbcSize: + Max: 50 + +Metrics/CyclomaticComplexity: + Max: 13 + +Metrics/PerceivedComplexity: + Max: 13 + +Metrics/LineLength: + Max: 155 + +Metrics/MethodLength: + Max: 34 + Style/SignalException: Enabled: false @@ -16,3 +33,39 @@ Style/ClassAndModuleChildren: Style/ParallelAssignment: Enabled: false + +Style/Documentation: + Enabled: false + +Style/RescueModifier: + Enabled: false + +Style/StringLiterals: + Enabled: false + +Style/CaseEquality: + Enabled: false + +Style/DoubleNegation: + Enabled: false + +Style/FileName: + Exclude: + - 'lib/sentry-raven-without-integrations.rb' + - 'lib/sentry-raven.rb' + +Style/NumericLiterals: + Exclude: + - 'spec/raven/processors/sanitizedata_processor_spec.rb' + +Style/HashSyntax: + EnforcedStyle: hash_rockets + +Lint/RescueException: + Exclude: + - 'lib/raven/base.rb' + - 'lib/raven/instance.rb' + - 'lib/raven/integrations/delayed_job.rb' + - 'lib/raven/integrations/rack.rb' + - 'lib/raven/integrations/sidekiq.rb' + - 'spec/raven/event_spec.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index c3be1999f..000000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,416 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2015-12-06 19:42:13 -0500 using RuboCop version 0.35.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - - -# Offense count: 6 -Lint/RescueException: - Exclude: - - 'lib/raven/base.rb' - - 'lib/raven/instance.rb' - - 'lib/raven/integrations/delayed_job.rb' - - 'lib/raven/integrations/rack.rb' - - 'lib/raven/integrations/sidekiq.rb' - - 'spec/raven/event_spec.rb' - -# Offense count: 1 -Lint/ShadowingOuterLocalVariable: - Exclude: - - 'lib/raven/event.rb' - -# Offense count: 1 -Lint/UnreachableCode: - Exclude: - - 'spec/raven/raven_spec.rb' - -# Offense count: 29 -Metrics/AbcSize: - Max: 73 - -# Offense count: 5 -Metrics/BlockNesting: - Max: 6 - -# Offense count: 2 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 250 - -# Offense count: 15 -Metrics/CyclomaticComplexity: - Max: 20 - -# Offense count: 112 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 155 - -# Offense count: 32 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 57 - -# Offense count: 2 -# Configuration parameters: CountComments. -Metrics/ModuleLength: - Max: 413 - -# Offense count: 14 -Metrics/PerceivedComplexity: - Max: 20 - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AccessModifierIndentation: - Enabled: false - -# Offense count: 9 -# Cop supports --auto-correct. -Style/Alias: - Exclude: - - 'lib/raven/base.rb' - - 'lib/raven/event.rb' - - 'lib/raven/integrations/rake.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/AlignArray: - Exclude: - - 'spec/raven/event_spec.rb' - - 'spec/raven/processors/utf8conversion_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AlignParameters: - Exclude: - - 'lib/raven/client.rb' - - 'lib/raven/event.rb' - - 'lib/raven/integrations/delayed_job.rb' - - 'spec/raven/event_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AndOr: - Exclude: - - 'lib/raven/interfaces/http.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. -Style/BlockDelimiters: - Exclude: - - 'spec/raven/cli_spec.rb' - -# Offense count: 27 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BracesAroundHashParameters: - Exclude: - - 'spec/raven/event_spec.rb' - - 'spec/raven/processors/removecirculareferences_spec.rb' - - 'spec/raven/processors/sanitizedata_processor_spec.rb' - -# Offense count: 1 -Style/CaseEquality: - Exclude: - - 'lib/raven/event.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep. -Style/CaseIndentation: - Enabled: false - -# Offense count: 37 -# Configuration parameters: Exclude. -Style/Documentation: - Enabled: false - -# Offense count: 1 -Style/DoubleNegation: - Exclude: - - 'lib/raven/configuration.rb' - -# Offense count: 2 -Style/EachWithObject: - Exclude: - - 'lib/raven/processor/removecircularreferences.rb' - - 'lib/raven/processor/sanitizedata.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/ElseAlignment: - Exclude: - - 'lib/raven/interfaces/stack_trace.rb' - -# Offense count: 33 -# Cop supports --auto-correct. -Style/EmptyLines: - Exclude: - - 'spec/spec_helper.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/EmptyLinesAroundModuleBody: - Exclude: - - 'lib/raven/backtrace.rb' - - 'lib/raven/event.rb' - - 'lib/raven/integrations/delayed_job.rb' - - 'lib/raven/interfaces.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -# Style/ExtraSpacing: -# Exclude: -# - 'lib/raven/event.rb' -# - 'lib/raven/processor/sanitizedata.rb' - -# Offense count: 2 -# Configuration parameters: Exclude. -Style/FileName: - Exclude: - - 'lib/sentry-raven-without-integrations.rb' - - 'lib/sentry-raven.rb' - -# Offense count: 9 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/FormatString: - Exclude: - - 'lib/raven/event.rb' - - 'lib/raven/integrations/rack.rb' - -# Offense count: 2 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'lib/raven/base.rb' - - 'lib/raven/configuration.rb' - -# Offense count: 119 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, UseHashRocketsWithSymbolValues. -Style/HashSyntax: - EnforcedStyle: hash_rockets - -# Offense count: 24 -# Cop supports --auto-correct. -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Exclude: - - 'lib/raven/event.rb' - - 'lib/raven/interfaces/exception.rb' - - 'lib/raven/interfaces/single_exception.rb' - -# Offense count: 58 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/IndentHash: - Enabled: false - - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: Width. -Style/IndentationWidth: - Exclude: - - 'lib/raven/event.rb' - - 'lib/raven/interfaces/stack_trace.rb' - - 'spec/raven/event_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -Style/Lambda: - Exclude: - - 'spec/raven/configuration_spec.rb' - - 'spec/raven/integrations/rack_spec.rb' - - 'spec/raven/raven_spec.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Style/LeadingCommentSpace: - Exclude: - - 'lib/raven/cli.rb' - - 'lib/raven/interfaces/http.rb' - - 'lib/raven/processor/sanitizedata.rb' - - 'lib/raven/transports.rb' - -# Offense count: 1 -Style/MultilineBlockChain: - Exclude: - - 'lib/raven/event.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/NegatedIf: - Exclude: - - 'lib/raven/client.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -Style/NumericLiterals: - MinDigits: 17 - -# Offense count: 4 -# Cop supports --auto-correct. -Style/ParallelAssignment: - Exclude: - - 'lib/raven/interfaces/stack_trace.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'lib/raven/base.rb' - - 'spec/raven/configuration_spec.rb' - - 'spec/raven/raven_spec.rb' - -# Offense count: 1 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. -Style/PredicateName: - Exclude: - - 'lib/raven/linecache.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Style/Proc: - Exclude: - - 'lib/raven/integrations/sidekiq.rb' - - 'spec/raven/configuration_spec.rb' - - 'spec/raven/raven_spec.rb' - -# Offense count: 10 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/RaiseArgs: - Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantBegin: - Exclude: - - 'lib/raven/processor/sanitizedata.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/raven/linecache.rb' - - 'spec/spec_helper.rb' - -# Offense count: 45 -# Cop supports --auto-correct. -Style/RedundantSelf: - Exclude: - - 'lib/raven/backtrace.rb' - - 'lib/raven/base.rb' - - 'lib/raven/client.rb' - - 'lib/raven/configuration.rb' - - 'lib/raven/interfaces/http.rb' - - 'lib/raven/interfaces/stack_trace.rb' - - 'lib/raven/transports/http.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. -Style/RegexpLiteral: - Exclude: - - 'lib/raven/backtrace.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -Style/RescueModifier: - Exclude: - - 'lib/raven/configuration.rb' - - 'lib/raven/event.rb' - -# Offense count: 1 -# Configuration parameters: Methods. -Style/SingleLineBlockParams: - Exclude: - - 'lib/raven/client.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -Style/SpaceBeforeFirstArg: - Exclude: - - 'exe/raven' - -# Offense count: 45 -# Cop supports --auto-correct. -Style/SpaceAfterComma: - Exclude: - - 'exe/raven' - - 'lib/raven/integrations/sidekiq.rb' - - 'lib/raven/processor/sanitizedata.rb' - - 'spec/raven/processors/sanitizedata_processor_spec.rb' - -# Offense count: 72 -# Cop supports --auto-correct. -# Configuration parameters: MultiSpaceAllowedForOperators. -Style/SpaceAroundOperators: - Exclude: - - 'lib/raven/client.rb' - - 'lib/raven/event.rb' - - 'lib/raven/integrations/sidekiq.rb' - - 'lib/raven/interfaces/stack_trace.rb' - - 'spec/raven/processors/sanitizedata_processor_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceBeforeBlockBraces: - Enabled: false - -# Offense count: 17 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -Style/SpaceInsideBlockBraces: - Enabled: false - -# Offense count: 3 -# Cop supports --auto-correct. -Style/SpaceInsideBrackets: - Exclude: - - 'lib/raven/integrations/rack.rb' - - 'lib/raven/interfaces.rb' - -# Offense count: 22 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. -Style/SpaceInsideHashLiteralBraces: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -Style/SpecialGlobalVars: - Exclude: - - 'lib/raven/base.rb' - - 'sentry-raven.gemspec' - -# Offense count: 201 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/StringLiterals: - Enabled: false - -# Offense count: 33 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. -Style/TrailingCommaInLiteral: - Exclude: - - 'lib/raven/configuration.rb' - - 'lib/raven/event.rb' - - 'lib/raven/integrations/rails/active_job.rb' - - 'lib/raven/logger.rb' - - 'spec/raven/event_spec.rb' - - 'spec/raven/processors/sanitizedata_processor_spec.rb' diff --git a/exe/raven b/exe/raven index 19eaf03e7..1bddf49d8 100755 --- a/exe/raven +++ b/exe/raven @@ -20,7 +20,7 @@ parser = OptionParser.new do |opt| # options[:daemon] = true # end - opt.on("-h","--help","help") do + opt.on("-h", "--help", "help") do puts parser end end @@ -28,13 +28,13 @@ end parser.parse! case ARGV[0] - when "test" - dsn = ARGV[1] if ARGV.length > 1 - if !dsn - puts "Usage: raven test " - else - Raven::CLI.test(dsn) - end +when "test" + dsn = ARGV[1] if ARGV.length > 1 + if !dsn + puts "Usage: raven test " else - puts parser + Raven::CLI.test(dsn) + end +else + puts parser end diff --git a/lib/raven/backtrace.rb b/lib/raven/backtrace.rb index e726de289..09a1148cd 100644 --- a/lib/raven/backtrace.rb +++ b/lib/raven/backtrace.rb @@ -1,16 +1,15 @@ ## Inspired by Rails' and Airbrake's backtrace parsers. module Raven - # Front end to parsing the backtrace for each notice class Backtrace # Handles backtrace parsing line by line class Line # regexp (optionnally allowing leading X: for windows support) - RUBY_INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$} + RUBY_INPUT_FORMAT = /^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$/ # org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170) - JAVA_INPUT_FORMAT = %r{^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$} + JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$/ # The file portion of the line (such as app/models/user.rb) attr_reader :file @@ -47,7 +46,7 @@ def initialize(file, number, method, module_name) end def in_app - if self.file =~ self.class.in_app_pattern + if file =~ self.class.in_app_pattern true else false diff --git a/lib/raven/base.rb b/lib/raven/base.rb index e662cc972..d5932eee0 100644 --- a/lib/raven/base.rb +++ b/lib/raven/base.rb @@ -25,7 +25,7 @@ require 'English' module Raven - AVAILABLE_INTEGRATIONS = %w[delayed_job railties sidekiq rack rack-timeout rake].freeze + AVAILABLE_INTEGRATIONS = %w(delayed_job railties sidekiq rack rack-timeout rake).freeze class << self extend Forwardable @@ -63,7 +63,7 @@ def inject_only(*only_integrations) integrations_to_load = Raven::AVAILABLE_INTEGRATIONS & only_integrations not_found_integrations = only_integrations - integrations_to_load if not_found_integrations.any? - self.logger.warn "Integrations do not exist: #{not_found_integrations.join ', '}" + logger.warn "Integrations do not exist: #{not_found_integrations.join ', '}" end integrations_to_load &= Gem.loaded_specs.keys # TODO(dcramer): integrations should have some additional checks baked-in @@ -78,7 +78,7 @@ def inject_only(*only_integrations) def load_integration(integration) require "raven/integrations/#{integration}" rescue Exception => error - self.logger.warn "Unable to load raven/integrations/#{integration}: #{error}" + logger.warn "Unable to load raven/integrations/#{integration}: #{error}" end def safely_prepend(module_name, opts = {}) diff --git a/lib/raven/cli.rb b/lib/raven/cli.rb index d6f2fc99f..7d23edbd6 100644 --- a/lib/raven/cli.rb +++ b/lib/raven/cli.rb @@ -1,6 +1,6 @@ module Raven class CLI - def self.test(dsn = nil, silent = false) + def self.test(dsn = nil, silent = false) # rubocop:disable all if silent Raven.configuration.logger = ::Logger.new(nil) else @@ -40,7 +40,7 @@ def self.test(dsn = nil, silent = false) else Raven.logger.debug "-> event ID: #{evt.id}" end - elsif evt #async configuration + elsif evt # async configuration if evt.value.is_a? Hash Raven.logger.debug "-> event ID: #{evt.value[:event_id]}" else diff --git a/lib/raven/client.rb b/lib/raven/client.rb index 2eaceabc0..bfc63819c 100644 --- a/lib/raven/client.rb +++ b/lib/raven/client.rb @@ -38,7 +38,7 @@ def send_event(event) begin transport.send_event(generate_auth_header, encoded_data, - :content_type => content_type) + :content_type => content_type) successful_send rescue => e failed_send(e, event) @@ -63,7 +63,7 @@ def transport private def encode(event) - hash = @processors.reduce(event.to_hash) { |memo, p| p.process(memo) } + hash = @processors.reduce(event.to_hash) { |a, e| e.process(a) } encoded = JSON.generate(hash) case configuration.encoding @@ -115,7 +115,7 @@ def initialize def should_try? return true if @status == :online - interval = @retry_after || [@retry_number, 6].min ** 2 + interval = @retry_after || [@retry_number, 6].min**2 return true if Time.now - @last_check >= interval false diff --git a/lib/raven/configuration.rb b/lib/raven/configuration.rb index 81e09810b..df91b666c 100644 --- a/lib/raven/configuration.rb +++ b/lib/raven/configuration.rb @@ -146,7 +146,7 @@ class Configuration 'ActiveRecord::RecordNotFound', 'CGI::Session::CookieStore::TamperedWithCookie', 'Mongoid::Errors::DocumentNotFound', - 'Sinatra::NotFound', + 'Sinatra::NotFound' ].freeze # Note the order - we have to remove circular references and bad characters @@ -156,7 +156,7 @@ class Configuration Raven::Processor::UTF8Conversion, Raven::Processor::SanitizeData, Raven::Processor::Cookies, - Raven::Processor::PostData, + Raven::Processor::PostData ].freeze def initialize @@ -210,22 +210,28 @@ def server=(value) alias dsn= server= def encoding=(encoding) - raise Error.new('Unsupported encoding') unless %w(gzip json).include? encoding + raise(Error, 'Unsupported encoding') unless %w(gzip json).include? encoding @encoding = encoding end def async=(value) - raise ArgumentError.new("async must be callable (or false to disable)") unless value == false || value.respond_to?(:call) + unless value == false || value.respond_to?(:call) + raise(ArgumentError, "async must be callable (or false to disable)") + end @async = value end def transport_failure_callback=(value) - raise ArgumentError.new("transport_failure_callback must be callable (or false to disable)") unless value == false || value.respond_to?(:call) + unless value == false || value.respond_to?(:call) + raise(ArgumentError, "transport_failure_callback must be callable (or false to disable)") + end @transport_failure_callback = value end def should_capture=(value) - raise ArgumentError.new("should_capture must be callable (or false to disable)") unless value == false || value.respond_to?(:call) + unless value == false || value.respond_to?(:call) + raise ArgumentError, "should_capture must be callable (or false to disable)" + end @should_capture = value end @@ -250,7 +256,7 @@ def capture_allowed?(message_or_exc = nil) def verify! %w(server public_key secret_key project_id).each do |key| - raise Error.new("No #{key} specified") unless self.public_send key + raise(Error, "No #{key} specified") unless public_send key end end diff --git a/lib/raven/event.rb b/lib/raven/event.rb index 83ea0cfd6..1bf0bc0db 100644 --- a/lib/raven/event.rb +++ b/lib/raven/event.rb @@ -8,7 +8,6 @@ require 'raven/linecache' module Raven - class Event LOG_LEVELS = { "debug" => 10, @@ -16,7 +15,7 @@ class Event "warn" => 30, "warning" => 30, "error" => 40, - "fatal" => 50, + "fatal" => 50 }.freeze BACKTRACE_RE = /^(.+?):(\d+)(?::in `(.+?)')?$/ @@ -25,8 +24,8 @@ class Event attr_reader :id attr_accessor :project, :message, :timestamp, :time_spent, :level, :logger, - :culprit, :server_name, :release, :modules, :extra, :tags, :context, :configuration, - :checksum, :fingerprint, :environment + :culprit, :server_name, :release, :modules, :extra, :tags, :context, :configuration, + :checksum, :fingerprint, :environment def initialize(init = {}) @configuration = Raven.configuration @@ -67,7 +66,7 @@ def initialize(init = {}) # Some type coercion @timestamp = @timestamp.strftime('%Y-%m-%dT%H:%M:%S') if @timestamp.is_a?(Time) - @time_spent = (@time_spent*1000).to_i if @time_spent.is_a?(Float) + @time_spent = (@time_spent * 1000).to_i if @time_spent.is_a?(Float) @level = LOG_LEVELS[@level.to_s.downcase] if @level.is_a?(String) || @level.is_a?(Symbol) end @@ -99,7 +98,7 @@ def from_exception(exc, options = {}, &block) end def from_message(message, options = {}) - message = message.byteslice(0...10000) # Messages limited to 10kb + message = message.byteslice(0...10_000) # Messages limited to 10kb configuration = options[:configuration] || Raven.configuration new(options) do |evt| @@ -135,9 +134,7 @@ def add_exception_interface(evt, exc) while exc.respond_to?(:cause) && exc.cause exc = exc.cause - if context.include?(exc.object_id) - break - end + break if context.include?(exc.object_id) exceptions << exc context.add(exc.object_id) end @@ -196,7 +193,7 @@ def list_gem_specs def interface(name, value = nil, &block) int = Raven.find_interface(name) - raise Error.new("Unknown interface: #{name}") unless int + raise(Error, "Unknown interface: #{name}") unless int @interfaces[int.name] = int.new(value, &block) if value || block @interfaces[int.name] end @@ -217,7 +214,7 @@ def to_hash :time_spent => @time_spent, :level => @level, :project => @project, - :platform => PLATFORM, + :platform => PLATFORM } data[:logger] = @logger if @logger data[:culprit] = @culprit if @culprit @@ -238,7 +235,7 @@ def to_hash end def get_file_context(filename, lineno, context) - return nil, nil, nil unless Raven::LineCache.is_valid_file(filename) + return nil, nil, nil unless Raven::LineCache.valid_file?(filename) lines = Array.new(2 * context + 1) do |i| Raven::LineCache.getline(filename, lineno - context + i) end @@ -252,10 +249,10 @@ def get_culprit(frames) # For cross-language compat class << self - alias :captureException :from_exception - alias :captureMessage :from_message - alias :capture_exception :from_exception - alias :capture_message :from_message + alias captureException from_exception + alias captureMessage from_message + alias capture_exception from_exception + alias capture_message from_message end private @@ -266,7 +263,7 @@ def generate_event_id ary = SecureRandom.random_bytes(16).unpack("NnnnnN") ary[2] = (ary[2] & 0x0fff) | 0x4000 ary[3] = (ary[3] & 0x3fff) | 0x8000 - uuid = "%08x-%04x-%04x-%04x-%04x%08x" % ary + uuid = "%08x-%04x-%04x-%04x-%04x%08x" % ary # rubocop:disable Style/FormatString ::Digest::MD5.hexdigest(uuid) end end diff --git a/lib/raven/integrations/delayed_job.rb b/lib/raven/integrations/delayed_job.rb index 711bcb79b..ffd3e19da 100644 --- a/lib/raven/integrations/delayed_job.rb +++ b/lib/raven/integrations/delayed_job.rb @@ -21,7 +21,7 @@ class Raven < ::Delayed::Plugin :locked_by => job.locked_by, :queue => job.queue, :created_at => job.created_at - } + } } # last_error can be nil extra[:last_error] = job.last_error[0...100] if job.last_error @@ -33,12 +33,12 @@ class Raven < ::Delayed::Plugin extra[:active_job] = job.payload_object.job_data end ::Raven.capture_exception(exception, - :logger => 'delayed_job', - :tags => { - :delayed_job_queue => job.queue, - :delayed_job_id => job.id - }, - :extra => extra) + :logger => 'delayed_job', + :tags => { + :delayed_job_queue => job.queue, + :delayed_job_id => job.id + }, + :extra => extra) # Make sure we propagate the failure! raise exception @@ -49,7 +49,6 @@ class Raven < ::Delayed::Plugin end end end - end end diff --git a/lib/raven/integrations/rack.rb b/lib/raven/integrations/rack.rb index bde1586b1..d1b4107d5 100644 --- a/lib/raven/integrations/rack.rb +++ b/lib/raven/integrations/rack.rb @@ -51,7 +51,6 @@ def call(env) rescue Error raise # Don't capture Raven errors rescue Exception => e - Raven.logger.debug "Collecting %p: %s" % [ e.class, e.message ] Raven::Rack.capture_exception(e, env) raise end diff --git a/lib/raven/integrations/rails/active_job.rb b/lib/raven/integrations/rails/active_job.rb index 780639d34..f75a27b45 100644 --- a/lib/raven/integrations/rails/active_job.rb +++ b/lib/raven/integrations/rails/active_job.rb @@ -12,7 +12,7 @@ def self.included(base) :arguments => arguments, :scheduled_at => scheduled_at, :job_id => job_id, - :locale => locale, + :locale => locale } # Add provider_job_id details if Rails 5 diff --git a/lib/raven/integrations/rake.rb b/lib/raven/integrations/rake.rb index a8b22256b..00108ff13 100644 --- a/lib/raven/integrations/rake.rb +++ b/lib/raven/integrations/rake.rb @@ -4,7 +4,7 @@ module Rake class Application - alias :orig_display_error_messsage :display_error_message + alias orig_display_error_messsage display_error_message def display_error_message(ex) Raven.capture_exception ex, :logger => 'rake', :tags => { 'rake_task' => @name } orig_display_error_messsage(ex) diff --git a/lib/raven/integrations/sidekiq.rb b/lib/raven/integrations/sidekiq.rb index 7eda5f9d4..9420145cb 100644 --- a/lib/raven/integrations/sidekiq.rb +++ b/lib/raven/integrations/sidekiq.rb @@ -8,7 +8,7 @@ def call(_worker, msg, _queue) yield rescue Exception => ex Raven.capture_exception(ex, :extra => { :sidekiq => msg }, - :time_spent => Time.now-started_at) + :time_spent => Time.now - started_at) raise ensure Context.clear! @@ -26,10 +26,10 @@ def call(_worker, msg, _queue) end else Sidekiq.configure_server do |config| - config.error_handlers << Proc.new do |ex, context| + config.error_handlers << proc do |ex, context| Raven.capture_exception(ex, :extra => { - :sidekiq => filter_context(context) - }) + :sidekiq => filter_context(context) + }) end end end diff --git a/lib/raven/interfaces.rb b/lib/raven/interfaces.rb index 8c4916924..ac358feb8 100644 --- a/lib/raven/interfaces.rb +++ b/lib/raven/interfaces.rb @@ -1,5 +1,4 @@ module Raven - # TODO: a constant isn't appropriate here, refactor INTERFACES = {} # rubocop:disable Style/MutableConstant @@ -17,7 +16,7 @@ def self.name(value = nil) end def to_hash - Hash[instance_variables.map { |name| [name[1..-1].to_sym, instance_variable_get(name)] } ] + Hash[instance_variables.map { |name| [name[1..-1].to_sym, instance_variable_get(name)] }] end end diff --git a/lib/raven/interfaces/exception.rb b/lib/raven/interfaces/exception.rb index 2299ac92a..9c6d5c8fc 100644 --- a/lib/raven/interfaces/exception.rb +++ b/lib/raven/interfaces/exception.rb @@ -7,9 +7,7 @@ class ExceptionInterface < Interface def to_hash(*args) data = super(*args) - if data[:values] - data[:values] = data[:values].map(&:to_hash) - end + data[:values] = data[:values].map(&:to_hash) if data[:values] data end end diff --git a/lib/raven/interfaces/single_exception.rb b/lib/raven/interfaces/single_exception.rb index 944d5ab89..4af751b46 100644 --- a/lib/raven/interfaces/single_exception.rb +++ b/lib/raven/interfaces/single_exception.rb @@ -9,9 +9,7 @@ class SingleExceptionInterface < Interface def to_hash(*args) data = super(*args) - if data[:stacktrace] - data[:stacktrace] = data[:stacktrace].to_hash - end + data[:stacktrace] = data[:stacktrace].to_hash if data[:stacktrace] data end end diff --git a/lib/raven/interfaces/stack_trace.rb b/lib/raven/interfaces/stack_trace.rb index e9b7238b4..8ba3aa276 100644 --- a/lib/raven/interfaces/stack_trace.rb +++ b/lib/raven/interfaces/stack_trace.rb @@ -34,7 +34,7 @@ def initialize(*arguments) end def filename - return nil if self.abs_path.nil? + return nil if abs_path.nil? prefix = if under_project_root? && in_app @@ -45,7 +45,7 @@ def filename longest_load_path end - prefix ? self.abs_path[prefix.to_s.chomp(File::SEPARATOR).length+1..-1] : self.abs_path + prefix ? abs_path[prefix.to_s.chomp(File::SEPARATOR).length + 1..-1] : abs_path end def under_project_root? @@ -57,16 +57,16 @@ def project_root end def longest_load_path - $LOAD_PATH.select { |s| self.abs_path.start_with?(s.to_s) }.sort_by { |s| s.to_s.length }.last + $LOAD_PATH.select { |s| abs_path.start_with?(s.to_s) }.sort_by { |s| s.to_s.length }.last end def to_hash(*args) data = super(*args) - data[:filename] = self.filename - data.delete(:vars) unless self.vars && !self.vars.empty? - data.delete(:pre_context) unless self.pre_context && !self.pre_context.empty? - data.delete(:post_context) unless self.post_context && !self.post_context.empty? - data.delete(:context_line) unless self.context_line && !self.context_line.empty? + data[:filename] = filename + data.delete(:vars) unless vars && !vars.empty? + data.delete(:pre_context) unless pre_context && !pre_context.empty? + data.delete(:post_context) unless post_context && !post_context.empty? + data.delete(:context_line) unless context_line && !context_line.empty? data end end diff --git a/lib/raven/linecache.rb b/lib/raven/linecache.rb index 424c8bdff..d537ee776 100644 --- a/lib/raven/linecache.rb +++ b/lib/raven/linecache.rb @@ -8,7 +8,7 @@ class << self # variable? CACHE = {} # rubocop:disable Style/MutableConstant - def is_valid_file(path) + def valid_file?(path) lines = getlines(path) !lines.nil? end diff --git a/lib/raven/logger.rb b/lib/raven/logger.rb index 2d6431340..de420bf4b 100644 --- a/lib/raven/logger.rb +++ b/lib/raven/logger.rb @@ -10,7 +10,7 @@ class Logger :error, :warn, :info, - :debug, + :debug ].each do |level| define_method level do |*args, &block| logger = Raven.configuration[:logger] diff --git a/lib/raven/processor/sanitizedata.rb b/lib/raven/processor/sanitizedata.rb index 64cc60dca..4f721e5f4 100644 --- a/lib/raven/processor/sanitizedata.rb +++ b/lib/raven/processor/sanitizedata.rb @@ -15,23 +15,23 @@ def initialize(client) end def process(value) - value.each_with_object(value) { |(k,v), memo| memo[k] = sanitize(k,v) } + value.each_with_object(value) { |(k, v), memo| memo[k] = sanitize(k, v) } end - def sanitize(k,v) + def sanitize(k, v) if v.is_a?(Hash) process(v) elsif v.is_a?(Array) - v.map{|a| sanitize(k, a)} + v.map { |a| sanitize(k, a) } elsif k.to_s == 'query_string' sanitize_query_string(v) - elsif v.is_a?(Integer) && matches_regexes?(k,v) + elsif v.is_a?(Integer) && matches_regexes?(k, v) INT_MASK elsif v.is_a?(String) if fields_re.match(v.to_s) && (json = parse_json_or_nil(v)) - #if this string is actually a json obj, convert and sanitize + # if this string is actually a json obj, convert and sanitize json.is_a?(Hash) ? process(json).to_json : v - elsif matches_regexes?(k,v) + elsif matches_regexes?(k, v) STRING_MASK else v @@ -69,11 +69,9 @@ def special_characters?(string) end def parse_json_or_nil(string) - begin - JSON.parse(string) - rescue JSON::ParserError, NoMethodError - nil - end + JSON.parse(string) + rescue JSON::ParserError, NoMethodError + nil end end end diff --git a/lib/raven/transports.rb b/lib/raven/transports.rb index c5c77cac6..de3654ad7 100644 --- a/lib/raven/transports.rb +++ b/lib/raven/transports.rb @@ -9,8 +9,8 @@ def initialize(configuration) @configuration = configuration end - def send_event #(auth_header, data, options = {}) - raise NotImplementedError.new('Abstract method not implemented') + def send_event # (auth_header, data, options = {}) + raise NotImplementedError, 'Abstract method not implemented' end protected diff --git a/sentry-raven.gemspec b/sentry-raven.gemspec index 4a527e267..06a79cd54 100644 --- a/sentry-raven.gemspec +++ b/sentry-raven.gemspec @@ -1,4 +1,4 @@ -$:.unshift File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('../lib', __FILE__) require 'raven/version' Gem::Specification.new do |gem| diff --git a/spec/raven/breadcrumbs_spec.rb b/spec/raven/breadcrumbs_spec.rb index ddc086fa6..0d01df535 100644 --- a/spec/raven/breadcrumbs_spec.rb +++ b/spec/raven/breadcrumbs_spec.rb @@ -34,7 +34,7 @@ it "is enumerable" do (0..10).each do |i| - @breadcrumbs.record(Raven::Breadcrumb.new.tap {|b| b.message = i}) + @breadcrumbs.record(Raven::Breadcrumb.new.tap { |b| b.message = i }) end expect(@breadcrumbs.each).to be_a Enumerator @@ -42,7 +42,7 @@ it "evicts when buffer exceeded" do (0..10).each do |i| - @breadcrumbs.record(Raven::Breadcrumb.new.tap {|b| b.message = i}) + @breadcrumbs.record(Raven::Breadcrumb.new.tap { |b| b.message = i }) end expect(@breadcrumbs.members[0].message).to eq(1) diff --git a/spec/raven/configuration_spec.rb b/spec/raven/configuration_spec.rb index 751acb4ae..236a3f099 100644 --- a/spec/raven/configuration_spec.rb +++ b/spec/raven/configuration_spec.rb @@ -34,25 +34,25 @@ context 'configuring for async' do it 'should be configurable to send events async' do - subject.async = lambda { |_e| :ok } + subject.async = ->(_e) { :ok } expect(subject.async.call('event')).to eq(:ok) end it 'should raise when setting async to anything other than callable or false' do - subject.transport_failure_callback = lambda {} + subject.transport_failure_callback = -> {} subject.transport_failure_callback = false expect { subject.async = true }.to raise_error(ArgumentError) end end it 'should raise when setting transport_failure_callback to anything other than callable or false' do - subject.transport_failure_callback = lambda {} + subject.transport_failure_callback = -> {} subject.transport_failure_callback = false expect { subject.transport_failure_callback = true }.to raise_error(ArgumentError) end it 'should raise when setting should_capture to anything other than callable or false' do - subject.should_capture = lambda {} + subject.should_capture = -> {} subject.should_capture = false expect { subject.should_capture = true }.to raise_error(ArgumentError) end @@ -64,19 +64,19 @@ end it 'should send events if test is whitelisted' do - subject.environments = %w[test] + subject.environments = %w(test) expect(subject.capture_allowed?).to eq(true) end it 'should not send events if test is not whitelisted' do - subject.environments = %w[not_test] + subject.environments = %w(not_test) expect(subject.capture_allowed?).to eq(false) end end context 'with a should_capture callback configured' do before(:each) do - subject.should_capture = lambda { |exc_or_msg| exc_or_msg != "dont send me" } + subject.should_capture = ->(exc_or_msg) { exc_or_msg != "dont send me" } subject.server = 'http://sentry.localdomain/sentry' end @@ -87,7 +87,7 @@ end it "should verify server configuration, looking for missing keys" do - expect{ subject.verify! }.to raise_error(Raven::Error, "No server specified") + expect { subject.verify! }.to raise_error(Raven::Error, "No server specified") subject.server, subject.public_key, subject.secret_key, subject.project_id = "", "", "", "" diff --git a/spec/raven/event_spec.rb b/spec/raven/event_spec.rb index 290308637..cfbb4a060 100644 --- a/spec/raven/event_spec.rb +++ b/spec/raven/event_spec.rb @@ -8,20 +8,18 @@ context 'a fully implemented event' do let(:hash) do - Raven::Event.new({ - :message => 'test', - :level => 'warning', - :logger => 'foo', - :tags => { - 'foo' => 'bar' - }, - :extra => { - 'my_custom_variable' => 'value' - }, - :server_name => 'foo.local', - :release => '721e41770371db95eee98ca2707686226b993eda', - :environment => 'production', - }).to_hash + Raven::Event.new(:message => 'test', + :level => 'warning', + :logger => 'foo', + :tags => { + 'foo' => 'bar' + }, + :extra => { + 'my_custom_variable' => 'value' + }, + :server_name => 'foo.local', + :release => '721e41770371db95eee98ca2707686226b993eda', + :environment => 'production').to_hash end it 'has message' do @@ -49,15 +47,11 @@ end it 'has tag data' do - expect(hash[:tags]).to eq({ - 'foo' => 'bar' - }) + expect(hash[:tags]).to eq('foo' => 'bar') end it 'has extra data' do - expect(hash[:extra]).to eq({ - 'my_custom_variable' => 'value' - }) + expect(hash[:extra]).to eq('my_custom_variable' => 'value') end it 'has platform' do @@ -67,81 +61,63 @@ context 'user context specified' do let(:hash) do - Raven.user_context({ - 'id' => 'hello', - }) + Raven.user_context('id' => 'hello') - Raven::Event.new({ - :level => 'warning', - :logger => 'foo', - :tags => { - 'foo' => 'bar' - }, - :extra => { - 'my_custom_variable' => 'value' - }, - :server_name => 'foo.local', - }).to_hash + Raven::Event.new(:level => 'warning', + :logger => 'foo', + :tags => { + 'foo' => 'bar' + }, + :extra => { + 'my_custom_variable' => 'value' + }, + :server_name => 'foo.local').to_hash end it "adds user data" do - expect(hash[:user]).to eq({ - 'id' => 'hello', - }) + expect(hash[:user]).to eq('id' => 'hello') end end context 'tags context specified' do let(:hash) do - Raven.tags_context({ - 'key' => 'value', - }) + Raven.tags_context('key' => 'value') - Raven::Event.new({ - :level => 'warning', - :logger => 'foo', - :tags => { - 'foo' => 'bar' - }, - :extra => { - 'my_custom_variable' => 'value' - }, - :server_name => 'foo.local', - }).to_hash + Raven::Event.new(:level => 'warning', + :logger => 'foo', + :tags => { + 'foo' => 'bar' + }, + :extra => { + 'my_custom_variable' => 'value' + }, + :server_name => 'foo.local').to_hash end it "merges tags data" do - expect(hash[:tags]).to eq({ - 'key' => 'value', - 'foo' => 'bar', - }) + expect(hash[:tags]).to eq('key' => 'value', + 'foo' => 'bar') end end context 'extra context specified' do let(:hash) do - Raven.extra_context({ - 'key' => 'value', - }) + Raven.extra_context('key' => 'value') - Raven::Event.new({ - :level => 'warning', - :logger => 'foo', - :tags => { - 'foo' => 'bar' - }, - :extra => { - 'my_custom_variable' => 'value' - }, - :server_name => 'foo.local', - }).to_hash + Raven::Event.new(:level => 'warning', + :logger => 'foo', + :tags => { + 'foo' => 'bar' + }, + :extra => { + 'my_custom_variable' => 'value' + }, + :server_name => 'foo.local').to_hash end it "merges extra data" do - expect(hash[:extra]).to eq({ - 'key' => 'value', - 'my_custom_variable' => 'value', - }) + expect(hash[:extra]).to eq('key' => 'value', + 'my_custom_variable' => 'value') end end @@ -149,50 +125,42 @@ require 'stringio' let(:hash) do - Raven.rack_context({ - 'REQUEST_METHOD' => 'POST', - 'QUERY_STRING' => 'biz=baz', - 'HTTP_HOST' => 'localhost', - 'SERVER_NAME' => 'localhost', - 'SERVER_PORT' => '80', - 'PATH_INFO' => '/lol', - 'rack.url_scheme' => 'http', - 'rack.input' => StringIO.new('foo=bar'), - }) - - Raven::Event.new({ - :level => 'warning', - :logger => 'foo', - :tags => { - 'foo' => 'bar' - }, - :extra => { - 'my_custom_variable' => 'value' - }, - :server_name => 'foo.local', - }).to_hash + Raven.rack_context('REQUEST_METHOD' => 'POST', + 'QUERY_STRING' => 'biz=baz', + 'HTTP_HOST' => 'localhost', + 'SERVER_NAME' => 'localhost', + 'SERVER_PORT' => '80', + 'PATH_INFO' => '/lol', + 'rack.url_scheme' => 'http', + 'rack.input' => StringIO.new('foo=bar')) + + Raven::Event.new(:level => 'warning', + :logger => 'foo', + :tags => { + 'foo' => 'bar' + }, + :extra => { + 'my_custom_variable' => 'value' + }, + :server_name => 'foo.local').to_hash end it "adds http data" do - expect(hash[:request]).to eq({ - :data => { 'foo' => 'bar' }, - :env => { 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80' }, - :headers => { 'Host' => 'localhost' }, - :method => 'POST', - :query_string => 'biz=baz', - :url => 'http://localhost/lol', - :cookies => nil - }) + expect(hash[:request]).to eq(:data => { 'foo' => 'bar' }, + :env => { 'SERVER_NAME' => 'localhost', 'SERVER_PORT' => '80' }, + :headers => { 'Host' => 'localhost' }, + :method => 'POST', + :query_string => 'biz=baz', + :url => 'http://localhost/lol', + :cookies => nil) end end context "rack context, long body" do let(:hash) do - Raven.rack_context({ - 'REQUEST_METHOD' => 'GET', - 'rack.url_scheme' => 'http', - 'rack.input' => StringIO.new('a' * 16_000), - }) + Raven.rack_context('REQUEST_METHOD' => 'GET', + 'rack.url_scheme' => 'http', + 'rack.input' => StringIO.new('a' * 16_000)) Raven::Event.new.to_hash end @@ -219,10 +187,8 @@ end it 'merges tags data' do - expect(hash[:tags]).to eq({ - 'key' => 'value', - 'foo' => 'bar' - }) + expect(hash[:tags]).to eq('key' => 'value', + 'foo' => 'bar') end end @@ -255,18 +221,16 @@ let(:hash) do config = Raven::Configuration.new config.tags = { - 'configuration_context_event_key' => 'configuration_value', - 'configuration_context_key' => 'configuration_value', - 'configuration_event_key' => 'configuration_value', - 'configuration_key' => 'configuration_value', + 'configuration_context_event_key' => 'configuration_value', + 'configuration_context_key' => 'configuration_value', + 'configuration_event_key' => 'configuration_value', + 'configuration_key' => 'configuration_value' } - Raven.tags_context({ - 'configuration_context_event_key' => 'context_value', - 'configuration_context_key' => 'context_value', - 'context_event_key' => 'context_value', - 'context_key' => 'context_value', - }) + Raven.tags_context('configuration_context_event_key' => 'context_value', + 'configuration_context_key' => 'context_value', + 'context_event_key' => 'context_value', + 'context_key' => 'context_value') Raven::Event.new( :level => 'warning', @@ -275,7 +239,7 @@ 'configuration_context_event_key' => 'event_value', 'configuration_event_key' => 'event_value', 'context_event_key' => 'event_value', - 'event_key' => 'event_value', + 'event_key' => 'event_value' }, :server_name => 'foo.local', :configuration => config @@ -283,67 +247,53 @@ end it 'merges tags data' do - expect(hash[:tags]).to eq({ - 'configuration_context_event_key' => 'event_value', - 'configuration_context_key' => 'context_value', - 'configuration_event_key' => 'event_value', - 'context_event_key' => 'event_value', - 'configuration_key' => 'configuration_value', - 'context_key' => 'context_value', - 'event_key' => 'event_value', - }) + expect(hash[:tags]).to eq('configuration_context_event_key' => 'event_value', + 'configuration_context_key' => 'context_value', + 'configuration_event_key' => 'event_value', + 'context_event_key' => 'event_value', + 'configuration_key' => 'configuration_value', + 'context_key' => 'context_value', + 'event_key' => 'event_value') end end context 'merging user context' do before do - Raven.user_context({ - 'context_event_key' => 'context_value', - 'context_key' => 'context_value', - }) + Raven.user_context('context_event_key' => 'context_value', + 'context_key' => 'context_value') end let(:hash) do - Raven::Event.new({ - :user => { - 'context_event_key' => 'event_value', - 'event_key' => 'event_value', - }, - }).to_hash + Raven::Event.new(:user => { + 'context_event_key' => 'event_value', + 'event_key' => 'event_value' + }).to_hash end it 'prioritizes event context over request context' do - expect(hash[:user]).to eq({ - 'context_event_key' => 'event_value', - 'context_key' => 'context_value', - 'event_key' => 'event_value', - }) + expect(hash[:user]).to eq('context_event_key' => 'event_value', + 'context_key' => 'context_value', + 'event_key' => 'event_value') end end context 'merging extra context' do before do - Raven.extra_context({ - 'context_event_key' => 'context_value', - 'context_key' => 'context_value', - }) + Raven.extra_context('context_event_key' => 'context_value', + 'context_key' => 'context_value') end let(:hash) do - Raven::Event.new({ - :extra => { - 'context_event_key' => 'event_value', - 'event_key' => 'event_value', - }, - }).to_hash + Raven::Event.new(:extra => { + 'context_event_key' => 'event_value', + 'event_key' => 'event_value' + }).to_hash end it 'prioritizes event context over request context' do - expect(hash[:extra]).to eq({ - 'context_event_key' => 'event_value', - 'context_key' => 'context_value', - 'event_key' => 'event_value', - }) + expect(hash[:extra]).to eq('context_event_key' => 'event_value', + 'context_key' => 'context_value', + 'event_key' => 'event_value') end end @@ -351,27 +301,23 @@ class ExceptionWithContext < StandardError def raven_context { :extra => { - 'context_event_key' => 'context_value', - 'context_key' => 'context_value' + 'context_event_key' => 'context_value', + 'context_key' => 'context_value' } } end end let(:hash) do - Raven::Event.from_exception(ExceptionWithContext.new, { - :extra => { - 'context_event_key' => 'event_value', - 'event_key' => 'event_value', - }, - }).to_hash + Raven::Event.from_exception(ExceptionWithContext.new, :extra => { + 'context_event_key' => 'event_value', + 'event_key' => 'event_value' + }).to_hash end it 'prioritizes event context over request context' do - expect(hash[:extra]).to eq({ - 'context_event_key' => 'event_value', - 'context_key' => 'context_value', - 'event_key' => 'event_value', - }) + expect(hash[:extra]).to eq('context_event_key' => 'event_value', + 'context_key' => 'context_value', + 'event_key' => 'event_value') end end @@ -408,7 +354,7 @@ def raven_context it 'accepts a stacktrace' do backtrace = ["/path/to/some/file:22:in `function_name'", - "/some/other/path:1412:in `other_function'"] + "/some/other/path:1412:in `other_function'"] evt = Raven::Event.capture_message(message, :backtrace => backtrace) expect(evt[:stacktrace]).to be_a(Raven::StacktraceInterface) @@ -485,7 +431,7 @@ class SubExc < BaseExc; end config = Raven::Configuration.new config.excluded_exceptions << 'Raven::Test::BaseExc' expect(Raven::Event.capture_exception(Raven::Test::BaseExc.new, - :configuration => config)).to be_nil + :configuration => config)).to be_nil end it 'returns nil for a class match' do @@ -493,7 +439,7 @@ class SubExc < BaseExc; end config.excluded_exceptions << Raven::Test::BaseExc expect(Raven::Event.capture_exception(Raven::Test::SubExc.new, - :configuration => config)).to be_nil + :configuration => config)).to be_nil end end @@ -528,7 +474,7 @@ class SubExc < BaseExc; end context 'when running under jRuby' do let(:exception) do begin - raise java.lang.OutOfMemoryError.new("A Java error") + raise java.lang.OutOfMemoryError, "A Java error" rescue Exception => e return e end diff --git a/spec/raven/integrations/rack_spec.rb b/spec/raven/integrations/rack_spec.rb index ad932055b..914460b73 100644 --- a/spec/raven/integrations/rack_spec.rb +++ b/spec/raven/integrations/rack_spec.rb @@ -14,7 +14,7 @@ expect(Raven::Rack).to receive(:capture_exception).with(exception, env) - app = lambda { |_e| raise exception } + app = ->(_e) { raise exception } stack = Raven::Rack.new(app) expect { stack.call(env) }.to raise_error(ZeroDivisionError) @@ -55,7 +55,7 @@ it 'should clear context after app is called' do Raven::Context.current.tags[:environment] = :test - app = lambda { |env| ['response', {}, env] } + app = ->(env) { ['response', {}, env] } stack = Raven::Rack.new(app) stack.call({}) @@ -88,7 +88,7 @@ env = Rack::MockRequest.env_for("/test") app = proc do - [200, {'Content-Type' => 'text/plain'}, ['OK']] + [200, { 'Content-Type' => 'text/plain' }, ['OK']] end stack = Raven::Rack.new(Rack::Lint.new(app)) diff --git a/spec/raven/json_spec.rb b/spec/raven/json_spec.rb index a7a958eca..eee887a56 100644 --- a/spec/raven/json_spec.rb +++ b/spec/raven/json_spec.rb @@ -24,7 +24,7 @@ end it "works with a hash of #{obj.val.class}s" do - expect(JSON.dump('bar' => {obj.key => obj.val})).to eq "{\"bar\":{#{obj.enc_key}:#{obj.enc_val}}}" + expect(JSON.dump('bar' => { obj.key => obj.val })).to eq "{\"bar\":{#{obj.enc_key}:#{obj.enc_val}}}" end end @@ -42,7 +42,7 @@ end it 'it raises the correct error on strings that look like incomplete objects' do - expect{JSON.parse("{")}.to raise_error(JSON::ParserError) - expect{JSON.parse("[")}.to raise_error(JSON::ParserError) + expect { JSON.parse("{") }.to raise_error(JSON::ParserError) + expect { JSON.parse("[") }.to raise_error(JSON::ParserError) end end diff --git a/spec/raven/processors/removecirculareferences_spec.rb b/spec/raven/processors/removecirculareferences_spec.rb index bfba69597..dd7e60935 100644 --- a/spec/raven/processors/removecirculareferences_spec.rb +++ b/spec/raven/processors/removecirculareferences_spec.rb @@ -20,6 +20,6 @@ expect(result['data']).to eq('(...)') expect(result['ary'].first['x']).to eq('(...)') expect(result['ary2']).not_to eq('(...)') - expect(result['leave intact']).to eq({ 'not a circular reference' => true }) + expect(result['leave intact']).to eq('not a circular reference' => true) end end diff --git a/spec/raven/processors/sanitizedata_processor_spec.rb b/spec/raven/processors/sanitizedata_processor_spec.rb index 7f5841129..04803ec6c 100644 --- a/spec/raven/processors/sanitizedata_processor_spec.rb +++ b/spec/raven/processors/sanitizedata_processor_spec.rb @@ -65,8 +65,8 @@ 'social_security_number' => 123456789, 'user_field' => 'user', 'user_field_foo' => 'hello' - }.to_json - } + }.to_json + } result = JSON.parse(@processor.process(data_with_json)['json']) @@ -87,28 +87,28 @@ data_with_embedded_json = { 'data' => { 'json' => %w(foo bar).to_json, - 'json_hash' => {'foo' => 'bar'}.to_json, - 'sensitive' => {'password' => 'secret'}.to_json - } + 'json_hash' => { 'foo' => 'bar' }.to_json, + 'sensitive' => { 'password' => 'secret' }.to_json } + } result = @processor.process(data_with_embedded_json) expect(JSON.parse(result["data"]["json"])).to eq(%w(foo bar)) - expect(JSON.parse(result["data"]["json_hash"])).to eq({'foo' => 'bar'}) - expect(JSON.parse(result["data"]["sensitive"])).to eq({'password' => Raven::Processor::SanitizeData::STRING_MASK}) + expect(JSON.parse(result["data"]["json_hash"])).to eq('foo' => 'bar') + expect(JSON.parse(result["data"]["sensitive"])).to eq('password' => Raven::Processor::SanitizeData::STRING_MASK) end it 'should not fail when json is invalid' do data_with_invalid_json = { 'data' => { - 'invalid' => "{\r\n\"key\":\"value\",\r\n \"foo\":{\"bar\":\"baz\"}\r\n" - } + 'invalid' => "{\r\n\"key\":\"value\",\r\n \"foo\":{\"bar\":\"baz\"}\r\n" } + } result = @processor.process(data_with_invalid_json) - expect{JSON.parse(result["data"]["invalid"])}.to raise_exception(JSON::ParserError) + expect { JSON.parse(result["data"]["invalid"]) }.to raise_exception(JSON::ParserError) end it 'should filter credit card values' do @@ -116,7 +116,7 @@ 'ccnumba' => '4242424242424242', 'ccnumba_13' => '4242424242424', 'ccnumba-dash' => '4242-4242-4242-4242', - 'ccnumba_int' => 4242424242424242, + 'ccnumba_int' => 4242424242424242 } result = @processor.process(data) @@ -131,7 +131,7 @@ 'ccnumba' => '4242424242424242', 'ccnumba_13' => '4242424242424', 'ccnumba-dash' => '4242-4242-4242-4242', - 'ccnumba_int' => 4242424242424242, + 'ccnumba_int' => 4242424242424242 } result = @processor.process(data) @@ -142,8 +142,8 @@ it 'sanitizes hashes nested in arrays' do data = { - "empty_array"=> [], - "array"=>[{'password' => 'secret'}], + "empty_array" => [], + "array" => [{ 'password' => 'secret' }] } result = @processor.process(data) diff --git a/spec/raven/processors/utf8conversion_spec.rb b/spec/raven/processors/utf8conversion_spec.rb index 71c908827..3a5b25bad 100644 --- a/spec/raven/processors/utf8conversion_spec.rb +++ b/spec/raven/processors/utf8conversion_spec.rb @@ -39,7 +39,7 @@ end it 'should work recursively on hashes' do - data = {'nested' => {}} + data = { 'nested' => {} } data['nested']['invalid'] = "invalid utf8 string goes here\255".force_encoding('UTF-8') results = @processor.process(data) @@ -48,14 +48,14 @@ it 'should work recursively on arrays' do data = ['good string', 'good string', - ['good string', "invalid utf8 string goes here\255".force_encoding('UTF-8')]] + ['good string', "invalid utf8 string goes here\255".force_encoding('UTF-8')]] results = @processor.process(data) expect(results[2][1]).to eq("invalid utf8 string goes here") end it 'should not blow up on symbols' do - data = {:key => :value} + data = { :key => :value } results = @processor.process(data) expect(results[:key]).to eq(:value) diff --git a/spec/raven/raven_spec.rb b/spec/raven/raven_spec.rb index 09e069068..6176b7f8e 100644 --- a/spec/raven/raven_spec.rb +++ b/spec/raven/raven_spec.rb @@ -30,7 +30,7 @@ around do |example| prior_async = Raven.configuration.async - Raven.configuration.async = Proc.new { :ok } + Raven.configuration.async = proc { :ok } example.run Raven.configuration.async = prior_async end @@ -69,7 +69,7 @@ around do |example| prior_async = Raven.configuration.async - Raven.configuration.async = Proc.new { :ok } + Raven.configuration.async = proc { :ok } example.run Raven.configuration.async = prior_async end @@ -95,7 +95,7 @@ expect(Raven).not_to receive(:send_event).with(event) prior_should_capture = Raven.configuration.should_capture - Raven.configuration.should_capture = Proc.new { false } + Raven.configuration.should_capture = proc { false } expect(Raven.configuration.should_capture).to receive(:call).with(exception) expect(Raven.capture_exception(exception, options)).to be false Raven.configuration.should_capture = prior_should_capture @@ -206,7 +206,7 @@ def ivars(object) describe '.inject_only' do before do - allow(Gem.loaded_specs).to receive(:keys).and_return(%w[railties rack sidekiq]) + allow(Gem.loaded_specs).to receive(:keys).and_return(%w(railties rack sidekiq)) end it 'loads integrations when they are valid configurations' do diff --git a/spec/raven/transports/http_spec.rb b/spec/raven/transports/http_spec.rb index b58d0e484..03b4391c9 100644 --- a/spec/raven/transports/http_spec.rb +++ b/spec/raven/transports/http_spec.rb @@ -16,7 +16,7 @@ Raven.configure { |config| config.http_adapter = [:test, stubs] } event = JSON.generate(Raven::Event.from_message("test").to_hash) - expect{Raven.client.send(:transport).send_event("test", event)}.to raise_error(Faraday::ResourceNotFound) + expect { Raven.client.send(:transport).send_event("test", event) }.to raise_error(Faraday::ResourceNotFound) stubs.verify_stubbed_calls end @@ -28,7 +28,7 @@ Raven.configure { |config| config.http_adapter = [:test, stubs] } event = JSON.generate(Raven::Event.from_message("test").to_hash) - expect{Raven.client.send(:transport).send_event("test", event)}.to raise_error(Faraday::ClientError) + expect { Raven.client.send(:transport).send_event("test", event) }.to raise_error(Faraday::ClientError) stubs.verify_stubbed_calls end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6bf7c2a0e..278c310b7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -45,5 +45,5 @@ def build_exception_with_recursive_cause allow(exception).to receive(:cause).and_return(exception) allow(exception).to receive(:message).and_return("example") allow(exception).to receive(:backtrace).and_return(backtrace) - return exception + exception end