Class: Operandi::RSpec::Matchers::DefineArgumentMatcher
- Inherits:
-
Object
- Object
- Operandi::RSpec::Matchers::DefineArgumentMatcher
- Defined in:
- lib/operandi/rspec/matchers/define_argument.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(name) ⇒ DefineArgumentMatcher
constructor
A new instance of DefineArgumentMatcher.
- #matches?(service_class) ⇒ Boolean
- #optional(value = true) ⇒ Object
- #required ⇒ Object
- #with_context(value = true) ⇒ Object
- #with_default(default) ⇒ Object
- #with_type(type) ⇒ Object
Constructor Details
#initialize(name) ⇒ DefineArgumentMatcher
Returns a new instance of DefineArgumentMatcher.
30 31 32 33 34 35 36 37 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 30 def initialize(name) @name = name @expected_type = nil @expected_optional = nil @expected_default = nil @check_default = false @expected_context = nil end |
Instance Method Details
#description ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 92 def description desc = "define argument :#{@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 += " with context" if @expected_context desc end |
#failure_message ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 78 def return "expected #{@actual_class} to define argument :#{@name}" unless argument_defined? return unless type_matches? return unless optional_matches? return unless default_matches? return unless context_matches? "" end |
#failure_message_when_negated ⇒ Object
88 89 90 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 88 def "expected #{@actual_class} not to define argument :#{@name}" end |
#matches?(service_class) ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 65 def matches?(service_class) @service_class = service_class @actual_class = service_class.is_a?(Class) ? service_class : service_class.class return false unless argument_defined? return false unless type_matches? return false unless optional_matches? return false unless default_matches? return false unless context_matches? true end |
#optional(value = true) ⇒ Object
44 45 46 47 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 44 def optional(value = true) @expected_optional = value self end |
#required ⇒ Object
49 50 51 52 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 49 def required @expected_optional = false self end |
#with_context(value = true) ⇒ Object
60 61 62 63 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 60 def with_context(value = true) @expected_context = value self end |
#with_default(default) ⇒ Object
54 55 56 57 58 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 54 def with_default(default) @check_default = true @expected_default = default self end |
#with_type(type) ⇒ Object
39 40 41 42 |
# File 'lib/operandi/rspec/matchers/define_argument.rb', line 39 def with_type(type) @expected_type = type self end |