RSpec

Library providing tools for writing and running RSpec tests.

Class: RSpec::SleepingKingStudios::Support::ValueSpy

Parent Namespace
RSpec::SleepingKingStudios::Support
Defined In
lib/rspec/sleeping_king_studios/support/value_spy.rb

Table Of Contents

Overview

Encapsulates the value of a method call or block, and captures a snapshot of the value at the time the spy is initialized.

Examples

Observing a Method

user  = Person.new(name: 'Alan Bradley')
value = ValueSpy.new(user, :name)
value.initial_value #=> 'Alan Bradley'
value.current_value #=> 'Alan Bradley'

user.name = 'Ed Dillinger'
value.initial_value #=> 'Alan Bradley'
value.current_value #=> 'Ed Dillinger'

Observing a Block

value = ValueSpy.new { Person.where(virtual: false).count }
value.initial_value #=> 4
value.current_value #=> 4

Person.where(name: 'Kevin Flynn').enter_grid!
value.initial_value #=> 4
value.current_value #=> 3

Back To Top

Constructor

#initialize(receiver, method_name) => Object
#initialize(&block) => Object

Overloads

#initialize(receiver, method_name) => Object
Parameters
  • receiver (Object) — The object to watch.
  • method_name (Symbol, String) — The name of the method to watch.
#initialize(&block) => Object
Yields
  • The value to watch. The block will be called each time the value is requested, and the return value of the block will be given as the current value.

Returns

Back To Top

Instance Attributes

#initial_hash => Integer (readonly)

Returns

#initial_inspect => String (readonly)

Returns

#initial_value => Object (readonly)

Returns

Back To Top

Instance Methods

#changed? => Boolean

Returns

#current_value => Object

Returns

#description => String

Returns

Back To Top


Back to Documentation | Reference | RSpec | RSpec::SleepingKingStudios | RSpec::SleepingKingStudios::Support