Sha256: 2aca71fd19ddf5d99c1caf6df80bd89394725f04f3c03e585ce632029513ff38

Contents?: true

Size: 1.55 KB

Versions: 6

Compression:

Stored size: 1.55 KB

Contents

require File.join(File.dirname(__FILE__), '/../../spec_helper')

describe Turnable do
  
  describe "Constants" do
    it "should have turn left" do
      Turnable::Left.should == :turn_left
    end
    it "should have turn right" do
      Turnable::Right.should == :turn_right
    end
  end
  
  context 'default' do
    before(:each) do
      @turnable = Class.new do
        include Turnable
      end.new 
    end
    describe "turn_speed" do
      it "should have a defined turn_speed method" do
        lambda { @turnable.turn_speed }.should_not raise_error
      end
      it "should return the class defined turn_speed" do
        @turnable.turn_speed.should == 0.5
      end
    end
  end
  
  context 'non-default' do
    before(:each) do
      @turnable = Class.new do
        include Turnable
        
        turn_speed 1.3
      end.new
      @turnable.stub! :rotation => 1.0
    end
    
    describe "turn_speed" do
      it "should have a defined turn_speed method" do
        lambda { @turnable.turn_speed }.should_not raise_error
      end
      it "should return the class defined turn_speed" do
        @turnable.turn_speed.should == 1.3
      end
    end
  
    describe "turn_left" do
      it "should subtract an amount from the rotation" do
        @turnable.should_receive(:rotation=).once.with 0.987
        
        @turnable.turn_left
      end
    end
    describe "turn_right" do
      it "should add an amount to the rotation" do
        @turnable.should_receive(:rotation=).once.with 1.013
        
        @turnable.turn_right
      end
    end
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gosu_extensions-0.3.8 spec/lib/traits/turnable_spec.rb
gosu_extensions-0.3.7 spec/lib/traits/turnable_spec.rb
gosu_extensions-0.3.6 spec/lib/traits/turnable_spec.rb
gosu_extensions-0.3.5 spec/lib/traits/turnable_spec.rb
gosu_extensions-0.3.4 spec/lib/traits/turnable_spec.rb
gosu_extensions-0.3.3 spec/lib/traits/turnable_spec.rb