Skip to content

Commit

Permalink
Fixed rubocop warnings + Fixed rubocop version
Browse files Browse the repository at this point in the history
  • Loading branch information
pierresouchay committed Sep 6, 2018
1 parent d6b2975 commit a1416a7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Metrics/LineLength:
# Allow classes longer than 100 lines of code
ClassLength:
Max: 250

Naming/UncommunicativeMethodParamName:
Enabled: false

Lint/UnneededCopDisableDirective:
Enabled: false
2 changes: 1 addition & 1 deletion diplomat.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new 'diplomat', Diplomat::VERSION do |spec|
spec.add_development_dependency 'pry', '~> 0.9'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rspec', '~> 3.2'
spec.add_development_dependency 'rubocop', '~> 0.47', '>= 0.47.1'
spec.add_development_dependency 'rubocop', '~> 0.49'

spec.add_runtime_dependency 'faraday', '~> 0.9'
spec.add_runtime_dependency 'json' if RUBY_VERSION < '1.9.3'
Expand Down
4 changes: 2 additions & 2 deletions lib/diplomat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def require_libs(*libs)

raise 'Diplomat only supports ruby >= 2.0.0' unless RUBY_VERSION.to_f >= 2.0

self.root_path = File.expand_path '..', __FILE__
self.lib_path = File.expand_path '../diplomat', __FILE__
self.root_path = File.expand_path __dir__
self.lib_path = File.expand_path 'diplomat', __dir__

require_libs 'configuration', 'rest_client', 'api_options', 'kv', 'datacenter',
'service', 'members', 'node', 'nodes', 'check', 'health', 'session', 'lock',
Expand Down
2 changes: 1 addition & 1 deletion lib/diplomat/kv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def decode_transaction(transaction) # rubocop:disable Metrics/MethodLength
next unless resp['KV']['Value']
begin
resp['KV']['Value'] = Base64.decode64(resp['KV']['Value'])
rescue # rubocop:disable RescueWithoutErrorClass
rescue StandardError
nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/diplomat/rest_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def decode_values
@raw.each_with_object([]) do |acc, el|
begin
acc['Value'] = Base64.decode64(acc['Value'])
rescue # rubocop:disable RescueWithoutErrorClass
rescue StandardError
nil
end
el << acc
Expand Down
1 change: 0 additions & 1 deletion lib/diplomat/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,5 @@ def maintenance(service_id, options = { enable: true })
end
maintenance.status == 200
end
# rubocop:enable AbcSize
end
end
23 changes: 14 additions & 9 deletions spec/agent_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'spec_helper'
require 'json'
require 'base64'

# rubocop:disable
describe Diplomat::Agent do
let(:faraday) { fake }

context 'agent' do
it 'self' do
faraday.stub(:get).and_return(OpenStruct.new(body: <<-JSON))
faraday.stub(:get)
.and_return(OpenStruct.new(body: <<-JSON))
{
"Config": {
"Bootstrap": true,
Expand Down Expand Up @@ -73,15 +74,16 @@
"DelegateCur": 4
}
}
JSON
JSON

agent = Diplomat::Agent.new(faraday)

expect(agent.self['Config']['NodeName']).to eq('foobar')
end

it 'checks' do
faraday.stub(:get).and_return(OpenStruct.new(body: <<-JSON))
faraday.stub(:get)
.and_return(OpenStruct.new(body: <<-JSON))
{
"service:redis": {
"Node": "foobar",
Expand All @@ -94,15 +96,16 @@
"ServiceName": "redis"
}
}
JSON
JSON

agent = Diplomat::Agent.new(faraday)

expect(agent.checks['service:redis']['Status']).to eq('passing')
end

it 'services' do
faraday.stub(:get).and_return(OpenStruct.new(body: <<-JSON))
faraday.stub(:get)
.and_return(OpenStruct.new(body: <<-JSON))
{
"redis": {
"ID": "redis",
Expand All @@ -112,15 +115,16 @@
"Port": 8000
}
}
JSON
JSON

agent = Diplomat::Agent.new(faraday)

expect(agent.services['redis']['Port']).to eq(8000)
end

it 'members' do
faraday.stub(:get).and_return(OpenStruct.new(body: <<-JSON))
faraday.stub(:get)
.and_return(OpenStruct.new(body: <<-JSON))
[
{
"Name": "foobar",
Expand All @@ -141,7 +145,7 @@
"DelegateCur": 3
}
]
JSON
JSON

agent = Diplomat::Agent.new(faraday)

Expand All @@ -150,3 +154,4 @@
end
end
end
# rubocop:enable

0 comments on commit a1416a7

Please sign in to comment.