Skip to content

Commit

Permalink
rubocop: fix various rubocop offences
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo committed Apr 6, 2017
1 parent 605e625 commit d6a68c6
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ Metrics/BlockLength:

Performance/RegexpMatch:
Enabled: false

Style/IndentHeredoc:
Enabled: false
1 change: 1 addition & 0 deletions benchmarks/payload_truncator_string_encoding.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8

require_relative 'benchmark_helpers'

require 'securerandom'
Expand Down
2 changes: 1 addition & 1 deletion lib/airbrake-ruby/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module Filters
##
# @return [Array<Symbol>] parts of a Notice's payload that can be modified
# by various filters
FILTERABLE_KEYS = [:environment, :session, :params].freeze
FILTERABLE_KEYS = %i[environment session params].freeze
end
end
12 changes: 6 additions & 6 deletions lib/airbrake-ruby/notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class Notice

# @return [Array<Symbol>] the list of keys that can be be overwritten with
# {Airbrake::Notice#[]=}
WRITABLE_KEYS = [
:notifier,
:context,
:environment,
:session,
:params
WRITABLE_KEYS = %i[
notifier
context
environment
session
params
].freeze

##
Expand Down
2 changes: 1 addition & 1 deletion spec/airbrake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
notifiers = described_class.instance_variable_get(:@notifiers)

expect(notifiers).to be_a(Hash)
expect(notifiers.keys).to eq([:default, :bingo])
expect(notifiers.keys).to eq(%i[default bingo])
expect(notifiers.values).to all(satisfy { |v| v.is_a?(Airbrake::Notifier) })
end

Expand Down
44 changes: 23 additions & 21 deletions spec/config/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
end

it "sets correct error message" do
expect { subject.valid_project_id? }.
to change { subject.error_message }.
to(/:project_id is required/)
expect { subject.valid_project_id? }.to(
change { subject.error_message }.to(/:project_id is required/)
)
end
end

Expand All @@ -28,8 +28,9 @@

it "sets correct error message" do
expect { subject.valid_project_id? }.
to change { subject.error_message }.
to(/:project_id is required/)
to(
change { subject.error_message }.to(/:project_id is required/)
)
end
end

Expand All @@ -41,9 +42,9 @@
end

it "sets correct error message" do
expect { subject.valid_project_id? }.
to change { subject.error_message }.
to(/:project_id is required/)
expect { subject.valid_project_id? }.to(
change { subject.error_message }.to(/:project_id is required/)
)
end
end

Expand All @@ -55,7 +56,7 @@
end

it "doesn't set the error message" do
expect { subject.valid_project_id? }.not_to change { subject.error_message }
expect { subject.valid_project_id? }.not_to(change { subject.error_message })
end
end
end
Expand All @@ -68,7 +69,7 @@
end

it "doesn't set the error message" do
expect { subject.valid_project_id? }.not_to change { subject.error_message }
expect { subject.valid_project_id? }.not_to(change { subject.error_message })
end
end
end
Expand Down Expand Up @@ -97,7 +98,7 @@
end

it "doesn't set the error message" do
expect { subject.valid_project_key? }.not_to change { subject.error_message }
expect { subject.valid_project_key? }.not_to(change { subject.error_message })
end
end
end
Expand All @@ -110,9 +111,9 @@
end

it "sets correct error message" do
expect { subject.valid_project_key? }.
to change { subject.error_message }.
to(/:project_key is required/)
expect { subject.valid_project_key? }.to(
change { subject.error_message }.to(/:project_key is required/)
)
end
end
end
Expand All @@ -126,7 +127,7 @@
end

it "doesn't set the error message" do
expect { subject.valid_environment? }.not_to change { subject.error_message }
expect { subject.valid_environment? }.not_to(change { subject.error_message })
end
end

Expand All @@ -139,9 +140,10 @@
end

it "sets the error message" do
expect { subject.valid_environment? }.
to change { subject.error_message }.
to(/the 'environment' option must be configured with a Symbol/)
expect { subject.valid_environment? }.to(
change { subject.error_message }.
to(/the 'environment' option must be configured with a Symbol/)
)
end
end

Expand All @@ -153,7 +155,7 @@
end

it "doesn't set the error message" do
expect { subject.valid_environment? }.not_to change { subject.error_message }
expect { subject.valid_environment? }.not_to(change { subject.error_message })
end
end

Expand All @@ -165,7 +167,7 @@
end

it "doesn't set the error message" do
expect { subject.valid_environment? }.not_to change { subject.error_message }
expect { subject.valid_environment? }.not_to(change { subject.error_message })
end
end

Expand All @@ -181,7 +183,7 @@
end

it "doesn't set the error message" do
expect { subject.valid_environment? }.not_to change { subject.error_message }
expect { subject.valid_environment? }.not_to(change { subject.error_message })
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
context "and when 'ignore_environments' contains Strings" do
it "returns true" do
config.environment = :bango
config.ignore_environments = %w(bango)
config.ignore_environments = %w[bango]

expect(config.ignored_environment?).to be_truthy
end
Expand Down
4 changes: 2 additions & 2 deletions spec/filter_chain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@

expect(notice[:errors].first[:file]).to be_nil
expect { @chain.refine(notice) }.
not_to change { notice[:errors].first[:file] }
not_to(change { notice[:errors].first[:file] })
end
end

Expand All @@ -200,7 +200,7 @@

expect(notice[:errors].first[:file]).to be_nil
expect { filter_chain.refine(notice) }.
not_to change { notice[:errors].first[:file] }
not_to(change { notice[:errors].first[:file] })
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/notifier_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8

require 'spec_helper'

RSpec.describe Airbrake::Notifier do
Expand Down Expand Up @@ -405,7 +406,7 @@ def to_json(*)
notifier.close
end

it "respawns workers on fork()", skip: %w(jruby rbx).include?(RUBY_ENGINE) do
it "respawns workers on fork()", skip: %w[jruby rbx].include?(RUBY_ENGINE) do
out = StringIO.new
notifier = described_class.new(airbrake_params.merge(logger: Logger.new(out)))

Expand Down Expand Up @@ -445,7 +446,7 @@ def to_json(*)
end

it "accepts multiple filters" do
[:bingo, :bongo, :bash].each do |key|
%i[bingo bongo bash].each do |key|
@airbrake.add_filter do |notice|
notice[:params][key] = '[Filtered]'.freeze if notice[:params][key]
end
Expand Down
4 changes: 2 additions & 2 deletions spec/notifier_spec/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def expect_a_request_with_body(body)
context "when the current env and notify envs are the same" do
params = {
environment: :development,
ignore_environments: [:production, :development]
ignore_environments: %i[production development]
}

include_examples 'ignored notice', params
Expand All @@ -217,7 +217,7 @@ def expect_a_request_with_body(body)
end

context "when the current env is not set and notify envs are present" do
params = { ignore_environments: [:production, :development] }
params = { ignore_environments: %i[production development] }

include_examples 'sent notice', params
end
Expand Down
6 changes: 3 additions & 3 deletions spec/notifier_spec/whitelist_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def expect_a_request_with_body(body)

include_examples(
'whitelisting',
%w(bongo bish),
%w[bongo bish],
bingo: 'bango', bongo: { bish: 'bash' }
)
end

context "and it is a recursive hash" do
it "errors when nested hashes are not filtered" do
whitelist = airbrake_params.merge(whitelist_keys: %w(bingo bango))
whitelist = airbrake_params.merge(whitelist_keys: %w[bingo bango])
notifier = Airbrake::Notifier.new(whitelist)

bongo = { bingo: {} }
Expand Down Expand Up @@ -196,7 +196,7 @@ def expect_a_request_with_body(body)

describe "context/url" do
let(:notifier) do
Airbrake::Notifier.new(airbrake_params.merge(whitelist_keys: %w(bish)))
Airbrake::Notifier.new(airbrake_params.merge(whitelist_keys: %w[bish]))
end

context "given a standard URL" do
Expand Down
5 changes: 3 additions & 2 deletions spec/payload_truncator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8

require 'spec_helper'

RSpec.describe Airbrake::PayloadTruncator do
Expand Down Expand Up @@ -216,13 +217,13 @@

context "of short strings" do
let(:params) do
{ bingo: %w(foo bar baz), bango: 'bongo', bish: 'bash' }
{ bingo: %w[foo bar baz], bango: 'bongo', bish: 'bash' }
end

it "truncates long strings in the array, but not short ones" do
@truncator.truncate_object(params)
expect(params).
to eq(bingo: %w(foo bar baz), bango: 'bongo', bish: 'bash')
to eq(bingo: %w[foo bar baz], bango: 'bongo', bish: 'bash')
end
end

Expand Down

0 comments on commit d6a68c6

Please sign in to comment.