Class: Smartest::ChangeMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/smartest/matchers.rb

Constant Summary collapse

UNSET =
Object.new

Instance Method Summary collapse

Methods inherited from Matcher

#and, #or

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

Returns:

  • (Boolean)


664
665
666
# File 'lib/smartest/matchers.rb', line 664

def composable_block_expectation?
  true
end

#composed_block_matches?Boolean

Returns:

  • (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

#descriptionObject



660
661
662
# File 'lib/smartest/matchers.rb', line 660

def description
  expected_description
end

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (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_messageObject



648
649
650
651
652
# File 'lib/smartest/matchers.rb', line 648

def failure_message
  return "expected a block to change value" unless @callable

  "expected value to #{expected_description}, but #{observed_description}#{failed_modifier_description}"
end

#finish_composed_block_expectationObject



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

Returns:

  • (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_messageObject



654
655
656
657
658
# File 'lib/smartest/matchers.rb', line 654

def negated_failure_message
  return "expected a block not to change value" unless @callable

  "expected value not to change, but #{observed_description}"
end

#prepare_composed_block_expectationObject



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