Class: RSpec::BecomeMatcher::Matcher
- Inherits:
-
Object
- Object
- RSpec::BecomeMatcher::Matcher
- Defined in:
- lib/rspec/become_matcher.rb
Constant Summary collapse
- DEFAULT_LIMIT =
3
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#expected_block ⇒ Object
readonly
Returns the value of attribute expected_block.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#was ⇒ Object
readonly
Returns the value of attribute was.
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #in(limit) ⇒ Object
-
#initialize(expected, &block) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(block) ⇒ Boolean
- #matching_now? ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
- #within(limit) ⇒ Object
Constructor Details
#initialize(expected, &block) ⇒ Matcher
Returns a new instance of Matcher.
9 10 11 12 13 |
# File 'lib/rspec/become_matcher.rb', line 9 def initialize(expected, &block) @expected = expected @expected_block = block @limit = DEFAULT_LIMIT end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
7 8 9 |
# File 'lib/rspec/become_matcher.rb', line 7 def current @current end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
7 8 9 |
# File 'lib/rspec/become_matcher.rb', line 7 def expected @expected end |
#expected_block ⇒ Object (readonly)
Returns the value of attribute expected_block.
7 8 9 |
# File 'lib/rspec/become_matcher.rb', line 7 def expected_block @expected_block end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
7 8 9 |
# File 'lib/rspec/become_matcher.rb', line 7 def limit @limit end |
#was ⇒ Object (readonly)
Returns the value of attribute was.
7 8 9 |
# File 'lib/rspec/become_matcher.rb', line 7 def was @was end |
Instance Method Details
#failure_message ⇒ Object
46 47 48 49 50 |
# File 'lib/rspec/become_matcher.rb', line 46 def <<~MESSAGE Expected #{was} to become #{expected || 'given block'} in #{limit.to_i} second, but not MESSAGE end |
#failure_message_when_negated ⇒ Object
52 53 54 55 56 |
# File 'lib/rspec/become_matcher.rb', line 52 def <<~MESSAGE Expected #{was} not to become #{expected || 'given block'} in #{limit.to_i} second MESSAGE end |
#in(limit) ⇒ Object
41 42 43 44 |
# File 'lib/rspec/become_matcher.rb', line 41 def in(limit) warn "[DEPRECATION] `in` is deprecated. Please use `within` instead." within(limit) end |
#matches?(block) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rspec/become_matcher.rb', line 15 def matches?(block) Timeout.timeout(limit) do @was = @current = block.call @current = begin sleep 0.1 block.call end until matching_now? true end rescue Timeout::Error false end |
#matching_now? ⇒ Boolean
28 29 30 31 32 33 34 |
# File 'lib/rspec/become_matcher.rb', line 28 def matching_now? if expected_block expected_block.call(current) else current == expected end end |
#supports_block_expectations? ⇒ Boolean
58 59 60 |
# File 'lib/rspec/become_matcher.rb', line 58 def supports_block_expectations? true end |
#within(limit) ⇒ Object
36 37 38 39 |
# File 'lib/rspec/become_matcher.rb', line 36 def within(limit) @limit = limit self end |