Class: RR::Space

Inherits:
Object
  • Object
show all
Defined in:
lib/rr/space.rb

Overview

RR::Space.instance is the global state subject for the RR framework.

Defined Under Namespace

Modules: Reader

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpace

Returns a new instance of Space.



25
26
27
28
29
# File 'lib/rr/space.rb', line 25

def initialize
  @ordered_doubles = []
  @trim_backtrace = false
  @recorded_calls = RR::RecordedCalls.new
end

Class Attribute Details

.instanceObject



11
12
13
# File 'lib/rr/space.rb', line 11

def instance
  @instance ||= new
end

Instance Attribute Details

#ordered_doublesObject (readonly)

Returns the value of attribute ordered_doubles.



22
23
24
# File 'lib/rr/space.rb', line 22

def ordered_doubles
  @ordered_doubles
end

#recorded_callsObject (readonly)

Returns the value of attribute recorded_calls.



22
23
24
# File 'lib/rr/space.rb', line 22

def recorded_calls
  @recorded_calls
end

#trim_backtraceObject

Returns the value of attribute trim_backtrace.



23
24
25
# File 'lib/rr/space.rb', line 23

def trim_backtrace
  @trim_backtrace
end

Instance Method Details

#blank_slate_whitelistObject



86
87
88
89
90
# File 'lib/rr/space.rb', line 86

def blank_slate_whitelist
  @blank_slate_whitelist ||= [
    "object_id", "respond_to?", "respond_to_missing?", "method_missing", "instance_eval", "instance_exec", "class_eval"
  ]
end

#record_call(subject, method_name, arguments, block) ⇒ Object



82
83
84
# File 'lib/rr/space.rb', line 82

def record_call(subject, method_name, arguments, block)
  @recorded_calls.add(subject, method_name, arguments, block)
end

#register_ordered_double(double) ⇒ Object

Registers the ordered Double to be verified.



32
33
34
# File 'lib/rr/space.rb', line 32

def register_ordered_double(double)
  @ordered_doubles << double unless ordered_doubles.include?(double)
end

#resetObject

Resets the registered Doubles and ordered Doubles



61
62
63
64
65
66
67
68
69
70
# File 'lib/rr/space.rb', line 61

def reset
  RR.trim_backtrace = false
  RR.overridden_error_class = nil
  reset_ordered_doubles
  Injections::DoubleInjection.reset
  reset_method_missing_injections
  reset_singleton_method_added_injections
  reset_recorded_calls
  reset_bound_objects
end

#reset_double(subject, method_name) ⇒ Object

Resets the DoubleInjection for the passed in subject and method_name.



78
79
80
# File 'lib/rr/space.rb', line 78

def reset_double(subject, method_name)
  Injections::DoubleInjection.reset_double(class << subject; self; end, method_name)
end

#verify_double(subject, method_name) ⇒ Object

Verifies the DoubleInjection for the passed in subject and method_name.



73
74
75
# File 'lib/rr/space.rb', line 73

def verify_double(subject, method_name)
  Injections::DoubleInjection.verify_double(class << subject; self; end, method_name)
end

#verify_doubles(*subjects) ⇒ Object Also known as: verify

Verifies all the DoubleInjection objects have met their TimesCalledExpectations.



55
56
57
# File 'lib/rr/space.rb', line 55

def verify_doubles(*subjects)
  Injections::DoubleInjection.verify(*subjects)
end

#verify_ordered_double(double) ⇒ Object

Verifies that the passed in ordered Double is being called in the correct position.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rr/space.rb', line 38

def verify_ordered_double(double)
  unless double.terminal?
    raise RR::Errors.build_error(:DoubleOrderError,
      "Ordered Doubles cannot have a NonTerminal TimesCalledExpectation")
  end
  unless @ordered_doubles.first == double
    message = Double.formatted_name(double.method_name, double.expected_arguments)
    message << " called out of order in list\n"
    message << Double.list_message_part(@ordered_doubles)
    raise RR::Errors.build_error(:DoubleOrderError, message)
  end
  @ordered_doubles.shift unless double.attempt?
  double
end