Skip to content

Commit

Permalink
Update Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Mar 10, 2021
1 parent 6df068d commit 75383e8
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 113 deletions.
32 changes: 20 additions & 12 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
---
require:
- rubocop-performance
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.4
Exclude:
- 'bin/bundle'
- 'bin/rake'
- 'bin/rspec'
- 'bin/rubocop'
NewCops: enable
SuggestExtensions: false
TargetRubyVersion: 2.6

Metrics/BlockLength:
Exclude:
- '*.gemspec'
- 'spec/**/*_spec.rb'

Layout/LineLength:
Max: 80
IgnoredPatterns:
- '^\s*it\s+.*do$'
- '^\s*context\s+.*do$'
- '^\s*describe\s+.*do$'

Layout/DotPosition:
EnforcedStyle: trailing

Expand All @@ -15,14 +34,3 @@ Style/ClassAndModuleChildren:
Style/MixinUsage:
Exclude:
- 'spec/spec_helper.rb'

Lint/RaiseException:
Enabled: true
Lint/StructNewOverride:
Enabled: true
Style/HashEachMethods:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: true
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ gemspec
gem 'pry'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 0.81.0', require: false
gem 'rubocop', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rspec', require: false
gem 'webmock', '~> 3.3.0'
35 changes: 23 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GEM
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
ast (2.4.2)
coderay (1.1.3)
crack (0.4.3)
safe_yaml (~> 1.0.0)
Expand All @@ -21,22 +21,22 @@ GEM
http-accept (1.7.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
jaro_winkler (1.5.4)
json (2.5.1)
method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0225)
netrc (0.11.0)
parallel (1.19.1)
parser (2.7.1.3)
ast (~> 2.4.0)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
pry (0.14.0)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (3.0.2)
rainbow (3.0.0)
rake (13.0.1)
regexp_parser (2.1.1)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand All @@ -56,20 +56,29 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.81.0)
jaro_winkler (~> 1.5.1)
rubocop (1.11.0)
parallel (~> 1.10)
parser (>= 2.7.0.1)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
ruby-progressbar (1.10.1)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-performance (1.10.1)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rspec (2.2.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
safe_yaml (1.0.4)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
unicode-display_width (1.7.0)
unicode-display_width (2.0.0)
webmock (3.3.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand All @@ -83,5 +92,7 @@ DEPENDENCIES
pry
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 0.81.0)
rubocop
rubocop-performance
rubocop-rspec
webmock (~> 3.3.0)
58 changes: 36 additions & 22 deletions spec/infreemation/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,89 @@
expect { subject }.to raise_error(ResponseError)
end

context 'non-errors' do
context 'without errors' do
let(:response) { File.read('spec/fixtures/response_0.json') }

it 'does not raise an error' do
expect { subject }.to_not raise_error
expect { subject }.not_to raise_error
end
end

context 'authentication invalid errors' do
context 'with authentication invalid errors' do
let(:response) { File.read('spec/fixtures/error_2.json') }

specify { expect { subject }.to raise_error(AuthenticationError) }
end

context 'missing or invalid start date errors' do
context 'with missing or invalid start date errors' do
let(:response) { File.read('spec/fixtures/error_3.json') }

specify do
expect { subject }.to raise_error(MissingOrInvalidParameterError)
end
end

context 'invalid FOI type errors' do
context 'with invalid FOI type errors' do
let(:response) { File.read('spec/fixtures/error_4.json') }

specify { expect { subject }.to raise_error(InvalidParameterError) }
end

context 'missing requester errors' do
context 'with missing subject errors' do
let(:response) { File.read('spec/fixtures/error_5.json') }

specify { expect { subject }.to raise_error(MissingParameterError) }
end

context 'missing contact errors' do
context 'with missing contact errors' do
let(:response) { File.read('spec/fixtures/error_6.json') }

specify { expect { subject }.to raise_error(MissingParameterError) }
end

context 'missing contact type errors' do
context 'with missing contact type errors' do
let(:response) { File.read('spec/fixtures/error_7.json') }

specify { expect { subject }.to raise_error(MissingParameterError) }
end

context 'missing body errors' do
context 'with missing body errors' do
let(:response) { File.read('spec/fixtures/error_8.json') }

specify { expect { subject }.to raise_error(MissingParameterError) }
end

context 'missing rt errors' do
context 'with missing rt errors' do
let(:response) { File.read('spec/fixtures/error_9.json') }

specify { expect { subject }.to raise_error(MissingParameterError) }
end

context 'authentication missing key errors' do
context 'with authentication missing key errors' do
let(:response) { File.read('spec/fixtures/error_10.json') }

specify { expect { subject }.to raise_error(AuthenticationError) }
end

context 'authentication missing username errors' do
context 'with authentication missing username errors' do
let(:response) { File.read('spec/fixtures/error_11.json') }

specify { expect { subject }.to raise_error(AuthenticationError) }
end

context 'request errors' do
context 'with request errors' do
let(:response) { File.read('spec/fixtures/error_12.json') }

specify { expect { subject }.to raise_error(RequestError) }
end

context 'other generic errors' do
context 'with other generic errors' do
let(:response) { File.read('spec/fixtures/error_n.json') }

specify { expect { subject }.to raise_error(GenericError) }
end

context 'response errors' do
context 'with response errors' do
let(:response) { 'permission denied' }

it 'raises resonse error with response body' do
Expand All @@ -106,7 +118,7 @@
end
end

context 'long response errors' do
context 'with long response errors' do
let(:response) { 'x' * 101 }

it 'trims response body' do
Expand All @@ -118,34 +130,36 @@
end

describe '.get' do
subject(:request) { described_class.get('/foi', params) }

let(:params) { { rt: 'published' } }
let(:response) { '{ "foo": "bar" }' }
subject { API.get('/foi', params) }

include_examples 'errors'

it 'must not raise error' do
expect { subject }.to_not raise_error
expect { request }.not_to raise_error
end

it 'must parse response' do
expect(subject).to eq(foo: 'bar')
expect(request).to eq(foo: 'bar')
end
end

describe '.post' do
subject(:request) { described_class.post('/foi', params) }

let(:params) { { requester: 'Kirk' } }
let(:response) { '{ "baz": "qux" }' }
subject { API.post('/foi', params) }

include_examples 'errors'

it 'must not raise error' do
expect { subject }.to_not raise_error
expect { request }.not_to raise_error
end

it 'must parse response' do
expect(subject).to eq(baz: 'qux')
expect(request).to eq(baz: 'qux')
end
end
end

0 comments on commit 75383e8

Please sign in to comment.