Module: GameboxSpecHelpers::InstanceMethods
- Defined in:
- lib/gamebox/spec/helper.rb
Instance Method Summary (collapse)
- - (Object) 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)
Instance Method Details
- (Object) actor_stubs(actor, attributes = {})
121 122 123 124 125 126 |
# File 'lib/gamebox/spec/helper.rb', line 121 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 |
- (Object) create_actor(type = :actor, args = {})
129 130 131 132 133 |
# File 'lib/gamebox/spec/helper.rb', line 129 def create_actor(type=:actor, args={}) act = create_conjected_object type, nil, false act.configure args.merge(actor_type: type) act end |
- (Object) create_actor_view(type = :actor_view, args = {}, configure = true)
145 146 147 |
# File 'lib/gamebox/spec/helper.rb', line 145 def create_actor_view(type=:actor_view, args={}, configure=true) create_conjected_object type, args, configure end |
- (Object) create_conjected_object(type, args = {}, configure = true)
135 136 137 138 139 140 141 142 143 |
# File 'lib/gamebox/spec/helper.rb', line 135 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 |
- (Object) create_mocks(*args)
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/gamebox/spec/helper.rb', line 149 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 |
- (Object) create_stub_everythings(*args)
160 161 162 163 164 165 166 167 168 |
# File 'lib/gamebox/spec/helper.rb', line 160 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 |
- (Object) evented_stub(wrapped_object)
188 189 190 |
# File 'lib/gamebox/spec/helper.rb', line 188 def evented_stub(wrapped_object) EventedStub.new wrapped_object end |
- (Object) expects_event(target, event_name, expected_args = [[]])
179 180 181 182 183 184 185 186 |
# File 'lib/gamebox/spec/helper.rb', line 179 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 |
- (Object) expects_no_event(target, event_name)
170 171 172 173 174 175 176 177 |
# File 'lib/gamebox/spec/helper.rb', line 170 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 |