Module: GameboxAcceptanceSpecHelpers::InstanceMethods

Defined in:
lib/gamebox/spec/helper.rb

Instance Method Summary collapse

Instance Method Details

#drawObject



443
444
445
# File 'lib/gamebox/spec/helper.rb', line 443

def draw
  gosu.draw 
end

#gameObject



455
456
457
458
459
460
461
462
# File 'lib/gamebox/spec/helper.rb', line 455

def game
  context = Conject.default_object_context
  @game ||= context[:testing_game].tap do |g|
    g.configure
    input_manager = context[:input_manager]
    input_manager.register g
  end
end

#gosuObject



464
465
466
# File 'lib/gamebox/spec/helper.rb', line 464

def gosu
  @gosu ||= MockGosuWindow.new
end

#mock_font(name, size) ⇒ Object



392
393
394
395
396
397
398
# File 'lib/gamebox/spec/helper.rb', line 392

def mock_font(name, size)
  context = Conject.default_object_context
  resource_manager = context[:resource_manager]
  MockFont.new(name, size).tap do |font|
    resource_manager.stubs(:load_font).with(name, size).returns(font)
  end
end

#mock_image(filename, w = 10, h = 20) ⇒ Object



352
353
354
355
356
357
358
# File 'lib/gamebox/spec/helper.rb', line 352

def mock_image(filename, w=10, h=20)
  context = Conject.default_object_context
  resource_manager = context[:resource_manager]
  MockImage.new(filename, w, h).tap do |img|
    resource_manager.stubs(:load_image).with(filename).returns(img)
  end
end

#mock_tiles(filename, width, height) ⇒ Object



339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/gamebox/spec/helper.rb', line 339

def mock_tiles(filename, width, height)
  context = Conject.default_object_context
  resource_manager = context[:resource_manager]

  [].tap do |tiles|
    (width * height).times do |i|
      tiles << MockImage.new("#{filename}_#{i}", 16, 16)
    end

    resource_manager.stubs(:load_tiles).returns(tiles)
  end
end

#pauseObject



406
407
408
# File 'lib/gamebox/spec/helper.rb', line 406

def pause
  game.current_stage.pause
end

#press_key(button_id) ⇒ Object



451
452
453
# File 'lib/gamebox/spec/helper.rb', line 451

def press_key(button_id)
  gosu.button_down button_id
end

#release_key(button_id) ⇒ Object



447
448
449
# File 'lib/gamebox/spec/helper.rb', line 447

def release_key(button_id)
  gosu.button_up button_id
end

#remove_actor(actor_type) ⇒ Object



414
415
416
417
418
# File 'lib/gamebox/spec/helper.rb', line 414

def remove_actor(actor_type)
  act = game.actor(actor_type)
  act.should be
  act.remove
end

#see_actor_attrs(actor_type, attrs) ⇒ Object



420
421
422
423
424
# File 'lib/gamebox/spec/helper.rb', line 420

def see_actor_attrs(actor_type, attrs)
  act = game.actor(actor_type)
  act.should be
  act.should have_attrs(attrs)
end

#see_actor_drawn(actor_type) ⇒ Object



360
361
362
363
# File 'lib/gamebox/spec/helper.rb', line 360

def see_actor_drawn(actor_type)
  act = game.actor(actor_type)
  act.should be
end

#see_image_drawn(img) ⇒ Object



365
366
367
368
369
# File 'lib/gamebox/spec/helper.rb', line 365

def see_image_drawn(img)
  img.calls.should_not be_empty
  img.calls.first.first.should == :draw
  img._reset!
end

#see_image_not_drawn(img) ⇒ Object



371
372
373
# File 'lib/gamebox/spec/helper.rb', line 371

def see_image_not_drawn(img)
  img.calls.should be_empty
end

#see_no_actor_attrs(actor_type, *attrs) ⇒ Object



426
427
428
429
430
# File 'lib/gamebox/spec/helper.rb', line 426

def see_no_actor_attrs(actor_type, *attrs)
  act = game.actor(actor_type)
  act.should be
  act.should have_no_attrs(attrs)
end

#see_stage_ivars(ivar_hash) ⇒ Object



400
401
402
403
404
# File 'lib/gamebox/spec/helper.rb', line 400

def see_stage_ivars(ivar_hash)
  ivar_hash.each do |name, val|
    game.current_stage.instance_variable_get("@#{name}").should == val
  end
end

#see_text_drawn(text, opts) ⇒ Object



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/gamebox/spec/helper.rb', line 375

def see_text_drawn(text, opts)
  font = opts[:in]
  font.calls.should_not be_empty
  first_call = font.calls.first

  first_call[0].should == :draw
  first_call[1].to_s.should == text
  first_call[2].should == opts[:x] if opts[:x]
  first_call[3].should == opts[:y] if opts[:y]
  first_call[4].should == opts[:z] if opts[:z]
  first_call[5].should == opts[:x_scale] if opts[:x_scale]
  first_call[6].should == opts[:y_scale] if opts[:y_scale]
  first_call[7].should == opts[:color] if opts[:color]

  font._reset!
end

#unpauseObject



410
411
412
# File 'lib/gamebox/spec/helper.rb', line 410

def unpause
  game.current_stage.unpause
end

#update(time, opts = {}) ⇒ Object



432
433
434
435
436
437
438
439
440
441
# File 'lib/gamebox/spec/helper.rb', line 432

def update(time, opts={})
  step = opts[:step] || time

  num_updates = time / step
  num_updates.times do
    gosu.update step
  end
  left_over = time % step
  gosu.update left_over unless left_over == 0
end