Class: GLCommand::Matchers::ReturnAttributeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gl_command/rspec/matchers.rb

Overview

Specific matcher for ‘returns`, which only stores an Array of keys.

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ ReturnAttributeMatcher

Returns a new instance of ReturnAttributeMatcher.



62
63
64
65
# File 'lib/gl_command/rspec/matchers.rb', line 62

def initialize(attribute)
  @attribute = attribute
  @type_check_attempted = false
end

Instance Method Details

#being(_expected_type) ⇒ Object



67
68
69
70
# File 'lib/gl_command/rspec/matchers.rb', line 67

def being(_expected_type)
  @type_check_attempted = true
  self
end

#descriptionObject



83
84
85
# File 'lib/gl_command/rspec/matchers.rb', line 83

def description
  "return attribute `#{@attribute}`"
end

#failure_messageObject



87
88
89
90
91
# File 'lib/gl_command/rspec/matchers.rb', line 87

def failure_message
  return @failure_reason if @failure_reason

  "Expected #{@command_class.name} to return `#{@attribute}`"
end

#failure_message_when_negatedObject



93
94
95
# File 'lib/gl_command/rspec/matchers.rb', line 93

def failure_message_when_negated
  "Expected #{@command_class.name} not to return `#{@attribute}`"
end

#matches?(command_class) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
79
80
81
# File 'lib/gl_command/rspec/matchers.rb', line 72

def matches?(command_class)
  @command_class = command_class.is_a?(Class) ? command_class : command_class.class

  if @type_check_attempted
    @failure_reason = 'GLCommand::Callable does not store types for `returns`, so `.being()` cannot be used.'
    return false
  end

  @command_class.returns.include?(@attribute)
end