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

- (Space) initialize

Returns a new instance of Space



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

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

Class Attribute Details

+ (Object) instance



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

def instance
  @instance ||= new
end

Instance Attribute Details

- (Object) ordered_doubles (readonly)

Returns the value of attribute ordered_doubles



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

def ordered_doubles
  @ordered_doubles
end

- (Object) recorded_calls (readonly)

Returns the value of attribute recorded_calls



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

def recorded_calls
  @recorded_calls
end

- (Object) trim_backtrace

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

- (Object) blank_slate_whitelist



83
84
85
86
87
# File 'lib/rr/space.rb', line 83

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

- (Object) record_call(subject, method_name, arguments, block)



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

def record_call(subject, method_name, arguments, block)
  @recorded_calls << [subject, method_name, arguments, block]
end

- (Object) register_ordered_double(double)

Registers the ordered Double to be verified.



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

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

- (Object) reset

Resets the registered Doubles and ordered Doubles



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

def reset
  reset_ordered_doubles
  Injections::DoubleInjection.reset
  reset_method_missing_injections
  reset_singleton_method_added_injections
  reset_recorded_calls
  reset_bound_objects
end

- (Object) reset_double(subject, method_name)

Resets the DoubleInjection for the passed in subject and method_name.



75
76
77
# File 'lib/rr/space.rb', line 75

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

- (Object) verify_double(subject, method_name)

Verifies the DoubleInjection for the passed in subject and method_name.



70
71
72
# File 'lib/rr/space.rb', line 70

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

- (Object) verify_doubles(*subjects) Also known as: verify

Verifies all the DoubleInjection objects have met their TimesCalledExpectations.



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

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

- (Object) verify_ordered_double(double)

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



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

def verify_ordered_double(double)
  unless double.terminal?
    raise Errors::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 Errors::DoubleOrderError, message
  end
  @ordered_doubles.shift unless double.attempt?
  double
end