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
-
#double_injections ⇒ Object
readonly
Returns the value of attribute double_injections.
-
#method_missing_injections ⇒ Object
readonly
Returns the value of attribute method_missing_injections.
-
#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
-
#double_injection(subject, method_name) ⇒ Object
Reuses or creates, if none exists, a DoubleInjection for the passed in subject and method_name.
- #double_injection_exists?(subject, method_name) ⇒ Boolean
-
#initialize ⇒ Space
constructor
A new instance of Space.
- #method_missing_injection(subject) ⇒ Object
- #method_missing_injection_exists?(subject) ⇒ Boolean
- #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.
- #singleton_method_added_injection(subject) ⇒ Object
- #singleton_method_added_injection_exists?(subject) ⇒ Boolean
-
#verify_double(subject, method_name) ⇒ Object
Verifies the DoubleInjection for the passed in subject and method_name.
-
#verify_doubles(*objects) ⇒ 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 29 30 31 32 33 |
# File 'lib/rr/space.rb', line 24 def initialize @double_injections = HashWithObjectIdKey.new do |hash, subject_object| hash.set_with_object_id(subject_object, {}) end @method_missing_injections = HashWithObjectIdKey.new @singleton_method_added_injections = HashWithObjectIdKey.new @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
#double_injections ⇒ Object (readonly)
Returns the value of attribute double_injections.
22 23 24 |
# File 'lib/rr/space.rb', line 22 def double_injections @double_injections end |
#method_missing_injections ⇒ Object (readonly)
Returns the value of attribute method_missing_injections.
22 23 24 |
# File 'lib/rr/space.rb', line 22 def method_missing_injections @method_missing_injections end |
#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
#double_injection(subject, method_name) ⇒ Object
Reuses or creates, if none exists, a DoubleInjection for the passed in subject and method_name. When a DoubleInjection is created, it binds the dispatcher to the subject.
39 40 41 42 43 |
# File 'lib/rr/space.rb', line 39 def double_injection(subject, method_name) @double_injections[subject][method_name.to_sym] ||= begin Injections::DoubleInjection.new(subject, method_name.to_sym, (class << subject; self; end)).bind end end |
#double_injection_exists?(subject, method_name) ⇒ Boolean
45 46 47 |
# File 'lib/rr/space.rb', line 45 def double_injection_exists?(subject, method_name) @double_injections.include?(subject) && @double_injections[subject].include?(method_name.to_sym) end |
#method_missing_injection(subject) ⇒ Object
49 50 51 52 53 |
# File 'lib/rr/space.rb', line 49 def method_missing_injection(subject) @method_missing_injections[subject] ||= begin Injections::MethodMissingInjection.new(subject).bind end end |
#method_missing_injection_exists?(subject) ⇒ Boolean
55 56 57 |
# File 'lib/rr/space.rb', line 55 def method_missing_injection_exists?(subject) @method_missing_injections.include?(subject) end |
#record_call(subject, method_name, arguments, block) ⇒ Object
126 127 128 |
# File 'lib/rr/space.rb', line 126 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.
70 71 72 |
# File 'lib/rr/space.rb', line 70 def register_ordered_double(double) @ordered_doubles << double unless ordered_doubles.include?(double) end |
#reset ⇒ Object
Resets the registered Doubles and ordered Doubles
104 105 106 107 108 109 110 |
# File 'lib/rr/space.rb', line 104 def reset reset_ordered_doubles reset_double_injections 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.
120 121 122 123 124 |
# File 'lib/rr/space.rb', line 120 def reset_double(subject, method_name) double_injection = @double_injections[subject].delete(method_name) @double_injections.delete(subject) if @double_injections[subject].empty? double_injection.reset end |
#singleton_method_added_injection(subject) ⇒ Object
59 60 61 62 63 |
# File 'lib/rr/space.rb', line 59 def singleton_method_added_injection(subject) @singleton_method_added_injections[subject] ||= begin Injections::SingletonMethodAddedInjection.new(subject).bind end end |
#singleton_method_added_injection_exists?(subject) ⇒ Boolean
65 66 67 |
# File 'lib/rr/space.rb', line 65 def singleton_method_added_injection_exists?(subject) @singleton_method_added_injections.include?(subject) end |
#verify_double(subject, method_name) ⇒ Object
Verifies the DoubleInjection for the passed in subject and method_name.
113 114 115 116 117 |
# File 'lib/rr/space.rb', line 113 def verify_double(subject, method_name) @double_injections[subject][method_name].verify ensure reset_double subject, method_name end |
#verify_doubles(*objects) ⇒ Object Also known as: verify
Verifies all the DoubleInjection objects have met their TimesCalledExpectations.
93 94 95 96 97 98 99 100 |
# File 'lib/rr/space.rb', line 93 def verify_doubles(*objects) objects = @double_injections.keys if objects.empty? objects.each do |subject| @double_injections[subject].keys.each do |method_name| verify_double(subject, method_name) end end end |
#verify_ordered_double(double) ⇒ Object
Verifies that the passed in ordered Double is being called in the correct position.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rr/space.rb', line 76 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 |