Class: Cuprum::RSpec::BeAResultMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/cuprum/rspec/be_a_result_matcher.rb

Overview

Custom matcher that asserts the actual object is a Cuprum result object with the specified properties.

Instance Method Summary collapse

Constructor Details

#initializeBeAResultMatcher

Returns a new instance of BeAResultMatcher.



16
17
18
19
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 16

def initialize
  @expected_error = DEFAULT_VALUE
  @expected_value = DEFAULT_VALUE
end

Instance Method Details

#descriptionString

Returns a short description of the matcher and expected properties.

Returns:

  • (String)

    a short description of the matcher and expected properties.



23
24
25
26
27
28
29
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 23

def description
  message = 'be a Cuprum result'

  return message unless expected_properties?

  "#{message} #{properties_description}"
end

#does_not_match?(actual) ⇒ Boolean

Checks that the given actual object is not a Cuprum result.

Parameters:

  • actual (Object)

    The actual object to match.

Returns:

  • (Boolean)

    false if the actual object is a result; otherwise true.

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 36

def does_not_match?(actual)
  @actual = actual

  raise ArgumentError, negated_matcher_warning if expected_properties?

  !actual_is_result?
end

#failure_messageString

Returns a summary message describing a failed expectation.

Returns:

  • (String)

    a summary message describing a failed expectation.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 45

def failure_message
  message = "expected #{actual.inspect} to #{description}"

  if !actual_is_result?
    message + ', but the object is not a result'
  elsif actual_is_uncalled_operation?
    message + ', but the object is an uncalled operation'
  elsif !properties_match?
    message + properties_failure_message
  else
    # :nocov:
    message
    # :nocov:
  end
end

#failure_message_when_negatedString

Returns a summary message describing a failed negated expectation.

Returns:

  • (String)

    a summary message describing a failed negated expectation.



63
64
65
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 63

def failure_message_when_negated
  "expected #{actual.inspect} not to #{description}"
end

#matches?(actual) ⇒ Boolean

Checks that the given actual object is a Cuprum result or compatible object and has the specified properties.

Parameters:

  • actual (Object)

    The actual object to match.

Returns:

  • (Boolean)

    true if the actual object is a result with the expected properties; otherwise false.



74
75
76
77
78
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 74

def matches?(actual)
  @actual = actual

  actual_is_result? && !actual_is_uncalled_operation? && properties_match?
end

#with_error(error) ⇒ BeAResultMatcher Also known as: and_error

Sets an error expectation on the matcher. Calls to #matches? will fail unless the actual object has the specified error.

Parameters:

Returns:



86
87
88
89
90
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 86

def with_error(error)
  @expected_error = error

  self
end

#with_status(status) ⇒ BeAResultMatcher Also known as: and_status

Sets a status expectation on the matcher. Calls to #matches? will fail unless the actual object has the specified status.

Parameters:

  • status (Symbol)

    The expected status.

Returns:



99
100
101
102
103
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 99

def with_status(status)
  @expected_status = status

  self
end

#with_value(value) ⇒ BeAResultMatcher Also known as: and_value

Sets a value expectation on the matcher. Calls to #matches? will fail unless the actual object has the specified value.

Parameters:

  • value (Object)

    The expected value.

Returns:



112
113
114
115
116
# File 'lib/cuprum/rspec/be_a_result_matcher.rb', line 112

def with_value(value)
  @expected_value = value

  self
end