Class: RSpec::Matchers::BuiltIn::Change

### Home Classes Methods

### In Files

- lib/rspec/matchers/built_in/change.rb

### Parent

Object

### Methods

- ::new
- #==
- #actual_delta
- #by
- #by_at_least
- #by_at_most
- #description
- #evaluate_value_proc
- #failure_message_for_should
- #failure_message_for_should_not
- #from
- #matches?
- #raise_block_syntax_error
- #to

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::DeprecatedConstants
- RSpec::Expectations::Deprecation
- RSpec::Expectations::Differ
- RSpec::Expectations::ExpectationHandler
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Syntax::ExpectExpressionGenerator
- RSpec::Expectations::Syntax::ShouldExpressionGenerator
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalse
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTrue
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::Change
- RSpec::Matchers::BuiltIn::Cover
- RSpec::Matchers::BuiltIn::EndWith
- RSpec::Matchers::BuiltIn::Eq
- RSpec::Matchers::BuiltIn::Eql
- RSpec::Matchers::BuiltIn::Equal
- RSpec::Matchers::BuiltIn::Exist
- RSpec::Matchers::BuiltIn::Has
- RSpec::Matchers::BuiltIn::Have
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::MatchArray
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::StartAndEndWith
- RSpec::Matchers::BuiltIn::StartWith
- RSpec::Matchers::BuiltIn::ThrowSymbol
- RSpec::Matchers::BuiltIn::YieldControl
- RSpec::Matchers::BuiltIn::YieldProbe
- RSpec::Matchers::BuiltIn::YieldSuccessiveArgs
- RSpec::Matchers::BuiltIn::YieldWithArgs
- RSpec::Matchers::BuiltIn::YieldWithNoArgs
- RSpec::Matchers::Configuration
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::Extensions
- RSpec::Matchers::Extensions::InstanceEvalWithArgs
- RSpec::Matchers::OperatorMatcher
- RSpec::Matchers::Pretty
- Array

No matching classes.

# RSpec::Matchers::BuiltIn::Change

### Public Class Methods

new(receiver=nil, message=nil, &block) click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 5
    def initialize(receiver=nil, message=nil, &block)
      @message = message
      @value_proc = block || lambda {receiver.__send__(message)}
      @expected_after = @expected_before = @minimum = @maximum = @expected_delta = nil
      @eval_before = @eval_after = false
    end

### Public Instance Methods

==(event_proc) click to toggle source
Alias for: matches?
actual_delta() click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 54
    def actual_delta
      @actual_after - @actual_before
    end

by(expected_delta) click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 62
    def by(expected_delta)
      @expected_delta = expected_delta
      self
    end

by_at_least(minimum) click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 67
    def by_at_least(minimum)
      @minimum = minimum
      self
    end

by_at_most(maximum) click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 72
    def by_at_most(maximum)
      @maximum = maximum
      self
    end

description() click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 89
    def description
      "change ##{message}"
    end

evaluate_value_proc() click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 29
    def evaluate_value_proc
      case val = @value_proc.call
      when Enumerable, String
        val.dup
      else
        val
      end
    end

failure_message_for_should() click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 38
    def failure_message_for_should
      if @eval_before && !expected_matches_actual?(@expected_before, @actual_before)
        "#{message} should have initially been #{@expected_before.inspect}, but was #{@actual_before.inspect}"
      elsif @eval_after && !expected_matches_actual?(@expected_after, @actual_after)
        "#{message} should have been changed to #{failure_message_for_expected_after}, but is now #{@actual_after.inspect}"
      elsif @expected_delta
        "#{message} should have been changed by #{@expected_delta.inspect}, but was changed by #{actual_delta.inspect}"
      elsif @minimum
        "#{message} should have been changed by at least #{@minimum.inspect}, but was changed by #{actual_delta.inspect}"
      elsif @maximum
        "#{message} should have been changed by at most #{@maximum.inspect}, but was changed by #{actual_delta.inspect}"
      else
        "#{message} should have changed, but is still #{@actual_before.inspect}"
      end
    end

failure_message_for_should_not() click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 58
    def failure_message_for_should_not
      "#{message} should not have changed, but did change from #{@actual_before.inspect} to #{@actual_after.inspect}"
    end

from(before) click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 83
    def from (before)
      @eval_before = true
      @expected_before = before
      self
    end

matches?(event_proc) click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 12
    def matches?(event_proc)
      raise_block_syntax_error if block_given?

      @actual_before = evaluate_value_proc
      event_proc.call
      @actual_after = evaluate_value_proc

      (!change_expected? || changed?) && matches_before? && matches_after? && matches_expected_delta? && matches_min? && matches_max?
    end

Also aliased as: ==
raise_block_syntax_error() click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 23
    def raise_block_syntax_error
      raise SyntaxError.new(block passed to should or should_not change must use {} instead of do/end)
    end

to(to) click to toggle source

    # File lib/rspec/matchers/built_in/change.rb, line 77
    def to(to)
      @eval_after = true
      @expected_after = to
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.