Class: SolidUseCase::RSpecMatchers::MatchFailure

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_use_case/rspec_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_error_name) ⇒ MatchFailure

Returns a new instance of MatchFailure.



41
42
43
# File 'lib/solid_use_case/rspec_matchers.rb', line 41

def initialize(expected_error_name)
  @expected_error_name = expected_error_name
end

Instance Method Details

#failure_messageObject



51
52
53
54
55
56
57
# File 'lib/solid_use_case/rspec_matchers.rb', line 51

def failure_message
  if @is_failure
    "expected result to fail with :#{@expected_error_name} (failed with :#{@result.value.type} instead)"
  else
    "expected result to fail with :#{@expected_error_name} (result was successful instead)"
  end
end

#failure_message_when_negatedObject



59
60
61
62
63
64
65
# File 'lib/solid_use_case/rspec_matchers.rb', line 59

def failure_message_when_negated
  if @is_failure
    "expected result to fail with an error not equal to :#{@expected_error_name}"
  else
    "expected result to fail with an error not equal to :#{@expected_error_name} (result was successful instead)"
  end
end

#matches?(result) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/solid_use_case/rspec_matchers.rb', line 45

def matches?(result)
  @result = result
  @is_failure = @result.is_a?(Deterministic::Failure)
  @is_failure && @result.value.type == @expected_error_name
end