Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/upgrade rubocop #36

Merged
merged 8 commits into from Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions .circleci/config.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
name: run tests
command: |
mkdir /tmp/test-results
bundle exec rubocop --format progress -r $(bundle info --path rubocop-junit-formatter)/lib/rubocop/formatter/junit_formatter.rb --format RuboCop::Formatter::JUnitFormatter --out /tmp/test-results/rubocop.xml
bundle exec rubocop --format progress --format junit --out /tmp/test-results/rubocop.xml
bundle exec rspec --format progress \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
Expand All @@ -32,10 +32,6 @@ jobs:
- store_artifacts:
path: /tmp/test-results
destination: test-results
ruby-23:
<<: *build
docker:
- image: circleci/ruby:2.3
ruby-24:
<<: *build
docker:
Expand All @@ -56,7 +52,6 @@ workflows:
version: 2
ruby-multi-build:
jobs:
- ruby-23
- ruby-24
- ruby-25
- ruby-26
Expand Down
153 changes: 145 additions & 8 deletions .rubocop.yml
@@ -1,12 +1,11 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.4

Metrics/LineLength:
Max: 120

Metrics/ClassLength:
Max: 300

Expand All @@ -29,7 +28,10 @@ Style/CollectionMethods:
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: no_comma

Style/TrailingCommaInLiteral:
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

Style/Documentation:
Expand All @@ -38,15 +40,15 @@ Style/Documentation:
Style/RedundantSelf:
Enabled: false

Layout/LineLength:
Max: 120

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Layout/IndentHash:
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Style/BracesAroundHashParameters:
Enabled: false

RSpec/NestedGroups:
Max: 5

Expand All @@ -65,3 +67,138 @@ RSpec/MessageSpies:
RSpec/AnyInstance:
Exclude:
- 'spec/scnnr/connection_spec.rb'

Layout/EmptyLinesAroundAttributeAccessor: # (new in 0.83)
Enabled: true

Layout/SpaceAroundMethodCallOperator: # (new in 0.82)
Enabled: true

Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
Enabled: true

Lint/DeprecatedOpenSSLConstant: # (new in 0.84)
Enabled: true

Lint/DuplicateElsifCondition: # (new in 0.88)
Enabled: true

Lint/DuplicateRequire: # (new in 0.90)
Enabled: true

Lint/DuplicateRescueException: # (new in 0.89)
Enabled: true

Lint/EmptyConditionalBody: # (new in 0.89)
Enabled: true

Lint/EmptyFile: # (new in 0.90)
Enabled: true

Lint/FloatComparison: # (new in 0.89)
Enabled: true

Lint/MissingSuper: # (new in 0.89)
Enabled: true

Lint/MixedRegexpCaptureTypes: # (new in 0.85)
Enabled: true

Lint/OutOfRangeRegexpRef: # (new in 0.89)
Enabled: true

Lint/RaiseException: # (new in 0.81)
Enabled: true

Lint/SelfAssignment: # (new in 0.89)
Enabled: true

Lint/StructNewOverride: # (new in 0.81)
Enabled: true

Lint/TopLevelReturnWithArgument: # (new in 0.89)
Enabled: true

Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
Enabled: true

Lint/UnreachableLoop: # (new in 0.89)
Enabled: true

Lint/UselessMethodDefinition: # (new in 0.90)
Enabled: true

Style/AccessorGrouping: # (new in 0.87)
Enabled: true

Style/ArrayCoercion: # (new in 0.88)
Enabled: true

Style/BisectedAttrAccessor: # (new in 0.87)
Enabled: true

Style/CaseLikeIf: # (new in 0.88)
Enabled: true

Style/CombinableLoops: # (new in 0.90)
Enabled: true

Style/ExplicitBlockArgument: # (new in 0.89)
Enabled: true

Style/ExponentialNotation: # (new in 0.82)
Enabled: true

Style/GlobalStdStream: # (new in 0.89)
Enabled: true

Style/HashAsLastArrayItem: # (new in 0.88)
Enabled: true

