Class: Moarspec::Matchers::Ret
- Inherits:
-
Object
- Object
- Moarspec::Matchers::Ret
- Includes:
- RSpec::Matchers::Composable
- Defined in:
- lib/moarspec/matchers/ret.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
Instance Method Summary collapse
- #description ⇒ Object
- #diffable? ⇒ Boolean
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected) ⇒ Ret
constructor
A new instance of Ret.
- #matches?(subject) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
Constructor Details
#initialize(expected) ⇒ Ret
Returns a new instance of Ret.
11 12 13 |
# File 'lib/moarspec/matchers/ret.rb', line 11 def initialize(expected) @expected = expected end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
9 10 11 |
# File 'lib/moarspec/matchers/ret.rb', line 9 def actual @actual end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
9 10 11 |
# File 'lib/moarspec/matchers/ret.rb', line 9 def expected @expected end |
Instance Method Details
#description ⇒ Object
31 32 33 |
# File 'lib/moarspec/matchers/ret.rb', line 31 def description "return #{@expected.respond_to?(:description) ? @expected.description : @expected.inspect}" end |
#diffable? ⇒ Boolean
27 28 29 |
# File 'lib/moarspec/matchers/ret.rb', line 27 def diffable? true end |
#failure_message ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/moarspec/matchers/ret.rb', line 35 def case when !@subject.respond_to?(:call) "expected to #{description}, but was not callable" when @expected.respond_to?(:failure_message) "return value mismatch: #{@expected.failure_message}" else "expected to #{description}, but returned #{@actual.inspect}" end end |
#failure_message_when_negated ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/moarspec/matchers/ret.rb', line 46 def case when @expected.respond_to?(:failure_message_when_negated) "return value mismatch: #{@expected.failure_message_when_negated}" else "expected not to #{description}, but returned it" end end |
#matches?(subject) ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/moarspec/matchers/ret.rb', line 15 def matches?(subject) @subject = subject return false unless subject.respond_to?(:call) @actual = subject.call @expected === @actual end |
#supports_block_expectations? ⇒ Boolean
23 24 25 |
# File 'lib/moarspec/matchers/ret.rb', line 23 def supports_block_expectations? true end |