Class: GLCommand::Matchers::CommandArgumentMatcher
- Inherits:
-
Object
- Object
- GLCommand::Matchers::CommandArgumentMatcher
show all
- Defined in:
- lib/gl_command/rspec/matchers.rb
Overview
Base matcher for ‘requires` and `allows`, which store a Hash of { attribute: Type }.
Instance Method Summary
collapse
Constructor Details
Returns a new instance of CommandArgumentMatcher.
9
10
11
12
|
# File 'lib/gl_command/rspec/matchers.rb', line 9
def initialize(attribute)
@attribute = attribute
@expected_type = nil
end
|
Instance Method Details
#being(expected_type) ⇒ Object
14
15
16
17
|
# File 'lib/gl_command/rspec/matchers.rb', line 14
def being(expected_type)
@expected_type = expected_type
self
end
|
#description ⇒ Object
29
30
31
|
# File 'lib/gl_command/rspec/matchers.rb', line 29
def description
"#{action} argument `#{@attribute}`"
end
|
#failure_message ⇒ Object
33
34
35
36
37
|
# File 'lib/gl_command/rspec/matchers.rb', line 33
def failure_message
message = "Expected #{@command_class.name} to #{action} `#{@attribute}`"
message += " of type `#{@expected_type}`" if @expected_type
message
end
|
#failure_message_when_negated ⇒ Object
39
40
41
42
43
|
# File 'lib/gl_command/rspec/matchers.rb', line 39
def failure_message_when_negated
message = "Expected #{@command_class.name} not to #{action} `#{@attribute}`"
message += " of type `#{@expected_type}`" if @expected_type
message
end
|
#matches?(command_class) ⇒ Boolean
19
20
21
22
23
24
25
26
27
|
# File 'lib/gl_command/rspec/matchers.rb', line 19
def matches?(command_class)
@command_class = command_class.is_a?(Class) ? command_class : command_class.class
attributes = @command_class.public_send(scope)
return false unless attributes.key?(@attribute)
return true if @expected_type.nil?
attributes[@attribute] == @expected_type
end
|