Skip to content

Commit

Permalink
Fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Apr 26, 2017
1 parent f5c37a8 commit 55494dd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AllCops:
Include:
- 'lib/**/*.rb'
- 'spec/**/*.rb'
- 'test/**/*.rb'
Exclude:
- 'examples/**/*'

Expand Down
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ Gem::PackageTask.new(gemspec).define

begin
require 'rspec/core/rake_task'

require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |task|
task.patterns = ['lib/**/*.rb','spec/**/*.rb',]
end

RuboCop::RakeTask.new(:rubocop)
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
end
Expand Down
19 changes: 19 additions & 0 deletions lib/raven/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,25 @@ def to_json_compatible
JSON.parse(JSON.generate(to_hash))
end

def self.capture_exception(message, opts = {})
Raven.logger.warn "DEPRECATION WARNING: Calling #capture_exception \
on Raven::Event will be removed in raven-ruby 4.0! Use Raven.capture_exception \
instead!"
Raven.capture_exception(message, opts)
end

def self.capture_message(message, opts = {})
Raven.logger.warn "DEPRECATION WARNING: Calling #capture_message \
on Raven::Event will be removed in raven-ruby 4.0! Use Raven.capture_message \
instead!"
Raven.capture_message(message, opts)
end

class << self
alias captureException capture_exception
alias captureMessage capture_message
end

private

# When behind a proxy (or if the user is using a proxy), we can't use
Expand Down
2 changes: 1 addition & 1 deletion test/interfaces/test_stacktrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class StacktraceInterfaceTest < Minitest::Spec
assert_equal " 1 / 0\n", @frame.context_line
assert_equal [" rescue ZeroDivisionError => exception\n"], @frame.post_context
end

it "converts to hash" do
assert @frame.to_hash.is_a?(Hash)
end
Expand Down
48 changes: 25 additions & 23 deletions test/test_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
require_relative 'helper'

module SentryExcludedModule; end
class SentryExcludedException < Exception; end
class SentryExcludedException < RuntimeError; end
class SentryExcludedViaSubclass < SentryExcludedException; end
class ExcludedViaExtend < Exception;
class ExcludedViaExtend < RuntimeError
extend SentryExcludedModule
end
class DontCaptureMeBro < Exception; end
class DontCaptureMeBro < RuntimeError; end

class ConfigurationTest < Minitest::Spec
@@config = Raven::Configuration.new

describe "is initialized with certain values" do
describe "hostname resolution" do
it "resolves a hostname via sys_command" do
Expand All @@ -35,47 +33,51 @@ class ConfigurationTest < Minitest::Spec

describe "setting the server" do
it "sets a bunch of attributes" do
@@config.server = "http://12345:67890@sentry.localdomain:3000/sentry/42"
@config = Raven::Configuration.new
@config.server = "http://12345:67890@sentry.localdomain:3000/sentry/42"

assert_equal "42", @@config.project_id
assert_equal "12345", @@config.public_key
assert_equal "67890", @@config.secret_key
assert_equal "http", @@config.scheme
assert_equal "sentry.localdomain", @@config.host
assert_equal 3000, @@config.port
assert_equal "/sentry", @@config.path
assert_equal "http://sentry.localdomain:3000/sentry", @@config.server
assert_equal "42", @config.project_id
assert_equal "12345", @config.public_key
assert_equal "67890", @config.secret_key
assert_equal "http", @config.scheme
assert_equal "sentry.localdomain", @config.host
assert_equal 3000, @config.port
assert_equal "/sentry", @config.path
assert_equal "http://sentry.localdomain:3000/sentry", @config.server
end
end

describe "setting the encoding" do
it "rejects unsupported options" do
assert_raises(ArgumentError) { @@config.encoding = "notarealencoding" }
@config = Raven::Configuration.new
assert_raises(ArgumentError) { @config.encoding = "notarealencoding" }
end
end

describe "setting configs which must be callable" do
it "rejects uncallable objects" do
@config = Raven::Configuration.new
%w(async transport_failure_callback should_capture).each do |m|
assert_raises(ArgumentError) { @@config.public_send("#{m}=", "not_callable") }
assert_raises(ArgumentError) { @config.public_send("#{m}=", "not_callable") }
end
end
end

it "allows hash-like access" do
assert @@config[:ssl_verification]
assert @@config["ssl_verification"]
@config = Raven::Configuration.new
assert @config[:ssl_verification]
assert @config["ssl_verification"]
end

it "converts current environment into a string" do
config = Raven::Configuration.new
config.current_environment = :staging
assert_equal "staging", config.current_environment
@config = Raven::Configuration.new
@config.current_environment = :staging
assert_equal "staging", @config.current_environment
end

describe "capture_allowed?" do
before do
@valid_config = Raven::Configuration.new(dsn: "http://12345:67890@sentry.localdomain:3000/sentry/42")
@valid_config = Raven::Configuration.new(:dsn => "http://12345:67890@sentry.localdomain:3000/sentry/42")
end

it "returns true if DSN is set" do
Expand Down Expand Up @@ -131,7 +133,7 @@ class ConfigurationTest < Minitest::Spec
end

it "checks if object is allowed by the should_capture callback" do
@valid_config.should_capture = lambda { |e| e == DontCaptureMeBro }
@valid_config.should_capture = ->(e) { e == DontCaptureMeBro }
refute @valid_config.capture_allowed?(DontCaptureMeBro.new)
assert_equal ["should_capture returned false"], @valid_config.errors
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InterfaceTest < Minitest::Spec
end

it "converts instance variables to a hash" do
int = TestInterface.new(foo: :bar)
int = TestInterface.new(:foo => :bar)
assert_equal({ :foo => :bar }, int.to_hash)
end
end

0 comments on commit 55494dd

Please sign in to comment.