Class: Operandi::RSpec::Matchers::DefineOutputMatcher
- Inherits:
-
Object
- Object
- Operandi::RSpec::Matchers::DefineOutputMatcher
- Defined in:
- lib/operandi/rspec/matchers/define_output.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(name) ⇒ DefineOutputMatcher
constructor
A new instance of DefineOutputMatcher.
- #matches?(service_class) ⇒ Boolean
- #optional(value = true) ⇒ Object
- #required ⇒ Object
- #with_default(default) ⇒ Object
- #with_type(type) ⇒ Object
Constructor Details
#initialize(name) ⇒ DefineOutputMatcher
Returns a new instance of DefineOutputMatcher.
27 28 29 30 31 32 33 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 27 def initialize(name) @name = name @expected_type = nil @expected_optional = nil @expected_default = nil @check_default = false end |
Instance Method Details
#description ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 81 def description desc = "define output :#{@name}" desc += " with type #{@expected_type}" if @expected_type desc += " as optional" if @expected_optional == true desc += " as required" if @expected_optional == false desc += " with default #{@expected_default.inspect}" if @check_default desc end |
#failure_message ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 68 def return "expected #{@actual_class} to define output :#{@name}" unless output_defined? return unless type_matches? return unless optional_matches? return unless default_matches? "" end |
#failure_message_when_negated ⇒ Object
77 78 79 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 77 def "expected #{@actual_class} not to define output :#{@name}" end |
#matches?(service_class) ⇒ Boolean
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 56 def matches?(service_class) @service_class = service_class @actual_class = service_class.is_a?(Class) ? service_class : service_class.class return false unless output_defined? return false unless type_matches? return false unless optional_matches? return false unless default_matches? true end |
#optional(value = true) ⇒ Object
40 41 42 43 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 40 def optional(value = true) @expected_optional = value self end |
#required ⇒ Object
45 46 47 48 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 45 def required @expected_optional = false self end |
#with_default(default) ⇒ Object
50 51 52 53 54 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 50 def with_default(default) @check_default = true @expected_default = default self end |
#with_type(type) ⇒ Object
35 36 37 38 |
# File 'lib/operandi/rspec/matchers/define_output.rb', line 35 def with_type(type) @expected_type = type self end |