From 85b1721a55422ee0e0a1f17783447a353a6f1e25 Mon Sep 17 00:00:00 2001 From: Wyatt Kirby Date: Thu, 23 Oct 2025 09:40:22 -0400 Subject: [PATCH 1/3] Drop official support for Ruby < 3.2 --- .github/workflows/test.yml | 2 +- lib/slayer/command.rb | 12 ++++-------- slayer.gemspec | 28 +++++++++++++++------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95a61ac..2b58435 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - ruby-version: ['3.3', '3.2', '3.1', '3.0', '2.7'] + ruby-version: ['3.4', '3.3', '3.2'] steps: - uses: actions/checkout@v4 diff --git a/lib/slayer/command.rb b/lib/slayer/command.rb index 3991df8..4488fb8 100644 --- a/lib/slayer/command.rb +++ b/lib/slayer/command.rb @@ -2,16 +2,15 @@ module Slayer class Command class << self def call(*args, **kwargs, &block) - instance = self.new + instance = new res = __get_result(instance, *args, **kwargs, &block) handle_match(res, instance, block) if block_given? raise CommandNotImplementedError unless res.is_a? Result - return res + res end - ruby2_keywords :call if respond_to?(:ruby2_keywords, true) def ok(value: nil, status: :default, message: nil) Result.new(value, status, message) @@ -28,11 +27,11 @@ def err!(value: nil, status: :default, message: nil) raise ResultFailureError, err(value: value, status: status, message: message) end - def __get_result(instance, *args, **kwargs, &block) + def __get_result(instance, ...) res = nil begin - res = instance.call(*args, **kwargs, &block) + res = instance.call(...) rescue ResultFailureError => e res = e.result end @@ -63,17 +62,14 @@ def handle_match(res, instance, block) def ok(*args) self.class.ok(*args) end - ruby2_keywords :ok if respond_to?(:ruby2_keywords, true) def err(*args) self.class.err(*args) end - ruby2_keywords :err if respond_to?(:ruby2_keywords, true) def err!(*args) self.class.err!(*args) end - ruby2_keywords :err! if respond_to?(:ruby2_keywords, true) def try!(value: nil, status: nil, message: nil) r = yield diff --git a/slayer.gemspec b/slayer.gemspec index 655c6a3..3abd6e2 100644 --- a/slayer.gemspec +++ b/slayer.gemspec @@ -1,21 +1,22 @@ - -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'slayer/version' Gem::Specification.new do |spec| - spec.name = 'slayer' - spec.version = Slayer::VERSION - spec.authors = ['Wyatt Kirby', 'Noah Callaway'] - spec.email = ['wyatt@apsis.io', 'noah@apsis.io'] + spec.name = 'slayer' + spec.version = Slayer::VERSION + spec.authors = ['Wyatt Kirby', 'Noah Callaway'] + spec.email = ['wyatt@apsis.io', 'noah@apsis.io'] + + spec.summary = 'A killer service layer' + spec.homepage = 'http://www.apsis.io' + spec.license = 'MIT' - spec.summary = 'A killer service layer' - spec.homepage = 'http://www.apsis.io' - spec.license = 'MIT' + spec.required_ruby_version = '>= 3.2.0' - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - spec.bindir = 'exe' - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.bindir = 'exe' + spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] spec.add_dependency 'virtus', '~> 2.0' @@ -24,9 +25,10 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'byebug', '~> 9.0' spec.add_development_dependency 'minitest', '~> 5.0' spec.add_development_dependency 'minitest-reporters', '~> 1.1' - spec.add_development_dependency 'rspec', '~> 3.12' spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec', '~> 3.12' spec.add_development_dependency 'rubocop', '= 1.38.0' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'yard', '~> 0.9' + spec.metadata['rubygems_mfa_required'] = 'true' end From cdb989e0b41a79b982a7e77d1c292221c355d6c4 Mon Sep 17 00:00:00 2001 From: Wyatt Kirby Date: Thu, 23 Oct 2025 10:02:25 -0400 Subject: [PATCH 2/3] Update dependencies, switch to standardrb --- .rubocop.yml | 64 ------------- .standard.yml | 11 +++ Gemfile | 2 +- Rakefile | 12 ++- lib/ext/string_ext.rb | 4 +- lib/slayer.rb | 14 +-- lib/slayer/command.rb | 20 ++-- lib/slayer/compat/compat_040.rb | 22 ++--- lib/slayer/compat/minitest_compat_040.rb | 10 +- lib/slayer/compat/rspec_compat_040.rb | 2 +- lib/slayer/cops/return_matcher.rb | 14 +-- lib/slayer/errors.rb | 4 +- lib/slayer/form.rb | 2 +- lib/slayer/minitest.rb | 10 +- lib/slayer/result.rb | 4 +- lib/slayer/result_matcher.rb | 24 ++--- lib/slayer/rspec.rb | 12 +-- lib/slayer/version.rb | 2 +- slayer.gemspec | 45 ++++----- spec/ext/string_ext_spec.rb | 34 +++---- spec/fixtures/commands/error_command.rb | 2 +- spec/fixtures/commands/no_arg_command.rb | 2 +- spec/fixtures/commands/no_result_command.rb | 4 +- .../commands/not_implemented_command.rb | 2 +- spec/fixtures/commands/scoped_command.rb | 4 +- spec/lib/command_spec.rb | 94 +++++++++---------- spec/lib/custom_matcher_spec.rb | 74 +++++++-------- spec/lib/form_spec.rb | 28 +++--- spec/lib/minitest_assertions_spec.rb | 16 ++-- spec/lib/result_matcher_spec.rb | 24 ++--- spec/lib/rspec_matchers_spec.rb | 44 ++++----- spec/slayer_spec.rb | 2 +- spec/spec_helper.rb | 16 ++-- 33 files changed, 288 insertions(+), 336 deletions(-) delete mode 100644 .rubocop.yml create mode 100644 .standard.yml diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 628fffc..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,64 +0,0 @@ -AllCops: - NewCops: enable - SuggestExtensions: false - TargetRubyVersion: 3.1 - Include: - - 'lib/**/*.rb' - - 'test/**/*.rb' - - 'spec/**/*.rb' - - '**/Gemfile' - - '**/Rakefile' - Exclude: - - 'bin/**/*' - - 'test/fixtures/**/*.rb' - -Style/HashSyntax: - EnforcedShorthandSyntax: never - -Style/Documentation: - Enabled: false - -Naming/BlockForwarding: - Enabled: false - -Style/RedundantSelf: - Enabled: false - -Style/RedundantReturn: - Enabled: false - -Style/GuardClause: - Enabled: false - -Style/ClassAndModuleChildren: - Enabled: false - -Layout/EmptyLinesAroundClassBody: - Enabled: false - -Style/FrozenStringLiteralComment: - Enabled: false - -Layout/CommentIndentation: - Enabled: false - -Layout/LineLength: - Max: 120 - -Metrics/ClassLength: - Max: 120 - -Layout/EmptyLineBetweenDefs: - AllowAdjacentOneLineDefs: true - -Naming/MethodParameterName: - AllowedNames: - - _ - -Style/ClassVars: - Exclude: - - 'lib/slayer/service.rb' - -Style/MutableConstant: - Exclude: - - 'lib/slayer/version.rb' diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..43e0932 --- /dev/null +++ b/.standard.yml @@ -0,0 +1,11 @@ +# Standard Ruby configuration +# https://github.com/testdouble/standard + +ruby_version: 3.2 + +ignore: + - 'bin/**/*' + - 'vendor/**/*' + - 'tmp/**/*' + +fix: true \ No newline at end of file diff --git a/Gemfile b/Gemfile index 881e0ba..888a903 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in slayer.gemspec gemspec diff --git a/Rakefile b/Rakefile index 4c774a2..f6db44e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,12 @@ -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -task default: :spec +begin + require "standard/rake" +rescue LoadError + # Standard not available +end + +task default: [:standard, :spec] diff --git a/lib/ext/string_ext.rb b/lib/ext/string_ext.rb index cfe4613..5af6f4e 100644 --- a/lib/ext/string_ext.rb +++ b/lib/ext/string_ext.rb @@ -1,10 +1,10 @@ class String def underscore word = dup - word.gsub!(/::/, '/') + word.gsub!("::", "/") word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') - word.tr!('-', '_') + word.tr!("-", "_") word.downcase! word end diff --git a/lib/slayer.rb b/lib/slayer.rb index 46efd68..b498676 100644 --- a/lib/slayer.rb +++ b/lib/slayer.rb @@ -1,8 +1,8 @@ -require 'ext/string_ext' unless defined?(Rails) +require "ext/string_ext" unless defined?(Rails) -require 'slayer/version' -require 'slayer/errors' -require 'slayer/result' -require 'slayer/result_matcher' -require 'slayer/command' -require 'slayer/form' +require "slayer/version" +require "slayer/errors" +require "slayer/result" +require "slayer/result_matcher" +require "slayer/command" +require "slayer/form" diff --git a/lib/slayer/command.rb b/lib/slayer/command.rb index 4488fb8..2b1ee1e 100644 --- a/lib/slayer/command.rb +++ b/lib/slayer/command.rb @@ -21,8 +21,8 @@ def err(value: nil, status: :default, message: nil) end def err!(value: nil, status: :default, message: nil) - unless ENV['SUPPRESS_SLAYER_WARNINGS'] - warn '[DEPRECATION] `err!` is deprecated. Please use `return err` instead.' + unless ENV["SUPPRESS_SLAYER_WARNINGS"] + warn "[DEPRECATION] `err!` is deprecated. Please use `return err` instead." end raise ResultFailureError, err(value: value, status: status, message: message) end @@ -48,7 +48,7 @@ def handle_match(res, instance, block) # raise error if not all defaults were handled unless matcher.handled_defaults? - raise(ResultNotHandledError, 'The pass or fail condition of a result was not handled') + raise(ResultNotHandledError, "The pass or fail condition of a result was not handled") end begin @@ -59,16 +59,16 @@ def handle_match(res, instance, block) end end - def ok(*args) - self.class.ok(*args) + def ok(...) + self.class.ok(...) end - def err(*args) - self.class.err(*args) + def err(...) + self.class.err(...) end - def err!(*args) - self.class.err!(*args) + def err!(...) + self.class.err!(...) end def try!(value: nil, status: nil, message: nil) @@ -80,7 +80,7 @@ def try!(value: nil, status: nil, message: nil) end def call - raise NotImplementedError, 'Commands must define method `#call`.' + raise NotImplementedError, "Commands must define method `#call`." end end end diff --git a/lib/slayer/compat/compat_040.rb b/lib/slayer/compat/compat_040.rb index 9d81bc6..69b1588 100644 --- a/lib/slayer/compat/compat_040.rb +++ b/lib/slayer/compat/compat_040.rb @@ -4,48 +4,48 @@ module Slayer class Command class << self def pass(value: nil, status: :default, message: nil) - warn '[DEPRECATION] `pass` is deprecated. Please use `ok` instead.' unless ENV['SUPPRESS_SLAYER_WARNINGS'] + warn "[DEPRECATION] `pass` is deprecated. Please use `ok` instead." unless ENV["SUPPRESS_SLAYER_WARNINGS"] ok(value: value, status: status, message: message) end def flunk(value: nil, status: :default, message: nil) - warn '[DEPRECATION] `flunk` is deprecated. Please use `err` instead.' unless ENV['SUPPRESS_SLAYER_WARNINGS'] + warn "[DEPRECATION] `flunk` is deprecated. Please use `err` instead." unless ENV["SUPPRESS_SLAYER_WARNINGS"] err(value: value, status: status, message: message) end def flunk!(value: nil, status: :default, message: nil) - unless ENV['SUPPRESS_SLAYER_WARNINGS'] - warn '[DEPRECATION] `flunk!` is deprecated. Please use `return err` instead.' + unless ENV["SUPPRESS_SLAYER_WARNINGS"] + warn "[DEPRECATION] `flunk!` is deprecated. Please use `return err` instead." end err!(value: value, status: status, message: message) end end - alias pass ok - alias flunk err - alias flunk! err! + alias_method :pass, :ok + alias_method :flunk, :err + alias_method :flunk!, :err! end class Result def success? - warn '[DEPRECATION] `success?` is deprecated. Please use `ok?` instead.' unless ENV['SUPPRESS_SLAYER_WARNINGS'] + warn "[DEPRECATION] `success?` is deprecated. Please use `ok?` instead." unless ENV["SUPPRESS_SLAYER_WARNINGS"] ok? end def failure? - warn '[DEPRECATION] `failure?` is deprecated. Please use `err?` instead.' unless ENV['SUPPRESS_SLAYER_WARNINGS'] + warn "[DEPRECATION] `failure?` is deprecated. Please use `err?` instead." unless ENV["SUPPRESS_SLAYER_WARNINGS"] err? end end class ResultMatcher def pass(...) - warn '[DEPRECATION] `pass` is deprecated. Please use `ok` instead.' unless ENV['SUPPRESS_SLAYER_WARNINGS'] + warn "[DEPRECATION] `pass` is deprecated. Please use `ok` instead." unless ENV["SUPPRESS_SLAYER_WARNINGS"] ok(...) end def fail(...) - warn '[DEPRECATION] `fail` is deprecated. Please use `err` instead.' unless ENV['SUPPRESS_SLAYER_WARNINGS'] + warn "[DEPRECATION] `fail` is deprecated. Please use `err` instead." unless ENV["SUPPRESS_SLAYER_WARNINGS"] err(...) end end diff --git a/lib/slayer/compat/minitest_compat_040.rb b/lib/slayer/compat/minitest_compat_040.rb index 6607fbc..17812f7 100644 --- a/lib/slayer/compat/minitest_compat_040.rb +++ b/lib/slayer/compat/minitest_compat_040.rb @@ -1,12 +1,12 @@ # :nocov: -require 'minitest/assertions' +require "minitest/assertions" module Minitest::Assertions - alias assert_success assert_ok - alias refute_failed assert_ok - alias assert_failed refute_ok - alias refute_success refute_ok + alias_method :assert_success, :assert_ok + alias_method :refute_failed, :assert_ok + alias_method :assert_failed, :refute_ok + alias_method :refute_success, :refute_ok end # :nocov: diff --git a/lib/slayer/compat/rspec_compat_040.rb b/lib/slayer/compat/rspec_compat_040.rb index 18e9c68..d42db38 100644 --- a/lib/slayer/compat/rspec_compat_040.rb +++ b/lib/slayer/compat/rspec_compat_040.rb @@ -1,6 +1,6 @@ # :nocov: -require 'rspec/expectations' +require "rspec/expectations" RSpec::Matchers.alias_matcher :be_failed_result, :be_err_result RSpec::Matchers.alias_matcher :be_success_result, :be_ok_result diff --git a/lib/slayer/cops/return_matcher.rb b/lib/slayer/cops/return_matcher.rb index d811b21..7e5d701 100644 --- a/lib/slayer/cops/return_matcher.rb +++ b/lib/slayer/cops/return_matcher.rb @@ -1,11 +1,11 @@ -require 'rubocop' +require "rubocop" module Slayer class CommandReturn < RuboCop::Cop::Base - def_node_search :explicit_returns, 'return' - def_node_matcher :slayer_command?, '(class (const (const nil :Slayer) :Command) _)' - def_node_matcher :is_call_to_pass?, '(send nil :pass ?)' - def_node_matcher :is_call_to_flunk?, '(send nil :flunk! ?)' + def_node_search :explicit_returns, "return" + def_node_matcher :slayer_command?, "(class (const (const nil :Slayer) :Command) _)" + def_node_matcher :is_call_to_pass?, "(send nil :pass ?)" + def_node_matcher :is_call_to_flunk?, "(send nil :flunk! ?)" def on_def(node) return unless node.method?(:call) @@ -27,7 +27,7 @@ def on_def(node) # Continue traversing `node` until you get to the last expression. # If that expression is a call to `.can_see?`, then add an offense. def implicit_returns(_node) - raise 'Not Implemented Yet' + raise "Not Implemented Yet" end def in_slayer_command?(node) @@ -39,7 +39,7 @@ def validate_return!(node, return_node = nil) return if is_call_to_flunk? node add_offense(return_node || node, - message: 'call in Slayer::Command must return the result of `pass` or call `flunk!`') + message: "call in Slayer::Command must return the result of `pass` or call `flunk!`") end end end diff --git a/lib/slayer/errors.rb b/lib/slayer/errors.rb index 9edec86..ecb4878 100644 --- a/lib/slayer/errors.rb +++ b/lib/slayer/errors.rb @@ -10,8 +10,8 @@ def initialize(result) class CommandNotImplementedError < StandardError def initialize(message = nil) - message ||= 'Command implementation must return a object' - super message + message ||= "Command implementation must return a object" + super end end diff --git a/lib/slayer/form.rb b/lib/slayer/form.rb index 4034441..3fbf861 100644 --- a/lib/slayer/form.rb +++ b/lib/slayer/form.rb @@ -1,4 +1,4 @@ -require 'virtus' +require "virtus" module Slayer class Form diff --git a/lib/slayer/minitest.rb b/lib/slayer/minitest.rb index 9703929..42041f4 100644 --- a/lib/slayer/minitest.rb +++ b/lib/slayer/minitest.rb @@ -1,9 +1,9 @@ # :nocov: -require 'minitest/assertions' +require "minitest/assertions" # rubocop:disable Metrics/MethodLength module Minitest::Assertions def assert_ok(result, status: nil, message: nil, value: nil) - assert result.ok?, 'Expected command to succeed.' + assert result.ok?, "Expected command to succeed." unless status.nil? assert_equal( @@ -29,10 +29,10 @@ def assert_ok(result, status: nil, message: nil, value: nil) ) end end - alias refute_err assert_ok + alias_method :refute_err, :assert_ok def refute_ok(result, status: nil, message: nil, value: nil) - refute result.ok?, 'Expected command to fail.' + refute result.ok?, "Expected command to fail." unless status.nil? refute_equal( @@ -58,7 +58,7 @@ def refute_ok(result, status: nil, message: nil, value: nil) ) end end - alias assert_err refute_ok + alias_method :assert_err, :refute_ok end # rubocop:enable Style/Documentation # rubocop:enable Metrics/MethodLength diff --git a/lib/slayer/result.rb b/lib/slayer/result.rb index 4188664..387726c 100644 --- a/lib/slayer/result.rb +++ b/lib/slayer/result.rb @@ -3,8 +3,8 @@ class Result attr_reader :value, :status, :message def initialize(value, status, message) - @value = value - @status = status + @value = value + @status = status @message = message end diff --git a/lib/slayer/result_matcher.rb b/lib/slayer/result_matcher.rb index cfaedaa..d82dcaf 100644 --- a/lib/slayer/result_matcher.rb +++ b/lib/slayer/result_matcher.rb @@ -110,11 +110,11 @@ def initialize(result, command) # These are set to false if they are never set. If they are set to `nil` that # means the block intentionally passed `nil` as the block to be executed. - @matching_block = false - @matching_all = false - @default_block = false - @default_all = false - @ensure_block = false + @matching_block = false + @matching_all = false + @default_block = false + @default_all = false + @ensure_block = false end # Provide a block that should be invoked if the {Result} is a success. @@ -129,11 +129,11 @@ def ok(*statuses, &block) statuses << :default if statuses.empty? @handled_default_ok ||= statuses.include?(:default) - block_is_match = @result.ok? && statuses.include?(@status) + block_is_match = @result.ok? && statuses.include?(@status) block_is_default = @result.ok? && statuses.include?(:default) @matching_block = block if block_is_match - @default_block = block if block_is_default + @default_block = block if block_is_default end # Provide a block that should be invoked if the {Result} is a failure. @@ -148,11 +148,11 @@ def err(*statuses, &block) statuses << :default if statuses.empty? @handled_default_err ||= statuses.include?(:default) - block_is_match = @result.err? && statuses.include?(@status) + block_is_match = @result.err? && statuses.include?(@status) block_is_default = @result.err? && statuses.include?(:default) @matching_block = block if block_is_match - @default_block = block if block_is_default + @default_block = block if block_is_default end # Provide a block that should be invoked for any {Result}. This has a lower precedence that @@ -169,11 +169,11 @@ def all(*statuses, &block) @handled_default_ok ||= statuses.include?(:default) @handled_default_err ||= statuses.include?(:default) - block_is_match = statuses.include?(@status) + block_is_match = statuses.include?(@status) block_is_default = statuses.include?(:default) @matching_all = block if block_is_match - @default_all = block if block_is_default + @default_all = block if block_is_default end # Provide a block that should be always be invoked after other blocks have executed. This block @@ -186,7 +186,7 @@ def ensure(&block) # # @api private def handled_defaults? - return @handled_default_ok && @handled_default_err + @handled_default_ok && @handled_default_err end # Executes the provided block that best matched the {Result}. If no block matched diff --git a/lib/slayer/rspec.rb b/lib/slayer/rspec.rb index dc5ff9b..6332741 100644 --- a/lib/slayer/rspec.rb +++ b/lib/slayer/rspec.rb @@ -1,5 +1,5 @@ -require 'rspec/mocks' -require 'rspec/expectations' +require "rspec/mocks" +require "rspec/expectations" # rubocop:disable Metrics/BlockLength RSpec::Matchers.define :be_ok_result do @@ -31,7 +31,7 @@ # :nocov: failure_message do |result| - return 'expected command to succeed' if @status.nil? && @value.nil? && @message.nil? + return "expected command to succeed" if @status.nil? && @value.nil? && @message.nil? return "expected command to succeed with status: :#{@status}, but got: :#{result.status}" unless @status.nil? return "expected command to succeed with value: #{@value}, but got: #{result.value}" unless @value.nil? return "expected command to succeed with message: #{@message}, but got: :#{result.message}" unless @message.nil? @@ -42,7 +42,7 @@ return "expected command not to have value: #{@value}" if !@value.nil? && result.value == @value return "expected command not to have status :#{@status}" if !@status.nil? && result.status == @status - return 'expected command to fail' + return "expected command to fail" end # :nocov: end @@ -76,7 +76,7 @@ # :nocov: failure_message do |result| - return 'expected command to fail' if @status.nil? && @value.nil? && @message.nil? + return "expected command to fail" if @status.nil? && @value.nil? && @message.nil? return "expected command to fail with status: :#{@status}, but got: :#{result.status}" unless @status.nil? return "expected command to fail with value: #{@value}, but got: #{result.value}" unless @value.nil? return "expected command to fail with message: #{@message}, but got: :#{result.message}" unless @message.nil? @@ -87,7 +87,7 @@ return "expected command to have value: #{@value}" if !@value.nil? && result.value == @value return "expected command to have status :#{@status}" if !@status.nil? && result.status == @status - return 'expected command to succeed' + return "expected command to succeed" end # :nocov: end diff --git a/lib/slayer/version.rb b/lib/slayer/version.rb index a8740fa..f34dc9e 100644 --- a/lib/slayer/version.rb +++ b/lib/slayer/version.rb @@ -1,3 +1,3 @@ module Slayer - VERSION = '0.5.4' + VERSION = "0.5.4" end diff --git a/slayer.gemspec b/slayer.gemspec index 3abd6e2..5372eec 100644 --- a/slayer.gemspec +++ b/slayer.gemspec @@ -1,34 +1,35 @@ -lib = File.expand_path('lib', __dir__) +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'slayer/version' +require "slayer/version" Gem::Specification.new do |spec| - spec.name = 'slayer' + spec.name = "slayer" spec.version = Slayer::VERSION - spec.authors = ['Wyatt Kirby', 'Noah Callaway'] - spec.email = ['wyatt@apsis.io', 'noah@apsis.io'] + spec.authors = ["Wyatt Kirby", "Noah Callaway"] + spec.email = ["wyatt@apsis.io", "noah@apsis.io"] - spec.summary = 'A killer service layer' - spec.homepage = 'http://www.apsis.io' - spec.license = 'MIT' + spec.summary = "A killer service layer" + spec.homepage = "http://www.apsis.io" + spec.license = "MIT" - spec.required_ruby_version = '>= 3.2.0' + spec.required_ruby_version = ">= 3.2.0" spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - spec.bindir = 'exe' + spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] + spec.require_paths = ["lib"] - spec.add_dependency 'virtus', '~> 2.0' + spec.add_dependency "bigdecimal" + spec.add_dependency "ostruct" + spec.add_dependency "virtus", "~> 2.0" - spec.add_development_dependency 'bundler', '~> 2.0' - spec.add_development_dependency 'byebug', '~> 9.0' - spec.add_development_dependency 'minitest', '~> 5.0' - spec.add_development_dependency 'minitest-reporters', '~> 1.1' - spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rspec', '~> 3.12' - spec.add_development_dependency 'rubocop', '= 1.38.0' - spec.add_development_dependency 'simplecov' - spec.add_development_dependency 'yard', '~> 0.9' - spec.metadata['rubygems_mfa_required'] = 'true' + spec.add_development_dependency "bundler", ">= 2.2.0" + spec.add_development_dependency "debug" + spec.add_development_dependency "minitest" + spec.add_development_dependency "rake", "~> 13.3" + spec.add_development_dependency "rspec", "~> 3.13" + spec.add_development_dependency "simplecov" + spec.add_development_dependency "standard" + + spec.metadata["rubygems_mfa_required"] = "true" end diff --git a/spec/ext/string_ext_spec.rb b/spec/ext/string_ext_spec.rb index 4058626..835ebe8 100644 --- a/spec/ext/string_ext_spec.rb +++ b/spec/ext/string_ext_spec.rb @@ -1,29 +1,29 @@ RSpec.describe String do - context 'transform string casing' do - describe '::underscore' do - context 'camelcase' do - subject { 'CamelcaseString'.underscore } - it { is_expected.to eq('camelcase_string') } + context "transform string casing" do + describe "::underscore" do + context "camelcase" do + subject { "CamelcaseString".underscore } + it { is_expected.to eq("camelcase_string") } end - context 'snake case' do - subject { 'snake_case'.underscore } - it { is_expected.to eq('snake_case') } + context "snake case" do + subject { "snake_case".underscore } + it { is_expected.to eq("snake_case") } end - context 'screaming snake case' do - subject { 'SCREAMING_SNAKE_CASE'.underscore } - it { is_expected.to eq('screaming_snake_case') } + context "screaming snake case" do + subject { "SCREAMING_SNAKE_CASE".underscore } + it { is_expected.to eq("screaming_snake_case") } end - context 'nested class names' do - subject { 'Nested::ClassName'.underscore } - it { is_expected.to eq('nested/class_name') } + context "nested class names" do + subject { "Nested::ClassName".underscore } + it { is_expected.to eq("nested/class_name") } end - context 'all caps' do - subject { 'ALLCAPS'.underscore } - it { is_expected.to eq('allcaps') } + context "all caps" do + subject { "ALLCAPS".underscore } + it { is_expected.to eq("allcaps") } end end end diff --git a/spec/fixtures/commands/error_command.rb b/spec/fixtures/commands/error_command.rb index 533efc9..daf53fd 100644 --- a/spec/fixtures/commands/error_command.rb +++ b/spec/fixtures/commands/error_command.rb @@ -1,5 +1,5 @@ class ErrorCommand < Slayer::Command def call - raise ArgumentError, 'Error Raised on Purpose' + raise ArgumentError, "Error Raised on Purpose" end end diff --git a/spec/fixtures/commands/no_arg_command.rb b/spec/fixtures/commands/no_arg_command.rb index c86a44f..ab4c021 100644 --- a/spec/fixtures/commands/no_arg_command.rb +++ b/spec/fixtures/commands/no_arg_command.rb @@ -1,5 +1,5 @@ class NoArgCommand < Slayer::Command def call - ok value: 'pass' + ok value: "pass" end end diff --git a/spec/fixtures/commands/no_result_command.rb b/spec/fixtures/commands/no_result_command.rb index 312d5ab..6fcdc8f 100644 --- a/spec/fixtures/commands/no_result_command.rb +++ b/spec/fixtures/commands/no_result_command.rb @@ -1,9 +1,9 @@ class NoResultCommand < Slayer::Command def call(should_pass: true) if should_pass - return ok + ok else - return err + err end end end diff --git a/spec/fixtures/commands/not_implemented_command.rb b/spec/fixtures/commands/not_implemented_command.rb index 9edbf7c..9e34719 100644 --- a/spec/fixtures/commands/not_implemented_command.rb +++ b/spec/fixtures/commands/not_implemented_command.rb @@ -1,6 +1,6 @@ # A command which does not properly implement the command interface class NotImplementedCommand < Slayer::Command def call - return true + true end end diff --git a/spec/fixtures/commands/scoped_command.rb b/spec/fixtures/commands/scoped_command.rb index 37da568..74b3e3e 100644 --- a/spec/fixtures/commands/scoped_command.rb +++ b/spec/fixtures/commands/scoped_command.rb @@ -4,12 +4,12 @@ def call end def not_call - puts 'not call' + puts "not call" end private def private_call - puts 'private_call' + puts "private_call" end end diff --git a/spec/lib/command_spec.rb b/spec/lib/command_spec.rb index 7f952e8..3400d9f 100644 --- a/spec/lib/command_spec.rb +++ b/spec/lib/command_spec.rb @@ -1,17 +1,17 @@ RSpec.describe Slayer::Command do let(:fake_result) { Slayer::Result.new(nil, :default, nil) } - context 'instantiation' do - describe '::call' do - it 'calls #call only once' do + context "instantiation" do + describe "::call" do + it "calls #call only once" do expect(NoArgCommand).to receive(:call).once.and_return(fake_result) NoArgCommand.call end end end - context 'method wrappers' do - describe 'instance' do + context "method wrappers" do + describe "instance" do subject { ScopedCommand.new } it { is_expected.to respond_to(:call) } @@ -19,7 +19,7 @@ it { is_expected.not_to respond_to(:private_call) } end - describe 'class' do + describe "class" do subject { ScopedCommand } it { is_expected.to respond_to(:call) } @@ -36,32 +36,32 @@ # on the Command objects defined in the fixtures # directory for correctness. - context 'result blocks' do - it 'can run with no block' do + context "result blocks" do + it "can run with no block" do result = PassCommand.call(should_pass: true) expect(result.ok?).to be(true) end - it 'yields a result block' do + it "yields a result block" do expect { |m| NoArgCommand.call(&m) }.to yield_result end - it 'executes pass block on pass' do + it "executes pass block on pass" do expect { |m| PassCommand.call(should_pass: true, &m) }.to yield_result.with_pass expect { |m| PassCommand.call(should_pass: false, &m) }.not_to yield_result.with_pass end - it 'exectues fail block on fail' do + it "exectues fail block on fail" do expect { |m| PassCommand.call(should_pass: false, &m) }.to yield_result.with_fail expect { |m| PassCommand.call(should_pass: true, &m) }.not_to yield_result.with_fail end - it 'executes ensure block on fail and pass' do + it "executes ensure block on fail and pass" do expect { |m| PassCommand.call(should_pass: false, &m) }.to yield_result.with_ensure expect { |m| PassCommand.call(should_pass: true, &m) }.to yield_result.with_ensure end - it 'executes ensure block on error' do + it "executes ensure block on error" do rescued = false begin expect { |m| ErrorCommand.call(&m) }.to yield_result.with_ensure @@ -71,16 +71,16 @@ expect(rescued).to be(true) end - it 'raises error if not all defaults are handled' do + it "raises error if not all defaults are handled" do expect { NoArgCommand.call { |m| m.ok { true } } } .to raise_error(Slayer::ResultNotHandledError) end - it 'provides result and command to result handler' do + it "provides result and command to result handler" do NoArgCommand.call do |r| r.all do |value, result, command| expect(value).to be_a(String) - expect(value).to eq('pass') + expect(value).to eq("pass") expect(result).to be_a(Slayer::Result) expect(result.ok?).to eq(true) @@ -91,50 +91,50 @@ end end - context 'result' do - context 'pass' do - it 'returns result' do + context "result" do + context "pass" do + it "returns result" do expect(PassCommand.call(should_pass: true)).to be_a(Slayer::Result) end - it 'has the correct value' do - result = ArgCommand.call(arg: 'arg') - expect(result.value).to eq('arg') + it "has the correct value" do + result = ArgCommand.call(arg: "arg") + expect(result.value).to eq("arg") expect(result.ok?).to be(true) end - it 'passes with no result' do + it "passes with no result" do result = NoResultCommand.call(should_pass: true) expect(result.value).to be(nil) expect(result.ok?).to be(true) end end - context 'fail' do - it 'returns result' do + context "fail" do + it "returns result" do expect(PassCommand.call(should_pass: false)).to be_a(Slayer::Result) end - it 'has the correct value' do + it "has the correct value" do result = ArgCommand.call(arg: nil) expect(result.value).to eq(nil) expect(result.ok?).to be(false) end - it 'fails with no result' do + it "fails with no result" do result = NoResultCommand.call(should_pass: false) expect(result.value).to be(nil) expect(result.err?).to be(true) end end - context 'try' do - it 'bubbles up errors' do + context "try" do + it "bubbles up errors" do result = TryCommand.call(value: :my_value, succeed: false) expect(result.err?).to be(true) end - it 'has the correct value' do + it "has the correct value" do result = TryCommand.call(value: :my_value, succeed: true) expect(result.value).to eq(:my_value) expect(result.ok?).to be(true) @@ -142,28 +142,28 @@ end end - context 'matchers' do - it 'calls pass matcher' do + context "matchers" do + it "calls pass matcher" do success = false PassCommand.call(should_pass: true) do |m| m.ok { success = true } - m.err { raise 'Should Pass, not fail' } - m.all { raise 'Should Pass, and not call `all`' } + m.err { raise "Should Pass, not fail" } + m.all { raise "Should Pass, and not call `all`" } end expect(success).to be true end - it 'calls fail matcher' do + it "calls fail matcher" do success = false PassCommand.call(should_pass: false) do |m| - m.ok { raise 'Should fail, not pass' } + m.ok { raise "Should fail, not pass" } m.err { success = true } - m.all { raise 'Should Fail, and not call `all`' } + m.all { raise "Should Fail, and not call `all`" } end expect(success).to be true end - it 'calls all matcher' do + it "calls all matcher" do success = false PassCommand.call(should_pass: true) do |m| m.all { success = true } @@ -171,7 +171,7 @@ expect(success).to be true end - it 'calls default pass matcher' do + it "calls default pass matcher" do success = false PassCommand.call(should_pass: true) do |m| m.err(:default) { raise "Shouldn't hit this code" } @@ -180,7 +180,7 @@ expect(success).to be true end - it 'calls default fail matcher' do + it "calls default fail matcher" do success = false PassCommand.call(should_pass: false) do |m| m.err(:default) { success = true } @@ -189,7 +189,7 @@ expect(success).to be true end - it 'calls default all matcher' do + it "calls default all matcher" do success = false PassCommand.call(should_pass: false) do |m| m.all(:default) { success = true } @@ -197,17 +197,17 @@ expect(success).to be true end - it 'calls default matcher' do + it "calls default matcher" do success = false NoDefaultCommand.call do |m| - m.ok(:bar) { raise 'This should never be called' } + m.ok(:bar) { raise "This should never be called" } m.ok(:default) { success = true } - m.err { raise 'This should never be called' } + m.err { raise "This should never be called" } end expect(success).to be true end - it 'calls default matcher' do + it "calls default matcher" do success = false NoDefaultCommand.call do |m| m.all { success = true } @@ -216,8 +216,8 @@ end end - context 'invalid calls' do - it { expect { ArgCommand.call(bar: 'arg') }.to raise_error(ArgumentError) } + context "invalid calls" do + it { expect { ArgCommand.call(bar: "arg") }.to raise_error(ArgumentError) } it { expect { NotImplementedCommand.call }.to raise_error(Slayer::CommandNotImplementedError) } it { expect { InvalidCommand.call }.to raise_error(NotImplementedError) } end diff --git a/spec/lib/custom_matcher_spec.rb b/spec/lib/custom_matcher_spec.rb index bb4e253..57483ed 100644 --- a/spec/lib/custom_matcher_spec.rb +++ b/spec/lib/custom_matcher_spec.rb @@ -1,31 +1,30 @@ -# rubocop:disable Metrics/LineLength -require 'slayer/rspec' +require "slayer/rspec" -RSpec.describe 'Custom Matchers' do - context 'be_ok_result' do - context 'success' do - it 'works' do +RSpec.describe "Custom Matchers" do + context "be_ok_result" do + context "success" do + it "works" do expect(WhateverCommand.call(succeed: true)).to be_ok_result end - it 'with value' do - expect(WhateverCommand.call(value: 'Hire Apsis Labs!', succeed: true)).to be_ok_result.with_value('Hire Apsis Labs!') + it "with value" do + expect(WhateverCommand.call(value: "Hire Apsis Labs!", succeed: true)).to be_ok_result.with_value("Hire Apsis Labs!") end - it 'with message' do - expect(WhateverCommand.call(message: 'Hire Apsis Labs!', succeed: true)).to be_ok_result.with_message('Hire Apsis Labs!') + it "with message" do + expect(WhateverCommand.call(message: "Hire Apsis Labs!", succeed: true)).to be_ok_result.with_message("Hire Apsis Labs!") end - it 'with status' do + it "with status" do expect(WhateverCommand.call(status: :apsis_rocks, succeed: true)).to be_ok_result.with_status(:apsis_rocks) end - it 'with' do - expect(WhateverCommand.call(value: 'Hire Apsis Labs!', message: 'Hire Apsis Labs!', status: :apsis_rocks, succeed: true)).to be_ok_result.with(value: 'Hire Apsis Labs!', message: 'Hire Apsis Labs!', status: :apsis_rocks) + it "with" do + expect(WhateverCommand.call(value: "Hire Apsis Labs!", message: "Hire Apsis Labs!", status: :apsis_rocks, succeed: true)).to be_ok_result.with(value: "Hire Apsis Labs!", message: "Hire Apsis Labs!", status: :apsis_rocks) end end - context 'failure' do + context "failure" do before :each do # These pending tests are actually real tests. If they start passing that's bad # But if they start passing, the test suite will fail. @@ -33,48 +32,48 @@ pending("A failed test here means you're passing. So these are permanently 'pending'") end - it 'works' do + it "works" do expect(WhateverCommand.call(succeed: false)).to be_ok_result end - it 'with value' do - expect(WhateverCommand.call(succeed: true)).to be_ok_result.with_value('Hoozah') + it "with value" do + expect(WhateverCommand.call(succeed: true)).to be_ok_result.with_value("Hoozah") end - it 'with message' do - expect(WhateverCommand.call(succeed: true)).to be_ok_result.with_message('Hire Apsis Labs!') + it "with message" do + expect(WhateverCommand.call(succeed: true)).to be_ok_result.with_message("Hire Apsis Labs!") end - it 'with status' do + it "with status" do expect(WhateverCommand.call(succeed: true)).to be_ok_result.with_status(:apsis_rocks) end end end - context 'be_err_result' do - context 'failure' do - it 'works' do + context "be_err_result" do + context "failure" do + it "works" do expect(WhateverCommand.call(succeed: false)).to be_err_result end - it 'be_err_result with value' do - expect(WhateverCommand.call(value: 'Hire Apsis Labs!', succeed: false)).to be_err_result.with_value('Hire Apsis Labs!') + it "be_err_result with value" do + expect(WhateverCommand.call(value: "Hire Apsis Labs!", succeed: false)).to be_err_result.with_value("Hire Apsis Labs!") end - it 'be_err_result with message' do - expect(WhateverCommand.call(message: 'Hire Apsis Labs!', succeed: false)).to be_err_result.with_message('Hire Apsis Labs!') + it "be_err_result with message" do + expect(WhateverCommand.call(message: "Hire Apsis Labs!", succeed: false)).to be_err_result.with_message("Hire Apsis Labs!") end - it 'be_err_result with status' do + it "be_err_result with status" do expect(WhateverCommand.call(status: :apsis_rocks, succeed: false)).to be_err_result.with_status(:apsis_rocks) end - it 'be_err_result with' do - expect(WhateverCommand.call(value: 'Hire Apsis Labs!', message: 'Hire Apsis Labs!', status: :apsis_rocks, succeed: false)).to be_err_result.with(value: 'Hire Apsis Labs!', message: 'Hire Apsis Labs!', status: :apsis_rocks) + it "be_err_result with" do + expect(WhateverCommand.call(value: "Hire Apsis Labs!", message: "Hire Apsis Labs!", status: :apsis_rocks, succeed: false)).to be_err_result.with(value: "Hire Apsis Labs!", message: "Hire Apsis Labs!", status: :apsis_rocks) end end - context 'success' do + context "success" do before :each do # These pending tests are actually real tests. If they start passing that's bad # But if they start passing, the test suite will fail. @@ -82,22 +81,21 @@ pending("A failed test here means you're passing. So these are permanently 'pending'") end - it 'works' do + it "works" do expect(WhateverCommand.call(succeed: true)).to be_err_result end - it 'be_err_result with value' do - expect(WhateverCommand.call(succeed: false)).to be_err_result.with_value('Hire Apsis Labs!') + it "be_err_result with value" do + expect(WhateverCommand.call(succeed: false)).to be_err_result.with_value("Hire Apsis Labs!") end - it 'be_err_result with message' do - expect(WhateverCommand.call(succeed: false)).to be_err_result.with_message('Hire Apsis Labs!') + it "be_err_result with message" do + expect(WhateverCommand.call(succeed: false)).to be_err_result.with_message("Hire Apsis Labs!") end - it 'be_err_result with status' do + it "be_err_result with status" do expect(WhateverCommand.call(succeed: false)).to be_err_result.with_status(:apsis_rocks) end end end end -# rubocop:enable Metrics/LineLength diff --git a/spec/lib/form_spec.rb b/spec/lib/form_spec.rb index aeeba7d..b3bf5bc 100644 --- a/spec/lib/form_spec.rb +++ b/spec/lib/form_spec.rb @@ -1,32 +1,32 @@ -RSpec.shared_examples 'a form' do - it 'sets values correctly' do - expect(form.name).to eq('Luke Skywalker') +RSpec.shared_examples "a form" do + it "sets values correctly" do + expect(form.name).to eq("Luke Skywalker") expect(form.age).to eq(20) end - it 'sets values with correct type' do + it "sets values with correct type" do expect(form.name).to be_a(String) expect(form.age).to be_a(Integer) end end RSpec.describe Slayer::Form do - describe '::new' do - context 'with symbol hash' do - it_behaves_like 'a form' do - let(:form) { PersonForm.new({ name: 'Luke Skywalker', age: 20 }) } + describe "::new" do + context "with symbol hash" do + it_behaves_like "a form" do + let(:form) { PersonForm.new({name: "Luke Skywalker", age: 20}) } end end - context 'with string hash' do - it_behaves_like 'a form' do - let(:form) { PersonForm.new({ 'name' => 'Luke Skywalker', 'age' => 20 }) } + context "with string hash" do + it_behaves_like "a form" do + let(:form) { PersonForm.new({"name" => "Luke Skywalker", "age" => 20}) } end end - context 'with mixed hash' do - it_behaves_like 'a form' do - let(:form) { PersonForm.new({ name: 'Luke Skywalker', 'age' => 20 }) } + context "with mixed hash" do + it_behaves_like "a form" do + let(:form) { PersonForm.new({:name => "Luke Skywalker", "age" => 20}) } end end end diff --git a/spec/lib/minitest_assertions_spec.rb b/spec/lib/minitest_assertions_spec.rb index 1ebff06..e5f8495 100644 --- a/spec/lib/minitest_assertions_spec.rb +++ b/spec/lib/minitest_assertions_spec.rb @@ -1,25 +1,25 @@ -require 'minitest' -require 'slayer/minitest' +require "minitest" +require "slayer/minitest" -RSpec.describe 'Custom Assertions' do - subject(:mock_test) { Minitest::Test.new('mock') } +RSpec.describe "Custom Assertions" do + subject(:mock_test) { Minitest::Test.new("mock") } - it 'assert_ok' do + it "assert_ok" do expect { mock_test.assert_ok PassCommand.call(should_pass: true) }.not_to raise_error expect { mock_test.assert_ok PassCommand.call(should_pass: false) }.to raise_error(Minitest::Assertion) end - it 'refute_ok' do + it "refute_ok" do expect { mock_test.refute_ok PassCommand.call(should_pass: false) }.not_to raise_error expect { mock_test.refute_ok PassCommand.call(should_pass: true) }.to raise_error(Minitest::Assertion) end - it 'assert_err' do + it "assert_err" do expect { mock_test.assert_err PassCommand.call(should_pass: false) }.not_to raise_error expect { mock_test.assert_err PassCommand.call(should_pass: true) }.to raise_error(Minitest::Assertion) end - it 'refute_err' do + it "refute_err" do expect { mock_test.refute_err PassCommand.call(should_pass: true) }.not_to raise_error expect { mock_test.refute_err PassCommand.call(should_pass: false) }.to raise_error(Minitest::Assertion) end diff --git a/spec/lib/result_matcher_spec.rb b/spec/lib/result_matcher_spec.rb index c9c3e7a..9421917 100644 --- a/spec/lib/result_matcher_spec.rb +++ b/spec/lib/result_matcher_spec.rb @@ -1,11 +1,11 @@ RSpec.describe Slayer::ResultMatcher do - describe '#handled_defaults?' do + describe "#handled_defaults?" do subject(:matcher) do - result = Slayer::Result.new(5, :default, 'my message') + result = Slayer::Result.new(5, :default, "my message") Slayer::ResultMatcher.new(result, NoArgCommand.new) end - context 'no default pass' do + context "no default pass" do it { matcher.ok(:ok, :awesome) matcher.all :ok @@ -14,7 +14,7 @@ } end - context 'no default fail' do + context "no default fail" do it { matcher.ok matcher.all :bad @@ -23,36 +23,36 @@ } end - context 'with default all' do + context "with default all" do it { matcher.all expect(matcher.handled_defaults?).to be(true) } end - context 'default fail and pass' do - context 'with implicit defaults' do - it 'passes with implicit defaults' do + context "default fail and pass" do + context "with implicit defaults" do + it "passes with implicit defaults" do matcher.ok matcher.err expect(matcher.handled_defaults?).to be(true) end end - context 'with explicit defaults' do - it 'passes with explicit defaults' do + context "with explicit defaults" do + it "passes with explicit defaults" do matcher.ok(:default) matcher.err(:default) expect(matcher.handled_defaults?).to be(true) end - it 'passes with multiple statuses' do + it "passes with multiple statuses" do matcher.ok(:default, :ok) matcher.err(:default, :bad) expect(matcher.handled_defaults?).to be(true) end - it 'passes with multiple declarations' do + it "passes with multiple declarations" do matcher.ok(:ok) matcher.ok matcher.err(:bad) diff --git a/spec/lib/rspec_matchers_spec.rb b/spec/lib/rspec_matchers_spec.rb index 211b20c..86d17c6 100644 --- a/spec/lib/rspec_matchers_spec.rb +++ b/spec/lib/rspec_matchers_spec.rb @@ -1,55 +1,55 @@ -require 'rspec' -require 'slayer/rspec' +require "rspec" +require "slayer/rspec" -RSpec.describe 'Custom Rspec Matchers' do +RSpec.describe "Custom Rspec Matchers" do # These tests are weird, but basically if they don't throw errors # and pass, then our custom matchers are working - it 'be_ok_result' do - expect(WhateverCommand.call(succeed: true, status: :foo, message: 'foo', - value: 'foo')).to be_ok_result.with_status(:foo).with_value('foo').with_message('foo') - expect(WhateverCommand.call(succeed: true, status: :foo, message: 'foo', - value: 'foo')).to be_ok_result.with({ status: :foo, - value: 'foo', message: 'foo' }) + it "be_ok_result" do + expect(WhateverCommand.call(succeed: true, status: :foo, message: "foo", + value: "foo")).to be_ok_result.with_status(:foo).with_value("foo").with_message("foo") + expect(WhateverCommand.call(succeed: true, status: :foo, message: "foo", + value: "foo")).to be_ok_result.with({status: :foo, + value: "foo", message: "foo"}) end - it 'be_err_result' do - expect(WhateverCommand.call(succeed: false, status: :foo, message: 'foo', - value: 'foo')).to be_err_result.with_status(:foo).with_value('foo').with_message('foo') - expect(WhateverCommand.call(succeed: false, status: :foo, message: 'foo', - value: 'foo')).to be_err_result.with({ status: :foo, - value: 'foo', message: 'foo' }) + it "be_err_result" do + expect(WhateverCommand.call(succeed: false, status: :foo, message: "foo", + value: "foo")).to be_err_result.with_status(:foo).with_value("foo").with_message("foo") + expect(WhateverCommand.call(succeed: false, status: :foo, message: "foo", + value: "foo")).to be_err_result.with({status: :foo, + value: "foo", message: "foo"}) end - describe 'stubs' do - context 'passing fake result' do + describe "stubs" do + context "passing fake result" do # We tell it to fail, but we stubbed a passing result, so it should # give us back an ok result let(:fake_res) { fake_result(ok: true) } - it 'works with result as argument' do + it "works with result as argument" do expect { stub_command_response(PassCommand, fake_res) }.not_to raise_error expect(PassCommand.call(should_pass: false)).to be_ok_result end - it 'works with result as block' do + it "works with result as block" do expect { stub_command_response(PassCommand) { fake_res } }.not_to raise_error expect(PassCommand.call(should_pass: false)).to be_ok_result end end - context 'failing fake result' do + context "failing fake result" do # We tell our command to pass, but we stubbed a failing result, so it should # give us back a failing result let(:fake_res) { fake_result(ok: false) } - it 'works with result as argument' do + it "works with result as argument" do expect { stub_command_response(PassCommand, fake_res) }.not_to raise_error expect(PassCommand.call(should_pass: true)).to be_err_result end - it 'works with result as block' do + it "works with result as block" do expect { stub_command_response(PassCommand) { fake_res } }.not_to raise_error expect(PassCommand.call(should_pass: true)).to be_err_result end diff --git a/spec/slayer_spec.rb b/spec/slayer_spec.rb index 60bf99f..a443dfc 100644 --- a/spec/slayer_spec.rb +++ b/spec/slayer_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Slayer do - it 'has a version number' do + it "has a version number" do expect(Slayer::VERSION).not_to be nil end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f63bb92..7b9caa2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,25 +1,25 @@ -require 'bundler/setup' -require 'simplecov' +require "bundler/setup" +require "simplecov" SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter ] SimpleCov.start do - add_filter '/spec/' + add_filter "/spec/" minimum_coverage(95) end -require 'slayer' -require 'byebug' +require "slayer" +require "debug" # Dir['test/assertions/**/*.rb'].each { |f| require File.expand_path(f) } -Dir['spec/fixtures/**/*.rb'].each { |f| require File.expand_path(f) } -Dir['spec/matchers/**/*.rb'].each { |f| require File.expand_path(f) } +Dir["spec/fixtures/**/*.rb"].each { |f| require File.expand_path(f) } +Dir["spec/matchers/**/*.rb"].each { |f| require File.expand_path(f) } RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = '.rspec_status' + config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! From 27112c372fd5d030839ef84f2072adaeda8c9ee1 Mon Sep 17 00:00:00 2001 From: Wyatt Kirby Date: Thu, 23 Oct 2025 10:04:56 -0400 Subject: [PATCH 3/3] Update hooks to use standardrb --- .githooks/pre-push | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.githooks/pre-push b/.githooks/pre-push index bce4a9b..9da74f6 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -17,12 +17,12 @@ if [ $? -ne 0 ]; then fi echo -echo "Starting rubocop" -bundle exec rubocop --format worst --format simple --format offenses +echo "Starting standard" +bundle exec standardrb if [ $? -ne 0 ]; then echo "" echo "" - echo "Rubocop failed; push aborted!" + echo "Standard failed; push aborted!" exit 1 fi