Class: Smartest::ChangeMatcher
- Defined in:
- lib/smartest/matchers.rb
Constant Summary collapse
- UNSET =
Object.new
Instance Method Summary collapse
- #by(expected_delta) ⇒ Object
- #composable_block_expectation? ⇒ Boolean
- #composed_block_matches? ⇒ Boolean
- #description ⇒ Object
- #does_not_match?(actual) ⇒ Boolean
- #failure_message ⇒ Object
- #finish_composed_block_expectation ⇒ Object
- #from(expected) ⇒ Object
-
#initialize(value_block) ⇒ ChangeMatcher
constructor
A new instance of ChangeMatcher.
- #matches?(actual) ⇒ Boolean
- #negated_failure_message ⇒ Object
- #prepare_composed_block_expectation ⇒ Object
- #to(expected) ⇒ Object
Methods inherited from Matcher
Constructor Details
#initialize(value_block) ⇒ ChangeMatcher
Returns a new instance of ChangeMatcher.
611 612 613 614 615 616 617 |
# File 'lib/smartest/matchers.rb', line 611 def initialize(value_block) @value_block = value_block @expected_from = UNSET @expected_to = UNSET @expected_delta = UNSET reset_result end |
Instance Method Details
#by(expected_delta) ⇒ Object
629 630 631 632 |
# File 'lib/smartest/matchers.rb', line 629 def by(expected_delta) @expected_delta = expected_delta self end |
#composable_block_expectation? ⇒ Boolean
664 665 666 |
# File 'lib/smartest/matchers.rb', line 664 def composable_block_expectation? true end |
#composed_block_matches? ⇒ Boolean
679 680 681 682 683 |
# File 'lib/smartest/matchers.rb', line 679 def composed_block_matches? return false unless @callable positive_failures.empty? end |
#description ⇒ Object
660 661 662 |
# File 'lib/smartest/matchers.rb', line 660 def description expected_description end |
#does_not_match?(actual) ⇒ Boolean
641 642 643 644 645 646 |
# File 'lib/smartest/matchers.rb', line 641 def does_not_match?(actual) run_change(actual) return false unless @callable negated_failures.empty? end |
#failure_message ⇒ Object
648 649 650 651 652 |
# File 'lib/smartest/matchers.rb', line 648 def return "expected a block to change value" unless @callable "expected value to #{expected_description}, but #{observed_description}#{failed_modifier_description}" end |
#finish_composed_block_expectation ⇒ Object
674 675 676 677 |
# File 'lib/smartest/matchers.rb', line 674 def finish_composed_block_expectation @after_value = @value_block.call calculate_delta if delta_expected? end |
#from(expected) ⇒ Object
619 620 621 622 |
# File 'lib/smartest/matchers.rb', line 619 def from(expected) @expected_from = expected self end |
#matches?(actual) ⇒ Boolean
634 635 636 637 638 639 |
# File 'lib/smartest/matchers.rb', line 634 def matches?(actual) run_change(actual) return false unless @callable positive_failures.empty? end |
#negated_failure_message ⇒ Object
654 655 656 657 658 |
# File 'lib/smartest/matchers.rb', line 654 def return "expected a block not to change value" unless @callable "expected value not to change, but #{observed_description}" end |
#prepare_composed_block_expectation ⇒ Object
668 669 670 671 672 |
# File 'lib/smartest/matchers.rb', line 668 def prepare_composed_block_expectation reset_result @callable = true @before_value = @value_block.call end |
#to(expected) ⇒ Object
624 625 626 627 |
# File 'lib/smartest/matchers.rb', line 624 def to(expected) @expected_to = expected self end |