Class: RR::Space
- Inherits:
-
Object
- Object
- RR::Space
- 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
-
#ordered_doubles ⇒ Object
readonly
Returns the value of attribute ordered_doubles.
-
#recorded_calls ⇒ Object
readonly
Returns the value of attribute recorded_calls.
-
#trim_backtrace ⇒ Object
Returns the value of attribute trim_backtrace.
Instance Method Summary collapse
- #blank_slate_whitelist ⇒ Object
-
#initialize ⇒ Space
constructor
A new instance of Space.
- #record_call(subject, method_name, arguments, block) ⇒ Object
-
#register_ordered_double(double) ⇒ Object
Registers the ordered Double to be verified.
-
#reset ⇒ Object
Resets the registered Doubles and ordered Doubles.
-
#reset_double(subject, method_name) ⇒ Object
Resets the DoubleInjection for the passed in subject and method_name.
-
#verify_double(subject, method_name) ⇒ Object
Verifies the DoubleInjection for the passed in subject and method_name.
-
#verify_doubles(*subjects) ⇒ Object
(also: #verify)
Verifies all the DoubleInjection objects have met their TimesCalledExpectations.
-
#verify_ordered_double(double) ⇒ Object
Verifies that the passed in ordered Double is being called in the correct position.
Constructor Details
#initialize ⇒ Space
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
.instance ⇒ Object
11 12 13 |
# File 'lib/rr/space.rb', line 11 def instance @instance ||= new end |
Instance Attribute Details
#ordered_doubles ⇒ Object (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_calls ⇒ Object (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_backtrace ⇒ Object
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_whitelist ⇒ Object
82 83 84 85 86 |
# File 'lib/rr/space.rb', line 82 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
78 79 80 |
# File 'lib/rr/space.rb', line 78 def record_call(subject, method_name, arguments, block) @recorded_calls << [subject, method_name, arguments, block] end |
#register_ordered_double(double) ⇒ Object
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 |
#reset ⇒ Object
Resets the registered Doubles and ordered Doubles
60 61 62 63 64 65 66 |
# 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 end |
#reset_double(subject, method_name) ⇒ Object
Resets the DoubleInjection for the passed in subject and method_name.
74 75 76 |
# File 'lib/rr/space.rb', line 74 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.
69 70 71 |
# File 'lib/rr/space.rb', line 69 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.
54 55 56 |
# File 'lib/rr/space.rb', line 54 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.
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 = Double.formatted_name(double.method_name, double.expected_arguments) << " called out of order in list\n" << Double.(@ordered_doubles) raise Errors::DoubleOrderError, end @ordered_doubles.shift unless double.attempt? double end |