Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::CacheItsValue
- Inherits:
-
Object
- Object
- ConvenientService::RSpec::PrimitiveMatchers::Classes::CacheItsValue
- Defined in:
- lib/convenient_service/rspec/primitive_matchers/classes/cache_its_value.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #matches?(block_expectation) ⇒ Boolean
-
#printable_block_expectation ⇒ Object
NOTE: An example of how RSpec extracts block source, but they marked it as private.
- #supports_block_expectations? ⇒ Boolean
Instance Method Details
#description ⇒ Object
41 42 43 |
# File 'lib/convenient_service/rspec/primitive_matchers/classes/cache_its_value.rb', line 41 def description "cache its value" end |
#failure_message ⇒ Object
45 46 47 |
# File 'lib/convenient_service/rspec/primitive_matchers/classes/cache_its_value.rb', line 45 def "expected #{printable_block_expectation} to cache its value" end |
#failure_message_when_negated ⇒ Object
49 50 51 |
# File 'lib/convenient_service/rspec/primitive_matchers/classes/cache_its_value.rb', line 49 def "expected #{printable_block_expectation} NOT to cache its value" end |
#matches?(block_expectation) ⇒ Boolean
Note:
‘cache_its_value` may lead to false positives.
Note:
‘cache_its_value` calls the `expect` block twice to check its return values object ids.
28 29 30 31 32 33 34 35 |
# File 'lib/convenient_service/rspec/primitive_matchers/classes/cache_its_value.rb', line 28 def matches?(block_expectation) @block_expectation = block_expectation ## # NOTE: Identical to `block_expectation.call.object_id == block_expectation.call.object_id`. # block_expectation.call.equal?(block_expectation.call) end |
#printable_block_expectation ⇒ Object
NOTE: An example of how RSpec extracts block source, but they marked it as private. github.com/rspec/rspec-expectations/blob/311aaf245f2c5493572bf683b8c441cb5f7e44c8/lib/rspec/matchers/built_in/change.rb#L437
TODO: ‘printable_block_expectation` when `method_source` is available. github.com/banister/method_source
def printable_block_expectation
@printable_block_expectation ||= block_expectation.source
end
64 65 66 |
# File 'lib/convenient_service/rspec/primitive_matchers/classes/cache_its_value.rb', line 64 def printable_block_expectation @printable_block_expectation ||= "{ ... }" end |
#supports_block_expectations? ⇒ Boolean
37 38 39 |
# File 'lib/convenient_service/rspec/primitive_matchers/classes/cache_its_value.rb', line 37 def supports_block_expectations? true end |