Style/HashEachMethods: # (new in 0.80)
Enabled: true

Style/HashLikeCase: # (new in 0.88)
Enabled: true

Style/HashTransformKeys: # (new in 0.80)
Enabled: true

Style/HashTransformValues: # (new in 0.80)
Enabled: true

Style/KeywordParametersOrder: # (new in 0.90)
Enabled: true

Style/OptionalBooleanParameter: # (new in 0.89)
Enabled: true

Style/RedundantAssignment: # (new in 0.87)
Enabled: true

Style/RedundantFetchBlock: # (new in 0.86)
Enabled: true

Style/RedundantFileExtensionInRequire: # (new in 0.88)
Enabled: true

Style/RedundantRegexpCharacterClass: # (new in 0.85)
Enabled: true

Style/RedundantRegexpEscape: # (new in 0.85)
Enabled: true

Style/RedundantSelfAssignment: # (new in 0.90)
Enabled: true

Style/SingleArgumentDig: # (new in 0.89)
Enabled: true

Style/SlicingWithRange: # (new in 0.83)
Enabled: true

Style/SoleNestedConditional: # (new in 0.89)
Enabled: true

Style/StringConcatenation: # (new in 0.89)
Enabled: true
28 changes: 28 additions & 0 deletions .rubocop_todo.yml
@@ -0,0 +1,28 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-09-07 08:04:46 UTC using RuboCop version 0.90.0.
# 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: 1
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'scnnr.gemspec'

# Offense count: 11
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/scnnr/connection_spec.rb'
- 'spec/scnnr/polling_manager_spec.rb'
- 'spec/scnnr/response_spec.rb'

# Offense count: 36
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 18
5 changes: 2 additions & 3 deletions Gemfile
Expand Up @@ -18,9 +18,8 @@ group :test do
gem 'rspec', '~> 3.5'
gem 'rspec_junit_formatter', '~> 0.3'

gem 'rubocop', '~> 0.49.0'
gem 'rubocop-junit-formatter', '~> 0.1'
gem 'rubocop-rspec', '~> 1.15.0'
gem 'rubocop', '~> 0.90.0'
gem 'rubocop-rspec', '~> 1.43.2'

gem 'webmock', '~> 3.0'
end
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@
- [API Documentation](https://api.scnnr.cubki.jp/v1/docs)

## Supported Ruby versions
- Ruby 2.3+
- Ruby 2.4+

## Installation

Expand Down
1 change: 1 addition & 0 deletions lib/scnnr/client.rb
Expand Up @@ -40,6 +40,7 @@ def recognize_url(url, options = {})
def fetch(recognition_id, options = {})
options = merge_options options
return request(recognition_id, options) if options.delete(:polling) == false

PollingManager.new(options.delete(:timeout)).polling(self, recognition_id, options)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/scnnr/configuration.rb
Expand Up @@ -4,7 +4,7 @@ module Scnnr
Configuration = Struct.new(:api_key, :api_version, :timeout, :logger) do
require 'logger'

DEFAULT_LOGGER = Logger.new(STDOUT, level: :info)
DEFAULT_LOGGER = Logger.new($stdout, level: :info)

def initialize
super(nil, 'v1', 0, DEFAULT_LOGGER)
Expand Down
1 change: 1 addition & 0 deletions lib/scnnr/response.rb
Expand Up @@ -6,6 +6,7 @@ class Response

def initialize(response)
raise UnexpectedError, response if response.content_type != SUPPORTED_CONTENT_TYPE

@response = response
end

Expand Down
5 changes: 3 additions & 2 deletions lib/scnnr/routing.rb
Expand Up @@ -26,16 +26,17 @@ def queries
end

def path
'/' + [self.path_prefix, @path]
"/#{[self.path_prefix, @path]
.map { |value| value.sub(%r{\A/}, '').sub(%r{/\z}, '') }
.join('/')
.join('/')}"
end

private

def query_string
params = self.queries
return if params.empty?

