Skip to content

Commit 84955cc

Browse files
committed
Fix linting errros
1 parent 8dd793f commit 84955cc

28 files changed

+170
-108
lines changed

.rubocop.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
AllCops:
2+
TargetRubyVersion: 2.3
3+
Include:
4+
- Rakefile
5+
Exclude:
6+
- Gemfile
7+
8+
Style/SymbolArray:
9+
EnforcedStyle: brackets
110
Style/LineLength:
211
Max: 180
312
Style/ClassAndModuleChildren:
413
EnforcedStyle: compact
514
Style/FileName:
615
Exclude:
716
- '**/mockserver-client.rb'
17+
- 'mockserver-client.gemspec'

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
# frozen_string_literal: true
12
# encoding: UTF-8
3+
24
require 'bundler/gem_tasks'
35
require 'rubocop/rake_task'
46
require 'rspec/core/rake_task'

lib/cli.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
24
require 'thor'
35
require 'colorize'
46
require_relative './mockserver-client'
@@ -88,7 +90,7 @@ class MockServerCLI < Thor
8890
def retrieve
8991
execute_command do |client, _|
9092
result = options.data ? client.retrieve(read_file(options.data)) : client.retrieve
91-
puts "RESULT:\n".bold + "#{result.to_json}".green
93+
puts "RESULT:\n".bold + result.to_json.green
9294
end
9395
end
9496

lib/mockserver-client.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
24
require_relative './mockserver/version'
35
require_relative './mockserver/mock_server_client'
46
require_relative './mockserver/proxy_client'
@@ -7,6 +9,7 @@
79
require 'json/pure'
810

911
# To fix serialization bugs. See: http://prettystatemachine.blogspot.com/2010/09/typeerrors-in-tojson-make-me-briefly.html
12+
# rubocop:disable Lint/UnifiedInteger
1013
class Fixnum
1114
def to_json(_)
1215
to_s

lib/mockserver/abstract_client.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
24
require 'rest-client'
35
require 'logging_factory'
46
require_relative './model/times'
@@ -24,8 +26,8 @@ class AbstractClient
2426
attr_accessor :logger
2527

2628
def initialize(host, port)
27-
fail 'Cannot instantiate AbstractClient class. You must subclass it.' if self.class == AbstractClient
28-
fail 'Host/port must not be nil' unless host && port
29+
raise 'Cannot instantiate AbstractClient class. You must subclass it.' if self.class == AbstractClient
30+
raise 'Host/port must not be nil' unless host && port
2931
protocol = ('https' if port == 443) || 'http'
3032
@base = RestClient::Resource.new("#{protocol}://#{host}:#{port}", headers: { 'Content-Type' => 'application/json' })
3133
@logger = ::LoggingFactory::DEFAULT_FACTORY.log(self.class)
@@ -34,7 +36,7 @@ def initialize(host, port)
3436
# Clear all expectations with the given request
3537
# @param request [Request] the request to use to clear an expectation
3638
# @return [Object] the response from the clear action
37-
def clear(request)
39+
def clear(request) # rubocop:disable Metrics/AbcSize
3840
request = camelized_hash(HTTP_REQUEST => Request.new(symbolize_keys(request)))
3941

4042
logger.debug("Clearing expectation with request: #{request}")
@@ -61,7 +63,7 @@ def reset
6163
# Retrieve the list of requests that have been processed by the server
6264
# @param request [Request] to filter requests
6365
# @return [Object] the list of responses processed by the server
64-
def retrieve(request = nil)
66+
def retrieve(request = nil) # rubocop:disable Metrics/AbcSize
6567
request = request ? camelized_hash(HTTP_REQUEST => Request.new(symbolize_keys(request))) : {}
6668

6769
logger.debug('Retrieving request list from mockserver')
@@ -95,7 +97,7 @@ def dump_log(request = nil, java = false)
9597
# @param request [Request] to filter requests
9698
# @param times [Times] expected number of times
9799
# @return [Object] the list of responses processed by the server that match the request
98-
def verify(request, times = exactly(1))
100+
def verify(request, times = exactly(1)) # rubocop:disable Metrics/AbcSize
99101
logger.debug('Sending query for verify to mockserver')
100102
results = retrieve(request)
101103

@@ -105,7 +107,7 @@ def verify(request, times = exactly(1))
105107
is_exact = !times.unlimited
106108

