Module: GameboxSpecHelpers::InstanceMethods
- Defined in:
- lib/gamebox/spec/helper.rb
Instance Method Summary collapse
- #actor_stubs(actor, attributes = {}) ⇒ Object
- #create_actor(type = :actor, args = {}) ⇒ Object
- #create_actor_view(type = :actor_view, args = {}, configure = true) ⇒ Object
- #create_conjected_object(type, args = {}, configure = true) ⇒ Object
- #create_mocks(*args) ⇒ Object
- #create_stub_everythings(*args) ⇒ Object
- #evented_stub(wrapped_object) ⇒ Object
- #expects_event(target, event_name, expected_args = [[]]) ⇒ Object
- #expects_no_event(target, event_name) ⇒ Object
Instance Method Details
#actor_stubs(actor, attributes = {}) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/gamebox/spec/helper.rb', line 123 def actor_stubs(actor, attributes={}) attributes.each do |att, value| actor.stubs(att).returns(value) actor.stubs(:do_or_do_not).with(att).returns(value) end end |
#create_actor(type = :actor, args = {}) ⇒ Object
131 132 133 134 135 |
# File 'lib/gamebox/spec/helper.rb', line 131 def create_actor(type=:actor, args={}) act = create_conjected_object type, nil, false act.configure args.merge(actor_type: type) act end |
#create_actor_view(type = :actor_view, args = {}, configure = true) ⇒ Object
147 148 149 |
# File 'lib/gamebox/spec/helper.rb', line 147 def create_actor_view(type=:actor_view, args={}, configure=true) create_conjected_object type, args, configure end |
#create_conjected_object(type, args = {}, configure = true) ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/gamebox/spec/helper.rb', line 137 def create_conjected_object(type, args={}, configure=true) actor_klass = ClassFinder.find(type) raise "Could not find actor class #{type}" unless actor_klass mocks = create_mocks *actor_klass.object_definition.component_names actor_klass.new(mocks).tap do |actor| actor.configure args if configure end end |
#create_mocks(*args) ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/gamebox/spec/helper.rb', line 151 def create_mocks(*args) {}.tap do |mocks| args.each do |mock_name| the_mock = instance_variable_get("@#{mock_name}") the_mock ||= mock(mock_name.to_s) instance_variable_set "@#{mock_name}", the_mock mocks[mock_name.to_sym] = the_mock end end end |
#create_stub_everythings(*args) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/gamebox/spec/helper.rb', line 162 def create_stub_everythings(*args) {}.tap do |stubs| args.each do |stub_name| the_stub = stub_everything(stub_name.to_s) instance_variable_set "@#{stub_name}", the_stub stubs[stub_name.to_sym] = the_stub end end end |
#evented_stub(wrapped_object) ⇒ Object
190 191 192 |
# File 'lib/gamebox/spec/helper.rb', line 190 def evented_stub(wrapped_object) EventedStub.new wrapped_object end |
#expects_event(target, event_name, expected_args = [[]]) ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/gamebox/spec/helper.rb', line 181 def expects_event(target, event_name, expected_args=[[]]) args = [] target.when event_name do |*event_args| args << event_args end yield args.should == expected_args end |
#expects_no_event(target, event_name) ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/gamebox/spec/helper.rb', line 172 def expects_no_event(target, event_name) args = [] target.when event_name do |*event_args| args << event_args end yield args.should be_empty end |