params
.map { |pair| pair.map { |val| URI.encode_www_form_component val }.join('=') }
.join('&')
Expand Down
3 changes: 1 addition & 2 deletions scnnr.gemspec
@@ -1,7 +1,6 @@
# coding: utf-8
# frozen_string_literal: true

lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'scnnr/version'

Expand Down
2 changes: 1 addition & 1 deletion spec/scnnr/client_spec.rb
Expand Up @@ -26,7 +26,7 @@

before do
allow(mock_origin_response).to receive(:body) { fixture('queued_recognition.json') }
allow(mock_origin_response).to receive(:content_type) { Scnnr::Response::SUPPORTED_CONTENT_TYPE }
allow(mock_origin_response).to receive(:content_type).and_return(Scnnr::Response::SUPPORTED_CONTENT_TYPE)
end

describe '#config' do
Expand Down
10 changes: 5 additions & 5 deletions spec/scnnr/connection_spec.rb
Expand Up @@ -19,7 +19,7 @@

context 'when the api_key is not set' do
it do
is_expected.to be_a Net::HTTPSuccess
expect(subject).to be_a Net::HTTPSuccess
expect(subject.body).to eq expected_body
expect(WebMock).to have_requested(method, uri)
end
Expand All @@ -30,7 +30,7 @@
let(:requested_options) { { headers: { 'x-api-key' => api_key } } }

it do
is_expected.to be_a Net::HTTPSuccess
expect(subject).to be_a Net::HTTPSuccess
expect(subject.body).to eq expected_body
expect(WebMock).to have_requested(method, uri).with(requested_options)
end
Expand All @@ -44,7 +44,7 @@
end

it do
is_expected.to be_a Net::HTTPSuccess
expect(subject).to be_a Net::HTTPSuccess
expect(subject.body).to eq expected_body
expect(WebMock).to have_requested(method, uri).with(requested_options)
end
Expand Down Expand Up @@ -96,7 +96,7 @@
it do
# can not test checking requested body_stream with WebMock, so instead.
expect_any_instance_of(Net::HTTP::Post).to receive(:body_stream=).with(image)
is_expected.to be_a Net::HTTPSuccess
expect(subject).to be_a Net::HTTPSuccess
expect(subject.body).to eq expected_body
expect(WebMock).to have_requested(method, uri).with(requested_options)
end
Expand All @@ -117,7 +117,7 @@
end

it do
is_expected.to be_a Net::HTTPSuccess
expect(subject).to be_a Net::HTTPSuccess
expect(subject.body).to eq expected_body
expect(WebMock).to have_requested(method, uri).with(requested_options)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/scnnr/polling_manager_spec.rb
Expand Up @@ -50,7 +50,7 @@
it 'times out with the queued recognition' do
expect(client).to receive(:fetch).with(
queued_recognition.id, hash_including(polling: false, timeout: Scnnr::PollingManager::MAX_TIMEOUT)
).exactly(2).times.and_return(queued_recognition)
).twice.and_return(queued_recognition)

expect { subject }.to raise_error(Scnnr::TimeoutError) do |e|
expect(e.recognition).to eq queued_recognition
Expand Down Expand Up @@ -99,7 +99,7 @@
it do
expect(client).to(receive(:fetch).with(recognition_id, hash_including(timeout: anything, polling: false))
.once { recognition })
expect { subject }.to change { manager.timeout }
expect { subject }.to change(manager, :timeout)
.from(timeout).to([timeout - Scnnr::PollingManager::MAX_TIMEOUT, 0].max)
expect(subject).to eq recognition
end
Expand All @@ -111,7 +111,7 @@
it do
expect(client).to(receive(:fetch).with(recognition_id, hash_including(timeout: anything, polling: false))
.once { recognition })
expect { subject }.to change { manager.timeout }
expect { subject }.to change(manager, :timeout)
.from(timeout).to([timeout - Scnnr::PollingManager::MAX_TIMEOUT, 0].max)
expect(subject).to eq recognition
end
Expand Down