107109
fulfilled = is_exact ? (num_times == results.size) : (num_times <= results.size)
108-
fail "Expected request to be present: [#{num_times}] (#{is_exact ? 'exactly' : 'at least'}). But found: [#{results.size}]" unless fulfilled
110+
raise "Expected request to be present: [#{num_times}] (#{is_exact ? 'exactly' : 'at least'}). But found: [#{results.size}]" unless fulfilled
109111
results
110112
end
111113
end

lib/mockserver/mock_server_client.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
24
require_relative './model/expectation'
35
require_relative './abstract_client'
46
require_relative './utility_methods'
@@ -18,8 +20,8 @@ class MockServerClient < AbstractClient
1820
# Registers an expectation with the mockserver
1921
# @param expectation [Expectation] the expectation to create the request from
2022
# @return [Object] the response from the register action
21-
def register(expectation)
22-
fail 'Expectation passed in is not valid type' unless expectation.is_a?(Expectation)
23+
def register(expectation) # rubocop:disable Metrics/AbcSize
24+
raise 'Expectation passed in is not valid type' unless expectation.is_a?(Expectation)
2325
request = create_expectation_request(expectation)
2426

2527
logger.debug('Registering new expectation')
@@ -35,11 +37,10 @@ def register(expectation)
3537
# Create an expecation request to send to the expectation endpoint of
3638
# @param expectation [Expectation] the expectation to create the request from
3739
# @return [Hash] a hash representing the request to use in registering an expectation with the mock server
38-
# rubocop:disable Lint/LiteralInInterpolation
3940
def create_expectation_request(expectation)
4041
expectation_request = camelized_hash(expectation)
4142
logger.debug("Expectation JSON: #{expectation_request.to_json}")
42-
fail "You can only set either of #{[HTTP_RESPONSE, HTTP_FORWARD]}. But not both" if expectation_request[HTTP_RESPONSE] && expectation_request[HTTP_FORWARD]
43+
raise "You can only set either of #{[HTTP_RESPONSE, HTTP_FORWARD]}. But not both" if expectation_request[HTTP_RESPONSE] && expectation_request[HTTP_FORWARD]
4344
expectation_request
4445
end
4546
end

lib/mockserver/model/array_of.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
# frozen_string_literal: true
12
# encoding: UTF-8
3+
24
#
35
# The ArrayOf class stores instances of a given class only.
46
# It enforces this by intercepting the methods :<<, :[]= and :insert on the Array class
@@ -15,9 +17,9 @@ module MockServer::Model
1517

1618
# The ArrayOf class stores instances of a given class only.
1719
class ArrayOf < Array
18-
alias_method :add_element, :<<
19-
alias_method :set_element, :[]=
20-
alias_method :insert_element, :insert
20+
alias add_element <<
21+
alias set_element []=
22+
alias insert_element insert
2123

2224
# Create an array from the elements passed in
2325
def initialize(items)
@@ -28,7 +30,7 @@ def initialize(items)
2830

2931
# The class/type that this array stores
3032
def child_class
31-
fail 'Subclass should override method :child_class'
33+
raise 'Subclass should override method :child_class'
3234
end
3335

3436
# Add the item to the array
@@ -75,7 +77,7 @@ def convert_to_child_class(item)
7577
if item && item.class != child_class
7678
begin
7779
item = child_class.new(item)
78-
rescue Exception => e # rubocop:disable Lint/RescueException
80+
rescue StandardError => e
7981
raise "Failed to convert element: #{item} to required type #{child_class}. Error: #{e.message}"
8082
end
8183
end

lib/mockserver/model/body.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
24
require 'hashie'
35
require_relative './parameter'
46
require_relative './enum'
@@ -11,16 +13,7 @@ module MockServer::Model
1113
# An enum for body type
1214
class BodyType < SymbolizedEnum
1315
def allowed_values
14-
[
15-
:STRING,
16-
:REGEX,
17-
:XPATH,
18-
:PARAMETERS,
19-
:BINARY,
20-
:JSON,
21-
:JSON_SCHEMA,
22-
:XML_SCHEMA
23-
]
16+
[:STRING, :REGEX, :XPATH, :PARAMETERS, :BINARY, :JSON, :JSON_SCHEMA, :XML_SCHEMA]
2417
end
2518
end
2619

lib/mockserver/model/cookie.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
24
require 'hashie'
35
require_relative './array_of'
46

lib/mockserver/model/delay.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# encoding: UTF-8
2+
# frozen_string_literal: true
3+
24
require_relative './enum'
35

46
#

0 commit comments

Comments
 (0)