From ed625b7863c772e6a263bd4fbb25f560758deb80 Mon Sep 17 00:00:00 2001 From: Kirill Drozdov Date: Sun, 31 Jul 2022 00:03:20 +0200 Subject: [PATCH] Bumped up ruby version to 3 --- .rubocop.yml | 14 +++- .ruby-version | 2 +- .travis.yml | 2 +- Gemfile.lock | 69 ++++++++++--------- lib/luna_park/entities/nested.rb | 4 +- lib/luna_park/errors/base.rb | 6 +- lib/luna_park/errors/http.rb | 2 +- lib/luna_park/extensions/data_mapper.rb | 4 +- lib/luna_park/extensions/dsl/attributes.rb | 4 +- lib/luna_park/extensions/dsl/foreign_key.rb | 4 +- lib/luna_park/extensions/has_errors.rb | 8 +-- lib/luna_park/extensions/injector.rb | 2 + .../extensions/repositories/postgres/read.rb | 8 +-- .../extensions/typed_attr_accessor.rb | 2 +- lib/luna_park/extensions/validatable/dry.rb | 4 +- lib/luna_park/forms/simple.rb | 3 +- lib/luna_park/forms/single_item.rb | 3 +- lib/luna_park/http/client.rb | 24 +++---- lib/luna_park/http/request.rb | 28 ++++---- lib/luna_park/http/response.rb | 10 +-- lib/luna_park/http/send.rb | 2 +- lib/luna_park/mappers/codirectional.rb | 14 ++-- lib/luna_park/notifiers/log.rb | 4 +- lib/luna_park/notifiers/log/formatters.rb | 7 +- lib/luna_park/validators/dry.rb | 4 +- lib/luna_park/values/attributable.rb | 2 +- luna_park.gemspec | 7 +- spec/luna_park/entities/nested_spec.rb | 16 ++--- spec/luna_park/entities/simple_spec.rb | 4 +- spec/luna_park/errors/base_spec.rb | 2 +- spec/luna_park/errors/http_spec.rb | 10 +-- spec/luna_park/extensions/comparable_spec.rb | 4 +- .../extensions/injector/dependencies_spec.rb | 2 +- spec/luna_park/extensions/injector_spec.rb | 41 +++++------ .../repositories/postgres/read_spec.rb | 12 ++-- .../luna_park/extensions/serializable_spec.rb | 4 +- .../extensions/severity_levels_spec.rb | 16 +++-- spec/luna_park/http/client_spec.rb | 6 +- spec/luna_park/http/request_spec.rb | 8 +-- spec/luna_park/http/response_spec.rb | 10 +-- spec/luna_park/http/send_spec.rb | 20 +++--- spec/luna_park/mappers/codirectional_spec.rb | 12 ++-- spec/luna_park/notifiers/bugsnag_spec.rb | 7 +- .../notifiers/log/formatters_spec.rb | 2 +- spec/luna_park/notifiers/log_spec.rb | 46 ++++++------- spec/luna_park/notifiers/sentry_spec.rb | 4 +- spec/luna_park/use_cases/scenario_spec.rb | 12 ++-- spec/luna_park/values/single_spec.rb | 4 +- 48 files changed, 252 insertions(+), 233 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 10d5ce98..dcffebe8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,17 +7,19 @@ inherit_mode: - Exclude AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 3.1 Exclude: - '**/tmp/**/*' - '**/script/**/*' - Rakefile - 'bin/*' UseCache: true + SuggestExtensions: false + NewCops: enable Metrics/LineLength: Max: 120 - IgnoredPatterns: ['\s*\#\s.*$'] + AllowedPatterns: ['\s*\#\s.*$'] Exclude: - 'spec/**/*' @@ -71,6 +73,9 @@ Lint/RaiseException: Lint/StructNewOverride: Enabled: true +Lint/EmptyClass: + Enabled: false + # TODO: поговорить с Филиппом про attr Style/AccessorGrouping: Enabled: false @@ -104,3 +109,8 @@ Style/RedundantRegexpEscape: Style/SlicingWithRange: Enabled: true + +Style/OpenStructUse: + Exclude: + - 'spec/**/*' + diff --git a/.ruby-version b/.ruby-version index 73462a5a..ef538c28 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.5.1 +3.1.2 diff --git a/.travis.yml b/.travis.yml index 4d78cad7..a0c9b204 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,5 @@ language: ruby cache: bundler rvm: - - 2.5.1 + - 3.2.1 before_install: gem install bundler -v 1.17.1 diff --git a/Gemfile.lock b/Gemfile.lock index ab1de439..966d107b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GEM specs: addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) - ast (2.4.1) + ast (2.4.2) bugsnag (6.13.1) concurrent-ruby (~> 1.0) byebug (11.1.3) @@ -22,8 +22,8 @@ GEM concurrent-ruby (1.1.6) crack (0.4.3) safe_yaml (~> 1.0.0) - diff-lcs (1.4.4) - docile (1.3.2) + diff-lcs (1.5.0) + docile (1.4.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) dry-configurable (0.11.6) @@ -86,8 +86,8 @@ GEM overcommit (0.55.0) childprocess (>= 0.6.3, < 5) iniparse (~> 1.4) - parallel (1.19.2) - parser (2.7.1.4) + parallel (1.22.1) + parser (3.1.3.0) ast (~> 2.4.1) pry (0.13.1) coderay (~> 1.1) @@ -96,40 +96,41 @@ GEM byebug (~> 11.0) pry (~> 0.13.0) public_suffix (4.0.6) - rainbow (3.0.0) + rainbow (3.1.1) rake (13.0.1) - regexp_parser (1.7.1) + regexp_parser (2.6.1) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) rexml (3.2.5) - rspec (3.9.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-core (3.9.2) - rspec-support (~> 3.9.3) - rspec-expectations (3.9.2) + rspec (3.11.0) + rspec-core (~> 3.11.0) + rspec-expectations (~> 3.11.0) + rspec-mocks (~> 3.11.0) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-mocks (3.9.1) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.3) - rubocop (0.87.1) + rspec-support (~> 3.11.0) + rspec-support (3.11.0) + rubocop (1.39.0) + json (~> 2.3) parallel (~> 1.10) - parser (>= 2.7.1.1) + parser (>= 3.1.2.1) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) - rexml - rubocop-ast (>= 0.1.0, < 1.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.23.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (0.1.0) - parser (>= 2.7.0.1) - ruby-progressbar (1.10.1) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.24.0) + parser (>= 3.1.1.0) + ruby-progressbar (1.11.0) ruby2_keywords (0.0.4) safe_yaml (1.0.5) sentry-ruby (4.2.1) @@ -139,15 +140,17 @@ GEM sentry-ruby-core (4.2.1) concurrent-ruby faraday - simplecov (0.18.5) + simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) - simplecov-html (0.12.2) - timecop (0.9.1) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + timecop (0.9.5) unf (0.1.4) unf_ext unf_ext (0.0.7.7) - unicode-display_width (1.7.0) + unicode-display_width (2.3.0) webmock (3.7.6) addressable (>= 2.3.6) crack (>= 0.3.2) @@ -171,7 +174,7 @@ DEPENDENCIES rake (~> 13.0) rest-client (~> 2.1) rspec (~> 3.0) - rubocop (~> 0.87) + rubocop (~> 1.39) sentry-ruby (~> 4.2) simplecov (~> 0.18) timecop (~> 0.9) @@ -179,4 +182,4 @@ DEPENDENCIES yard (~> 0.9) BUNDLED WITH - 2.2.30 + 2.3.26 diff --git a/lib/luna_park/entities/nested.rb b/lib/luna_park/entities/nested.rb index 8255a70f..3b827350 100644 --- a/lib/luna_park/entities/nested.rb +++ b/lib/luna_park/entities/nested.rb @@ -6,13 +6,13 @@ module LunaPark module Entities # add description class Nested < Attributable - def self.namespace(name, &block) # rubocop:disable Metrics/MethodLength + def self.namespace(name, &) # rubocop:disable Metrics/MethodLength serializable_attributes(name) comparable_attributes(name) namespace_class = Class.new(Nested) namespace_class.define_singleton_method(:name) { "Namespace:#{name}" } - namespace_class.class_eval(&block) + namespace_class.class_eval(&) anonym_mixin = Module.new do attr_reader(name) diff --git a/lib/luna_park/errors/base.rb b/lib/luna_park/errors/base.rb index f82acf9e..fb3aea19 100644 --- a/lib/luna_park/errors/base.rb +++ b/lib/luna_park/errors/base.rb @@ -77,9 +77,9 @@ def message(txt = nil, i18n_key: nil, i18n: nil, &default_message_block) def inherited(inheritor) if __default_message_block__ - inheritor.message(i18n_key: i18n_key, &__default_message_block__) + inheritor.message(i18n_key:, &__default_message_block__) elsif i18n_key - inheritor.message(i18n_key: i18n_key) + inheritor.message(i18n_key:) end inheritor.default_notify = default_notify @@ -232,7 +232,7 @@ def localized_message(locale = nil, show_error:) return unless self.class.i18n_key return unless show_error || I18n.exists?(self.class.i18n_key) - I18n.t(self.class.i18n_key, locale: locale, **details) + I18n.t(self.class.i18n_key, locale:, **details) end # @return [String] - Default message diff --git a/lib/luna_park/errors/http.rb b/lib/luna_park/errors/http.rb index 91d635e7..403f1d6a 100644 --- a/lib/luna_park/errors/http.rb +++ b/lib/luna_park/errors/http.rb @@ -32,7 +32,7 @@ def initialize(msg = nil, response:, notify: nil, **details) raise ArgumentError, 'Response should be Http::Response' unless response.is_a? LunaPark::Http::Response @response = response - super msg, notify: notify, **details + super msg, notify:, **details end # Return request which call this is error. diff --git a/lib/luna_park/extensions/data_mapper.rb b/lib/luna_park/extensions/data_mapper.rb index 2178e8c8..2b5a9972 100644 --- a/lib/luna_park/extensions/data_mapper.rb +++ b/lib/luna_park/extensions/data_mapper.rb @@ -66,8 +66,8 @@ def db_primary_key end module InstanceMethods - def transaction(&block) - dataset.transaction(&block) + def transaction(&) + dataset.transaction(&) end private diff --git a/lib/luna_park/extensions/dsl/attributes.rb b/lib/luna_park/extensions/dsl/attributes.rb index 544cda51..c43cf805 100644 --- a/lib/luna_park/extensions/dsl/attributes.rb +++ b/lib/luna_park/extensions/dsl/attributes.rb @@ -89,7 +89,7 @@ def attr?(*args, **options) # attrs name1, name2, name3, Type, :type_method, **attr_options # # @return [Array of Hash(Symbol => Symbol)] Hash of defined methods - def attrs(*args, **options) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity + def attrs(*args, **options) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity *names, type, type_meth = if args.all? { |arg| arg.is_a?(Symbol) } [*args, nil, nil] elsif args[0..-2].all? { |arg| arg.is_a?(Symbol) } @@ -98,7 +98,7 @@ def attrs(*args, **options) # rubocop:disable Metrics/MethodLength, Metrics/Cycl args else raise ArgumentError, 'must be (*names) | ' \ - '(*names, type) | (*names, type, type_meth)' + '(*names, type) | (*names, type, type_meth)' end names.map { |name| attr name, type, type_meth, **options } diff --git a/lib/luna_park/extensions/dsl/foreign_key.rb b/lib/luna_park/extensions/dsl/foreign_key.rb index 4ac5e0e6..7d94a0b3 100644 --- a/lib/luna_park/extensions/dsl/foreign_key.rb +++ b/lib/luna_park/extensions/dsl/foreign_key.rb @@ -86,8 +86,8 @@ module InstanceMethods private def extract_pk_value_from_object__(object, pk_name) - object.respond_to?(:[]) && object[pk_name] || - object.respond_to?(pk_name) && object.public_send(pk_name) || + (object.respond_to?(:[]) && object[pk_name]) || + (object.respond_to?(pk_name) && object.public_send(pk_name)) || nil end end diff --git a/lib/luna_park/extensions/has_errors.rb b/lib/luna_park/extensions/has_errors.rb index e0652267..ad04afcc 100644 --- a/lib/luna_park/extensions/has_errors.rb +++ b/lib/luna_park/extensions/has_errors.rb @@ -71,8 +71,8 @@ module ClassMethods # logic_error = Service::LogicError.new # logic_error.is_a? LunaPark::Errors::Business # => true # logic_error.message # => '2' - def business_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block) # rubocop:disable Metrics/ParameterLists - custom_error title, Errors::Business, txt, i18n: i18n || i18n_key, notify: notify, &default_message_block + def business_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block) + custom_error title, Errors::Business, txt, i18n: i18n || i18n_key, notify:, &default_message_block end ## @@ -92,8 +92,8 @@ def business_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &def # tech_error = Service::TechError.new # tech_error.is_a? LunaPark::Errors::System # => true # tech_error.message # => 'Error message' - def system_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block) # rubocop:disable Metrics/ParameterLists - custom_error title, Errors::System, txt, i18n: i18n || i18n_key, notify: notify, &default_message_block + def system_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block) + custom_error title, Errors::System, txt, i18n: i18n || i18n_key, notify:, &default_message_block end ## diff --git a/lib/luna_park/extensions/injector.rb b/lib/luna_park/extensions/injector.rb index 0d5b2200..a129ddd6 100644 --- a/lib/luna_park/extensions/injector.rb +++ b/lib/luna_park/extensions/injector.rb @@ -112,6 +112,8 @@ def inherited(inheritor) dependencies.each_pair do |key, block| inheritor.dependency(key, &block) end + + super end ## diff --git a/lib/luna_park/extensions/repositories/postgres/read.rb b/lib/luna_park/extensions/repositories/postgres/read.rb index beb13151..a4369009 100644 --- a/lib/luna_park/extensions/repositories/postgres/read.rb +++ b/lib/luna_park/extensions/repositories/postgres/read.rb @@ -7,12 +7,12 @@ module Postgres module Read def find!(pk_value, for_update: false) ds = dataset.where(primary_key => pk_value) - read_one!(ds, for_update: for_update, not_found_meta: pk_value) + read_one!(ds, for_update:, not_found_meta: pk_value) end def find(pk_value, for_update: false) ds = dataset.where(primary_key => pk_value) - read_one(ds, for_update: for_update) + read_one(ds, for_update:) end def lock!(pk_value) @@ -37,8 +37,8 @@ def last private - def read_one!(dataset, for_update: false, not_found_meta:) - read_one(dataset, for_update: for_update).tap do |entity| + def read_one!(dataset, not_found_meta:, for_update: false) + read_one(dataset, for_update:).tap do |entity| raise Errors::NotFound, "#{short_class_name} (#{not_found_meta})" if entity.nil? end end diff --git a/lib/luna_park/extensions/typed_attr_accessor.rb b/lib/luna_park/extensions/typed_attr_accessor.rb index 891de224..24717cd5 100644 --- a/lib/luna_park/extensions/typed_attr_accessor.rb +++ b/lib/luna_park/extensions/typed_attr_accessor.rb @@ -5,7 +5,7 @@ module Extensions module TypedAttrAccessor def typed_attr_accessor(*names, callable, is_array: false) attr_reader(*names) - typed_attr_writer(*names, callable, is_array: is_array) + typed_attr_writer(*names, callable, is_array:) end def typed_attr_writer(*names, callable, is_array: false) diff --git a/lib/luna_park/extensions/validatable/dry.rb b/lib/luna_park/extensions/validatable/dry.rb index bde42158..543e63e6 100644 --- a/lib/luna_park/extensions/validatable/dry.rb +++ b/lib/luna_park/extensions/validatable/dry.rb @@ -11,11 +11,11 @@ def self.included(base) base.extend self end - def validator(klass = nil, &block) + def validator(klass = nil, &) return super unless block_given? klass = Class.new(Validators::Dry) - klass.validation_schema(&block) + klass.validation_schema(&) super(klass) end end diff --git a/lib/luna_park/forms/simple.rb b/lib/luna_park/forms/simple.rb index 145bd9d6..4a79f20a 100644 --- a/lib/luna_park/forms/simple.rb +++ b/lib/luna_park/forms/simple.rb @@ -51,7 +51,8 @@ def submit if valid? perform! true - else false + else + false end end diff --git a/lib/luna_park/forms/single_item.rb b/lib/luna_park/forms/single_item.rb index 251f2194..e3313e79 100644 --- a/lib/luna_park/forms/single_item.rb +++ b/lib/luna_park/forms/single_item.rb @@ -44,7 +44,8 @@ def submit fill! perform! true - else false + else + false end end diff --git a/lib/luna_park/http/client.rb b/lib/luna_park/http/client.rb index 6a7dc559..e2bc13b8 100644 --- a/lib/luna_park/http/client.rb +++ b/lib/luna_park/http/client.rb @@ -122,11 +122,11 @@ def form_request(title:, url:, method: nil, body: nil, headers: nil, data: nil, form_body = body || data # * we have no a good generator for `x-www-form-urlencoded` type, but Driver has build_request( - title: title, - url: url, - method: method, + title:, + url:, + method:, body: form_body, - headers: headers, + headers:, content_type: 'application/x-www-form-urlencoded', **opts ) @@ -158,14 +158,14 @@ def form_request(title:, url:, method: nil, body: nil, headers: nil, data: nil, # @return [LunaPark::Http::Request] # rubocop:disable Metrics/ParameterLists def json_request(title:, url:, method: nil, body: nil, data: nil, headers: nil, **opts) - json_body = body || data && JSON.generate(data) + json_body = body || (data && JSON.generate(data)) build_request( - title: title, - url: url, - method: method, + title:, + url:, + method:, body: json_body, - headers: headers, + headers:, content_type: 'application/json', **opts ) @@ -274,11 +274,11 @@ def build_request(title:, url:, method: nil, body: nil, headers: nil, content_ty # rubocop:disable Layout/HashAlignment Request.new( - title: title, + title:, url: url.to_s, # TODO: Use {LunaPark::Tools::URI} with @query method: method || DEFAULT_METHOD, - body: body, - headers: headers, + body:, + headers:, open_timeout: open_timeout || self.class.open_timeout, read_timeout: read_timeout || self.class.read_timeout, driver: driver || self.class.driver diff --git a/lib/luna_park/http/request.rb b/lib/luna_park/http/request.rb index ad7aaf70..a99e252b 100644 --- a/lib/luna_park/http/request.rb +++ b/lib/luna_park/http/request.rb @@ -96,7 +96,7 @@ def method(name = nil) # @param open_timeout (see #open_timeout) # @param driver is HTTP driver which use to send this request # rubocop:disable Metrics/ParameterLists, Layout/LineLength - def initialize(title:, method: nil, url: nil, body: nil, headers: nil, open_timeout: nil, read_timeout: nil, driver:) + def initialize(title:, driver:, method: nil, url: nil, body: nil, headers: nil, open_timeout: nil, read_timeout: nil) @title = title @method = method @url = url @@ -191,12 +191,12 @@ def driver # # @url=\"http://localhost:8080/get_200\" @method=\"get\" # # @headers=\"{}\" @body=\"\" @sent_at=\"\">" def inspect - "<#{self.class.name} " \ - "@title=#{title.inspect} " \ - "@url=#{url.inspect} " \ - "@method=#{method.inspect} " \ + "<#{self.class.name} " \ + "@title=#{title.inspect} " \ + "@url=#{url.inspect} " \ + "@method=#{method.inspect} " \ "@headers=#{headers.inspect} " \ - "@body=#{body.inspect} " \ + "@body=#{body.inspect} " \ "@sent_at=#{sent_at.inspect}>" end @@ -210,14 +210,14 @@ def inspect # :open_timeout=>10} def to_h { - title: title, - method: method, - url: url, - body: body, - headers: headers, - read_timeout: read_timeout, - open_timeout: open_timeout, - sent_at: sent_at + title:, + method:, + url:, + body:, + headers:, + read_timeout:, + open_timeout:, + sent_at: } end end diff --git a/lib/luna_park/http/response.rb b/lib/luna_park/http/response.rb index abf29e06..7fd96372 100644 --- a/lib/luna_park/http/response.rb +++ b/lib/luna_park/http/response.rb @@ -338,7 +338,7 @@ def json_parse!(payload_key: nil, stringify_keys: false) # # @return [Hash, String, nil] def json_parse(payload_key: nil, stringify_keys: false) - json_parse!(payload_key: payload_key, stringify_keys: stringify_keys) + json_parse!(payload_key:, stringify_keys:) rescue Errors::JsonParse nil end @@ -361,10 +361,10 @@ def json_parse(payload_key: nil, stringify_keys: false) # @return [Hash] def to_h { - code: code, - body: body, - headers: headers, - cookies: cookies, + code:, + body:, + headers:, + cookies:, request: request.to_h } end diff --git a/lib/luna_park/http/send.rb b/lib/luna_park/http/send.rb index 6856e130..045e4554 100644 --- a/lib/luna_park/http/send.rb +++ b/lib/luna_park/http/send.rb @@ -62,7 +62,7 @@ def call # @return [LunaPark::Http::Response] def call! call.tap do |response| - raise Errors::Http.new(response.status, response: response) unless response.success? + raise Errors::Http.new(response.status, response:) unless response.success? end end diff --git a/lib/luna_park/mappers/codirectional.rb b/lib/luna_park/mappers/codirectional.rb index 1c86790b..6643c461 100644 --- a/lib/luna_park/mappers/codirectional.rb +++ b/lib/luna_park/mappers/codirectional.rb @@ -63,7 +63,7 @@ def attr(attr, row: nil) if attr_path == row_path attrs(attr_path) else - nested_copyists << Copyists::Nested.new(attrs_path: attr_path, row_path: row_path) + nested_copyists << Copyists::Nested.new(attrs_path: attr_path, row_path:) end end @@ -85,16 +85,16 @@ def attrs(*common_keys) def from_row(input) row = input.to_h {}.tap do |attrs| - slice_copyist.from_row(row: row, attrs: attrs) - nested_copyists.each { |copyist| copyist.from_row(row: row, attrs: attrs) } + slice_copyist.from_row(row:, attrs:) + nested_copyists.each { |copyist| copyist.from_row(row:, attrs:) } end end def to_row(input) attrs = input.to_h {}.tap do |row| - slice_copyist.to_row(row: row, attrs: attrs) - nested_copyists.each { |copyist| copyist.to_row(row: row, attrs: attrs) } + slice_copyist.to_row(row:, attrs:) + nested_copyists.each { |copyist| copyist.to_row(row:, attrs:) } end end @@ -109,9 +109,9 @@ def to_path(input, full: input) when Symbol then input when String then input.to_sym when Array - return to_path(input.first, full: full) if input.size <= 1 + return to_path(input.first, full:) if input.size <= 1 - input.flat_map { |elem| to_path(elem, full: full) } + input.flat_map { |elem| to_path(elem, full:) } else raise ArgumentError, "Unexpected path part `#{input.inspect}` in `#{full.inspect}`. " \ 'Expected Symbol, String or Array' end diff --git a/lib/luna_park/notifiers/log.rb b/lib/luna_park/notifiers/log.rb index cf520af2..c78f6288 100644 --- a/lib/luna_park/notifiers/log.rb +++ b/lib/luna_park/notifiers/log.rb @@ -80,7 +80,7 @@ def initialize(logger: nil, format: nil, formatter: nil, min_lvl: :debug) # @param [Hash] details - Any another details for current message def post(msg, lvl: :error, **details) severity = severity(lvl) - message = serialize(msg, details) + message = serialize(msg, **details) logger.add severity, message end @@ -90,7 +90,7 @@ def logger(val) end def default_logger - @default_logger ||= Logger.new(STDOUT) + @default_logger ||= Logger.new($stdout) end end diff --git a/lib/luna_park/notifiers/log/formatters.rb b/lib/luna_park/notifiers/log/formatters.rb index 68d4a9f3..af97d3d6 100644 --- a/lib/luna_park/notifiers/log/formatters.rb +++ b/lib/luna_park/notifiers/log/formatters.rb @@ -1,6 +1,5 @@ # frozen_string_literal: false -require 'pp' require 'json' module LunaPark @@ -32,7 +31,7 @@ module Formatters # # :duck=>"quack", # # :horse=>"yell"}} MULTILINE = lambda do |klass, message, details = {}| - PP.pp({ class: klass, message: message, details: details }, '') + PP.pp({ class: klass, message:, details: }, '') end # - JSON - this format should be good choose for logger which be processed by external logger system @@ -42,7 +41,7 @@ module Formatters # # I, [2022-09-29T12:00:47.600052 #90508] INFO -- : {"class":"String", "message":"You hear", # # "details":{"dog":"wow","cats":{"chloe":"mow","timmy":"mow"}}} JSON = lambda do |klass, message, details = {}| - ::JSON.generate(class: klass, message: message, details: details) + ::JSON.generate(class: klass, message:, details:) end # - PRETTY_JSON - pretty json output @@ -62,7 +61,7 @@ module Formatters # # "horse": "yell" # # } PRETTY_JSON = lambda do |klass, message, details = {}| - ::JSON.pretty_generate(class: klass, message: message, details: details) + ::JSON.pretty_generate(class: klass, message:, details:) end end end diff --git a/lib/luna_park/validators/dry.rb b/lib/luna_park/validators/dry.rb index 8138a5a8..af032239 100644 --- a/lib/luna_park/validators/dry.rb +++ b/lib/luna_park/validators/dry.rb @@ -48,7 +48,7 @@ def schema alias validate new - def validation_schema(&block) + def validation_schema(&) unless defined?(::Dry::Validation) raise NameError, "uninitialized constant ::Dry::Validation\n" \ 'Perhaps you forgot to add gem "dry-validation"' @@ -59,7 +59,7 @@ def validation_schema(&block) 'which appears in version 1.0 of gem "dry-validation"' end - @_schema = Class.new(::Dry::Validation::Contract, &block).new + @_schema = Class.new(::Dry::Validation::Contract, &).new end end end diff --git a/lib/luna_park/values/attributable.rb b/lib/luna_park/values/attributable.rb index 125403b9..f0d3f462 100644 --- a/lib/luna_park/values/attributable.rb +++ b/lib/luna_park/values/attributable.rb @@ -14,7 +14,7 @@ class Attributable < Compound # redefine: make defined setters privat def self.attr(*args, **opts) - super.tap { |result| protected(result[:setter]) } # rubocop:disable Style/AccessModifierDeclarations + super.tap { |result| protected(result[:setter]) } end end end diff --git a/luna_park.gemspec b/luna_park.gemspec index 9e91fd0d..ba620265 100644 --- a/luna_park.gemspec +++ b/luna_park.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| spec.summary = 'Domain driven oriented microservice framework.' spec.homepage = 'https://github.com/am-team/luna_park' spec.license = 'MIT' - spec.required_ruby_version = '>= 2.5.1' + spec.required_ruby_version = '>= 3.1.2' # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' # to allow pushing to a single host or delete this section to allow pushing to any host. @@ -21,7 +21,7 @@ Gem::Specification.new do |spec| # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'" else raise 'RubyGems 2.0 or newer is required to protect against ' \ - 'public gem pushes.' + 'public gem pushes.' end spec.metadata['yard.run'] = 'yri' @@ -46,10 +46,11 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rest-client', '~> 2.1' spec.add_development_dependency 'rspec', '~> 3.0' - spec.add_development_dependency 'rubocop', '~> 0.87' + spec.add_development_dependency 'rubocop', '~> 1.39' spec.add_development_dependency 'sentry-ruby', '~> 4.2' spec.add_development_dependency 'simplecov', '~> 0.18' spec.add_development_dependency 'timecop', '~> 0.9' spec.add_development_dependency 'webmock', '~> 3.7.0' spec.add_development_dependency 'yard', '~> 0.9' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/spec/luna_park/entities/nested_spec.rb b/spec/luna_park/entities/nested_spec.rb index ab1283a7..07d60372 100644 --- a/spec/luna_park/entities/nested_spec.rb +++ b/spec/luna_park/entities/nested_spec.rb @@ -168,14 +168,14 @@ module LunaPark it 'returns expected string' do is_expected.to eq '# ' \ - 'ears=# ' \ - 'legs=# ' \ - 'trunk_length=2.1> alive=true ' \ - 'weapon=# height=4.2 ' \ - 'number_of_crushed_enemies=2328 ' \ - 'last_battle_time=#>' + 'head=# ' \ + 'ears=# ' \ + 'legs=# ' \ + 'trunk_length=2.1> alive=true ' \ + 'weapon=# height=4.2 ' \ + 'number_of_crushed_enemies=2328 ' \ + 'last_battle_time=#>' end end end diff --git a/spec/luna_park/entities/simple_spec.rb b/spec/luna_park/entities/simple_spec.rb index 11894f29..1e75e7ca 100644 --- a/spec/luna_park/entities/simple_spec.rb +++ b/spec/luna_park/entities/simple_spec.rb @@ -18,13 +18,13 @@ module LunaPark let(:object_abstract) { Entities::Simple.new } - let(:attributes) { { email: email, password: password } } + let(:attributes) { { email:, password: } } let(:email) { 'john.doe@email.com' } let(:password) { 'qwerty' } describe '.new' do context 'when all attributes are passed through initializer' do - let(:attributes) { { email: email, password: password } } + let(:attributes) { { email:, password: } } it { is_expected.to be_an_instance_of EntitiesSimpleCpec::User } diff --git a/spec/luna_park/errors/base_spec.rb b/spec/luna_park/errors/base_spec.rb index 09c03634..1f853f5c 100644 --- a/spec/luna_park/errors/base_spec.rb +++ b/spec/luna_park/errors/base_spec.rb @@ -284,7 +284,7 @@ module LunaPark end it 'builds expected message' do - expect(error_class.new({ foo: 'Foo' }).message).to eq 'Dynamic message Foo' + expect(error_class.new(**{ foo: 'Foo' }).message).to eq 'Dynamic message Foo' end end diff --git a/spec/luna_park/errors/http_spec.rb b/spec/luna_park/errors/http_spec.rb index 385e03b5..5f95c47d 100644 --- a/spec/luna_park/errors/http_spec.rb +++ b/spec/luna_park/errors/http_spec.rb @@ -17,7 +17,7 @@ module LunaPark describe '#response' do let(:response) { double } - let(:error) { described_class.new response: response } + let(:error) { described_class.new response: } subject { error.response } before do @@ -31,8 +31,8 @@ module LunaPark describe '#request' do let(:request) { double } - let(:response) { double request: request } - let(:error) { described_class.new response: response } + let(:response) { double request: } + let(:error) { described_class.new response: } subject { error.request } @@ -63,11 +63,11 @@ module LunaPark code: 200, headers: { 'Content-Type' => 'application/json' }, cookies: { 'Secret' => 'dkmvc9saudj3cndsaosp' }, - request: request + request: ) end - let(:error) { described_class.new 'Custom message', response: response, something: 'important' } + let(:error) { described_class.new 'Custom message', response:, something: 'important' } subject { error.details } diff --git a/spec/luna_park/extensions/comparable_spec.rb b/spec/luna_park/extensions/comparable_spec.rb index 6f3ea8de..24094159 100644 --- a/spec/luna_park/extensions/comparable_spec.rb +++ b/spec/luna_park/extensions/comparable_spec.rb @@ -54,13 +54,13 @@ module LunaPark end context 'when comparable_attributes is not registered' do - # rubocop:disable Style/ClassAndModuleChildren, Style/StructInheritance + # rubocop:disable Lint/ConstantDefinitionInBlock, Style/ClassAndModuleChildren, Style/StructInheritance let(:klass) do class ExtensionsComparableSpec::ClassName < Struct.new(:title, :author, :weight) include LunaPark::Extensions::Comparable end end - # rubocop:enable Style/ClassAndModuleChildren, Style/StructInheritance + # rubocop:enable Lint/ConstantDefinitionInBlock, Style/ClassAndModuleChildren, Style/StructInheritance it 'raises meaningfull exception' do expect { eq }.to raise_error Errors::NotConfigured, diff --git a/spec/luna_park/extensions/injector/dependencies_spec.rb b/spec/luna_park/extensions/injector/dependencies_spec.rb index 7f9fb8a8..baed3933 100644 --- a/spec/luna_park/extensions/injector/dependencies_spec.rb +++ b/spec/luna_park/extensions/injector/dependencies_spec.rb @@ -52,7 +52,7 @@ module LunaPark describe '#[]=' do let(:result) { double } - let(:dependencies) { described_class.try_convert(foo: -> { nil }) } + let(:dependencies) { described_class.try_convert(foo: -> {}) } let(:run_dependency) { dependencies.call_with_cache(:foo) } it 'should reset memorization' do diff --git a/spec/luna_park/extensions/injector_spec.rb b/spec/luna_park/extensions/injector_spec.rb index 4c8eaa8f..b5142bcf 100644 --- a/spec/luna_park/extensions/injector_spec.rb +++ b/spec/luna_park/extensions/injector_spec.rb @@ -3,35 +3,36 @@ require 'luna_park/extensions/injector' require 'luna_park/errors' -class Fuel; end -class Oil; end - -class Engine - include LunaPark::Extensions::Injector - - dependency(:fuel) { Fuel.new } - dependency(:oil) { Oil.new } -end - module LunaPark RSpec.describe Extensions::Injector do - let(:engine) { Engine.new } + let!(:fuel_class) { stub_const('Fuel', Class.new) } + let!(:oil_class) { stub_const('Oil', Class.new) } + + let(:engine_class) do + Class.new do + include LunaPark::Extensions::Injector + + dependency(:fuel) { Fuel.new } + dependency(:oil) { Oil.new } + end + end + let(:engine) { engine_class.new } describe '.dependency' do it 'sets dependency' do - expect { Engine.dependency(:foo) { 'Foo' } }.to change { Engine.dependencies[:foo] }.from(nil).to Proc + expect { engine_class.dependency(:foo) { 'Foo' } }.to change { engine_class.dependencies[:foo] }.from(nil).to Proc end context 'when no block given' do it 'raises ArgumentError' do - expect { Engine.dependency(:foo) }.to raise_error ArgumentError, 'no block given' + expect { engine_class.dependency(:foo) }.to raise_error ArgumentError, 'no block given' end end end describe '.dependencies' do context 'on defined class' do - subject(:dependencies) { Engine.dependencies } + subject(:dependencies) { engine_class.dependencies } it { is_expected.to be_an_instance_of Hash } @@ -42,8 +43,8 @@ module LunaPark end context 'on child class' do - class Rotor < Engine; end - subject(:dependencies) { Rotor.dependencies } + let(:rotor_class) { Class.new(engine_class) } + subject(:dependencies) { rotor_class.dependencies } it { is_expected.to be_an_instance_of Hash } @@ -53,8 +54,8 @@ class Rotor < Engine; end end it 'Instance shoulde respond to dependencies method' do - expect(Rotor.new).to respond_to :fuel - expect(Rotor.new).to respond_to :oil + expect(rotor_class.new).to respond_to :fuel + expect(rotor_class.new).to respond_to :oil end end end @@ -70,7 +71,7 @@ class Rotor < Engine; end end describe '.dependencies' do - subject(:dependencies) { Engine.dependencies } + subject(:dependencies) { engine_class.dependencies } it { is_expected.to be_an_instance_of Hash } @@ -85,7 +86,7 @@ class Rotor < Engine; end context 'when dependencies is not defined in the instance' do it 'should be eq dependencies defined in class' do - is_expected.to eq Engine.dependencies + is_expected.to eq engine_class.dependencies end end diff --git a/spec/luna_park/extensions/repositories/postgres/read_spec.rb b/spec/luna_park/extensions/repositories/postgres/read_spec.rb index 61b55317..6c65780c 100644 --- a/spec/luna_park/extensions/repositories/postgres/read_spec.rb +++ b/spec/luna_park/extensions/repositories/postgres/read_spec.rb @@ -44,15 +44,15 @@ def self.name let(:uid) { 42 } context 'when exist' do - let(:fake_row) { { uid: uid, foo: 'FOO' } } + let(:fake_row) { { uid:, foo: 'FOO' } } - before { allow(fake_dataset).to receive(:where).with(uid: uid).and_return([fake_row]) } + before { allow(fake_dataset).to receive(:where).with(uid:).and_return([fake_row]) } it { is_expected.to eq fake_entity_klass.new(fake_row) } end context 'when not exist' do - before { allow(fake_dataset).to receive(:where).with(uid: uid).and_return([]) } + before { allow(fake_dataset).to receive(:where).with(uid:).and_return([]) } it { is_expected.to be_nil } end @@ -63,15 +63,15 @@ def self.name let(:uid) { 42 } context 'when exist' do - let(:fake_row) { { uid: uid, foo: 'FOO' } } + let(:fake_row) { { uid:, foo: 'FOO' } } - before { allow(fake_dataset).to receive(:where).with(uid: uid).and_return([fake_row]) } + before { allow(fake_dataset).to receive(:where).with(uid:).and_return([fake_row]) } it { is_expected.to eq fake_entity_klass.new(fake_row) } end context 'when not exist' do - before { allow(fake_dataset).to receive(:where).with(uid: uid).and_return([]) } + before { allow(fake_dataset).to receive(:where).with(uid:).and_return([]) } it { expect { find! }.to raise_error LunaPark::Errors::NotFound, 'FakeEntity (42)' } end diff --git a/spec/luna_park/extensions/serializable_spec.rb b/spec/luna_park/extensions/serializable_spec.rb index 40404e28..c07541b3 100644 --- a/spec/luna_park/extensions/serializable_spec.rb +++ b/spec/luna_park/extensions/serializable_spec.rb @@ -88,13 +88,13 @@ module LunaPark end context 'when serializable_attributes is not registered' do - # rubocop:disable Style/ClassAndModuleChildren, Style/StructInheritance + # rubocop:disable Lint/ConstantDefinitionInBlock, Style/ClassAndModuleChildren, Style/StructInheritance let(:klass) do class ExtensionsSerializableSpec::ClassName < Struct.new(:title, :author, :weight) include LunaPark::Extensions::Serializable end end - # rubocop:enable Style/ClassAndModuleChildren, Style/StructInheritance + # rubocop:enable Lint/ConstantDefinitionInBlock, Style/ClassAndModuleChildren, Style/StructInheritance it 'raises meaningfull exception' do expect { to_h }.to raise_error Errors::NotConfigured, diff --git a/spec/luna_park/extensions/severity_levels_spec.rb b/spec/luna_park/extensions/severity_levels_spec.rb index 3146eeed..40e168a5 100644 --- a/spec/luna_park/extensions/severity_levels_spec.rb +++ b/spec/luna_park/extensions/severity_levels_spec.rb @@ -4,15 +4,17 @@ module LunaPark RSpec.describe Extensions::SeverityLevels do - class FakeNotifier - include Extensions::SeverityLevels + let(:fake_notifier) do + Class.new do + include Extensions::SeverityLevels - def post(msg = '', lvl:, **details) - { msg: msg, lvl: lvl, details: details } + def post(msg = '', lvl:, **details) + { msg:, lvl:, details: } + end end end - let(:notifier) { FakeNotifier.new } + let(:notifier) { fake_notifier.new } describe '#min_lvl' do subject { notifier.min_lvl } @@ -47,14 +49,14 @@ def post(msg = '', lvl:, **details) subject { notifier.send(lvl, 'Message text', foo: 1) } it 'should send expected message' do - is_expected.to eq(msg: 'Message text', lvl: lvl, details: { foo: 1 }) + is_expected.to eq(msg: 'Message text', lvl:, details: { foo: 1 }) end end context 'when message is block' do subject { notifier.send(lvl, foo: 1) { 'Message text' } } it 'should send expected message' do - is_expected.to eq(msg: 'Message text', lvl: lvl, details: { foo: 1 }) + is_expected.to eq(msg: 'Message text', lvl:, details: { foo: 1 }) end it 'should change run code in block' do diff --git a/spec/luna_park/http/client_spec.rb b/spec/luna_park/http/client_spec.rb index 548e0e9a..3fb8a5e4 100644 --- a/spec/luna_park/http/client_spec.rb +++ b/spec/luna_park/http/client_spec.rb @@ -49,7 +49,7 @@ module LunaPark shared_examples 'send request' do |request_type| let(:response) { double } let(:driver) { double(call: response, call!: response) } - let(:request) { Http::Request.new(title: 'Test request', method: :get, url: 'example.com', driver: driver) } + let(:request) { Http::Request.new(title: 'Test request', method: :get, url: 'example.com', driver:) } it 'should send request' do expect { subject }.to change(request, :sent?).from(false).to(true) @@ -66,7 +66,7 @@ module LunaPark describe '#get' do it_behaves_like 'send request', :get do - let(:request) { Http::Request.new(title: 'Test request', method: :post, url: 'example.com', driver: driver) } + let(:request) { Http::Request.new(title: 'Test request', method: :post, url: 'example.com', driver:) } subject { client.get request } end end @@ -97,7 +97,7 @@ module LunaPark describe '#get!' do it_behaves_like 'send request', :get do - let(:request) { Http::Request.new(title: 'Test request', method: :post, url: 'example.com', driver: driver) } + let(:request) { Http::Request.new(title: 'Test request', method: :post, url: 'example.com', driver:) } subject { client.get! request } end end diff --git a/spec/luna_park/http/request_spec.rb b/spec/luna_park/http/request_spec.rb index 757a3c2c..73e7ec2d 100644 --- a/spec/luna_park/http/request_spec.rb +++ b/spec/luna_park/http/request_spec.rb @@ -15,7 +15,7 @@ module LunaPark url: 'http://example.com', body: JSON.generate(message: 'ping'), headers: { 'Content-Type': 'application/json' }, - driver: driver + driver: ) end @@ -150,11 +150,11 @@ module LunaPark describe '#driver' do subject { request.driver } - class Driver; end - let(:request) { Http::Request.new(title: 'Example', method: :get, url: 'http://yandex.ru', driver: Driver) } + let(:driver_class) { Class.new } + let(:request) { Http::Request.new(title: 'Example', method: :get, url: 'http://yandex.ru', driver: driver_class) } it 'should be expected driver' do - is_expected.to eq Driver + is_expected.to eq driver_class end end diff --git a/spec/luna_park/http/response_spec.rb b/spec/luna_park/http/response_spec.rb index 011d1e0c..6c8889ff 100644 --- a/spec/luna_park/http/response_spec.rb +++ b/spec/luna_park/http/response_spec.rb @@ -10,8 +10,8 @@ module LunaPark body: '{"message":"pong"}', code: 200, headers: { 'Content-Type': 'application/json' }, - cookies: { 'Secret': 'dkmvc9saudj3cndsaosp' }, - request: request + cookies: { Secret: 'dkmvc9saudj3cndsaosp' }, + request: } end @@ -75,10 +75,10 @@ module LunaPark subject { response.cookies } context 'when defined in initialize method' do - before { params[:cookies] = { 'SSID': 'r2t5uvjq435r4q7ib3vtdjq120' } } + before { params[:cookies] = { SSID: 'r2t5uvjq435r4q7ib3vtdjq120' } } it 'should eq defined value' do - is_expected.to eq('SSID': 'r2t5uvjq435r4q7ib3vtdjq120') + is_expected.to eq(SSID: 'r2t5uvjq435r4q7ib3vtdjq120') end end @@ -359,7 +359,7 @@ module LunaPark body: '{"message":"pong"}', code: 200, headers: { 'Content-Type': 'application/json' }, - cookies: { 'Secret': 'dkmvc9saudj3cndsaosp' }, + cookies: { Secret: 'dkmvc9saudj3cndsaosp' }, request: request_hash ) end diff --git a/spec/luna_park/http/send_spec.rb b/spec/luna_park/http/send_spec.rb index 41251880..e692db15 100644 --- a/spec/luna_park/http/send_spec.rb +++ b/spec/luna_park/http/send_spec.rb @@ -53,7 +53,7 @@ module LunaPark set_cookie: ['theme=light'] }, cookies: { 'theme' => 'light' }, - request: request + request: ) end end @@ -78,7 +78,7 @@ module LunaPark content_type: 'application/json' }, cookies: {}, - request: request + request: ) end end @@ -89,7 +89,7 @@ module LunaPark end it 'should get response with 503' do - is_expected.to eq Http::Response.new(code: 503, request: request) + is_expected.to eq Http::Response.new(code: 503, request:) end end @@ -97,7 +97,7 @@ module LunaPark before { stub_request(:any, 'http://example.com').to_raise(Net::OpenTimeout) } it 'should get response with 408' do - is_expected.to eq Http::Response.new(code: 408, request: request) + is_expected.to eq Http::Response.new(code: 408, request:) end end @@ -105,7 +105,7 @@ module LunaPark before { stub_request(:any, 'http://example.com').to_raise(Net::ReadTimeout) } it 'should get response with 408' do - is_expected.to eq Http::Response.new(code: 408, request: request) + is_expected.to eq Http::Response.new(code: 408, request:) end end end @@ -146,7 +146,7 @@ module LunaPark set_cookie: ['theme=light'] }, cookies: { 'theme' => 'light' }, - request: request + request: ) end end @@ -168,7 +168,7 @@ module LunaPark headers: { content_type: 'application/json' }, - request: request + request: ) expect { send! }.to raise_error( @@ -186,7 +186,7 @@ module LunaPark end it 'should raise http exception with 503 error code response' do - expected_response = Http::Response.new(code: 503, request: request) + expected_response = Http::Response.new(code: 503, request:) expect { send! }.to raise_error( an_instance_of(Errors::Http).and(having_attributes( @@ -201,7 +201,7 @@ module LunaPark before { stub_request(:any, 'http://example.com').to_raise(Net::OpenTimeout) } it 'should raise http exception with 408 error code response' do - expected_response = Http::Response.new(code: 408, request: request) + expected_response = Http::Response.new(code: 408, request:) expect { send! }.to raise_error( an_instance_of(Errors::Http).and(having_attributes( @@ -216,7 +216,7 @@ module LunaPark before { stub_request(:any, 'http://example.com').to_raise(Net::ReadTimeout) } it 'should raise http exception with 408 error code response' do - expected_response = Http::Response.new(code: 408, request: request) + expected_response = Http::Response.new(code: 408, request:) expect { send! }.to raise_error( an_instance_of(Errors::Http).and(having_attributes( diff --git a/spec/luna_park/mappers/codirectional_spec.rb b/spec/luna_park/mappers/codirectional_spec.rb index 01cbb5d8..d2b76b74 100644 --- a/spec/luna_park/mappers/codirectional_spec.rb +++ b/spec/luna_park/mappers/codirectional_spec.rb @@ -18,13 +18,13 @@ class Transaction def initialize(**opts) @uid = opts[:uid] - @funds = Funds.new(opts[:funds]) + @funds = Funds.new(**opts[:funds]) @comment = opts[:comment] @sizes = opts[:sizes] end def to_h - { uid: uid, funds: funds.to_h, comment: comment, sizes: @sizes.to_h } + { uid:, funds: funds.to_h, comment:, sizes: @sizes.to_h } end end @@ -32,7 +32,7 @@ class Funds attr_reader :charge, :usd def initialize(charge:, usd: nil) - @charge = Money.new(charge) + @charge = Money.new(**charge) @usd = usd end @@ -50,7 +50,7 @@ def initialize(amount:, currency:) end def to_h - { amount: amount, currency: currency } + { amount:, currency: } end end end @@ -61,8 +61,8 @@ module LunaPark let(:sizes) { { waist: 42, length: 176 } } - let(:attrs) { { uid: 42, funds: { charge: { amount: 10, currency: 'USD' } }, sizes: sizes, comment: 'Foobar' } } - let(:row) { { id: 42, funds_charge_amount: 10, funds_charge_currency: 'USD', sizes: sizes, comment: 'Foobar' } } + let(:attrs) { { uid: 42, funds: { charge: { amount: 10, currency: 'USD' } }, sizes:, comment: 'Foobar' } } + let(:row) { { id: 42, funds_charge_amount: 10, funds_charge_currency: 'USD', sizes:, comment: 'Foobar' } } describe '.to_row' do subject(:to_row) { mapper.to_row(input) } diff --git a/spec/luna_park/notifiers/bugsnag_spec.rb b/spec/luna_park/notifiers/bugsnag_spec.rb index 2deaf7af..3e761f98 100644 --- a/spec/luna_park/notifiers/bugsnag_spec.rb +++ b/spec/luna_park/notifiers/bugsnag_spec.rb @@ -36,9 +36,8 @@ module LunaPark end context 'when message is custom error' do - class CustomError < RuntimeError; end - - subject(:post_message) { notifier.post CustomError.new('Something went wrong. Again.') } + let(:custom_error_class) { Class.new(RuntimeError) } + subject(:post_message) { notifier.post custom_error_class.new('Something went wrong. Again.') } it 'should notify bugsnag with CustomError' do post_message @@ -195,7 +194,7 @@ def have_sent_bugsnag_notification(&block) event = JSON.parse(request.body).dig('events', 0) error_class = event.dig('exceptions', 0, 'errorClass') message = event.dig('exceptions', 0, 'message') - severity = event.dig('severity') + severity = event['severity'] details = event.dig('metaData', 'details') custom = event.dig('metaData', 'custom') diff --git a/spec/luna_park/notifiers/log/formatters_spec.rb b/spec/luna_park/notifiers/log/formatters_spec.rb index aafc9b66..f3adbb1b 100644 --- a/spec/luna_park/notifiers/log/formatters_spec.rb +++ b/spec/luna_park/notifiers/log/formatters_spec.rb @@ -40,7 +40,7 @@ module LunaPark it 'returns message with details in the form of a hash divided into several lines' do is_expected.to eq <<~MULTILINE.chomp # heredoc has newline symbol at the end, chomp it {:class=>String, - :message=>\"Task is finished\", + :message=>"Task is finished", :details=>{:duration=>0.67, :user=>{:uid=>"uid", :name=>"John"}}}\n MULTILINE end diff --git a/spec/luna_park/notifiers/log_spec.rb b/spec/luna_park/notifiers/log_spec.rb index 51b86f0e..dde518c5 100644 --- a/spec/luna_park/notifiers/log_spec.rb +++ b/spec/luna_park/notifiers/log_spec.rb @@ -6,13 +6,13 @@ module LunaPark RSpec.describe Notifiers::Log do let(:logger) { double } let(:formatter) { Notifiers::Log::Formatters::SINGLE } - let(:notifier) { described_class.new(logger: logger, formatter: formatter) } + let(:notifier) { described_class.new(logger:, formatter:) } describe '#formatter' do subject { notifier.formatter } context 'when defined in initialize method' do - let(:notifier) { described_class.new(logger: logger, formatter: Notifiers::Log::Formatters::JSON) } + let(:notifier) { described_class.new(logger:, formatter: Notifiers::Log::Formatters::JSON) } it 'should eq defined value' do is_expected.to eq Notifiers::Log::Formatters::JSON @@ -20,13 +20,13 @@ module LunaPark end context 'when undefined in initialize method' do - let(:notifier) { described_class.new(logger: logger) } + let(:notifier) { described_class.new(logger:) } it { is_expected.to eq Notifiers::Log::Formatters::SINGLE } end context 'when format param used to set formatter' do - let(:notifier) { described_class.new(logger: logger, format: :json) } + let(:notifier) { described_class.new(logger:, format: :json) } it { is_expected.to eq Notifiers::Log::Formatters::JSON } end @@ -42,50 +42,50 @@ module LunaPark # It's really dirty, like code of logger class it 'should output to stdout' do - expect(logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)).to eq STDOUT + expect(logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)).to eq $stdout end end context 'defined in class' do - class FakeLogger; end + let!(:fake_logger) { stub_const('FakeLogger', Class.new) } let(:log_class) do - Class.new(described_class) { logger FakeLogger } + Class.new(described_class) { logger(FakeLogger) } end let(:notifier) { log_class.new } it 'should be expected driver' do - is_expected.to eq FakeLogger + is_expected.to eq fake_logger end end context 'defined at initialize of instance' do - class FakeLogger; end - let(:notifier) { described_class.new logger: FakeLogger } + let(:fake_logger) { Class.new } + let(:notifier) { described_class.new logger: fake_logger } it 'should be expected driver' do - is_expected.to eq FakeLogger + is_expected.to eq fake_logger end end end describe '#message' do - class TestLogger - attr_reader :severity, :output - - def initialize(severity, output) - @severity = severity - @output = output - end - - def self.add(severity, obj) - new(severity, obj) + let(:logger) do + Class.new do + attr_reader :severity, :output + + def initialize(severity, output) + @severity = severity + @output = output + end + + def self.add(severity, obj) + new(severity, obj) + end end end - let(:logger) { TestLogger } - context 'when message has not details' do subject(:posted_message) { notifier.post('Message example') } diff --git a/spec/luna_park/notifiers/sentry_spec.rb b/spec/luna_park/notifiers/sentry_spec.rb index d186e3b2..49b605cc 100644 --- a/spec/luna_park/notifiers/sentry_spec.rb +++ b/spec/luna_park/notifiers/sentry_spec.rb @@ -40,8 +40,8 @@ module LunaPark end context 'when message is custom error' do - class CustomError < RuntimeError; end - let(:error) { CustomError.new('Something went wrong. Again.') } + let(:custom_error) { Class.new(RuntimeError) } + let(:error) { custom_error.new('Something went wrong. Again.') } subject(:post_message) { notifier.post error } diff --git a/spec/luna_park/use_cases/scenario_spec.rb b/spec/luna_park/use_cases/scenario_spec.rb index e0bb1233..b28dcb2b 100644 --- a/spec/luna_park/use_cases/scenario_spec.rb +++ b/spec/luna_park/use_cases/scenario_spec.rb @@ -169,7 +169,7 @@ def call! describe 'notify parameter' do let(:notifier) { double('Notifier', error: nil, warning: nil, info: nil) } - let(:scenario) { gunshot.new lucky_mode: false, notifier: notifier, error: YouDied.new(notify: notify) } + let(:scenario) { gunshot.new lucky_mode: false, notifier:, error: YouDied.new(notify:) } context 'when it undefined' do let(:notify) { nil } @@ -264,24 +264,24 @@ def call! end context 'when notifier defined in class' do - class Notifier; end + let!(:notifier) { stub_const('Notifier', Class.new) } let(:gunshot) do Class.new(described_class) do attr_accessor :notify, :lucky_mode, :error - notify_with Notifier + notify_with notifier end end it 'should eq class defined notifier' do - is_expected.to eq Notifier + is_expected.to eq notifier end end context 'when notifier does not set in instance' do let(:notifier) { double 'Notifier' } - let(:scenario) { gunshot.new notifier: notifier } + let(:scenario) { gunshot.new notifier: } it 'should eq defined notifier' do is_expected.to eq notifier @@ -385,7 +385,7 @@ class Notifier; end end context 'when notifier defined in class' do - class Notifier; end + let!(:notifier) { stub_const('Notifier', Class.new) } let(:gunshot) do Class.new(described_class) do diff --git a/spec/luna_park/values/single_spec.rb b/spec/luna_park/values/single_spec.rb index 35f06e69..c0ab96c4 100644 --- a/spec/luna_park/values/single_spec.rb +++ b/spec/luna_park/values/single_spec.rb @@ -47,8 +47,8 @@ module LunaPark end describe '#to_s' do - let(:value) { 6 } - subject(:to_s) { rank.to_s } + let(:value) { 6 } + subject(:to_string) { rank.to_s } it 'is equal value.to_s' do is_expected.to eq value.to_s