Skip to content

Commit

Permalink
Fix rubocops
Browse files Browse the repository at this point in the history
  • Loading branch information
bvicenzo committed May 5, 2022
1 parent 2a05dd0 commit e4be6a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/f_service/rspec/support/helpers/result.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

# Methods to mock a FService result from a service call.
module FServiceResultHelpers
# Create an Fservice result Success or Failure.
def f_service_result(result, value = nil, type = nil)
if result == :success
FService::Result::Success.new(value, type)
Expand All @@ -9,6 +11,7 @@ def f_service_result(result, value = nil, type = nil)
end
end

# Mock a Fservice service call returning a result.
def mock_service(service, result: :success, value: nil, type: nil)
service_result = f_service_result(result, value, type)
allow(service).to receive(:call).and_return(service_result)
Expand Down
6 changes: 4 additions & 2 deletions lib/f_service/rspec/support/matchers/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
if actual.is_a?(FService::Result::Failure)
message = "expected failure's type '#{actual.type.inspect}' to be equal '#{expected.inspect}'"
if defined?(@expected_error)
has_description = @expected_error.respond_to?(:description)
message += " and error '#{actual.error.inspect}' to be "
message += @expected_error.respond_to?(:description) ? @expected_error.description : "equal '#{@expected_error.inspect}'"
message += has_description ? @expected_error.description : "equal '#{@expected_error.inspect}'"
end

message
Expand All @@ -47,8 +48,9 @@
if actual.is_a?(FService::Result::Success)
message = "expected success's type '#{actual.type.inspect}' to be equal '#{expected.inspect}'"
if defined?(@expected_value)
has_description = @expected_value.respond_to?(:description)
message += " and value '#{actual.value.inspect}' to be "
message += @expected_value.respond_to?(:description) ? @expected_value.description : "equal '#{@expected_value.inspect}'"
message += has_description ? @expected_value.description : "equal '#{@expected_value.inspect}'"
end

message
Expand Down

0 comments on commit e4be6a6

Please sign in to comment.