Sha256: 2c485dc9396c26a70b34b9ac0744c1fc6d4402f5487eeb7c724eeea7271eab32

Contents?: true

Size: 1.81 KB

Versions: 36

Compression:

Stored size: 1.81 KB

Contents

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

describe ShortLived do
  
  before(:all) do
    @window = stub :window
  end
  
  class SuperClass; def initialize(*); end; end
  
  module ThreadedMock
    def threaded lifetime
      # TODO
    end
  end
  
  def self.threaded_mock expected
    
  end
  
  context 'lifetime given as block' do
    before(:each) do
      @short_lived_class = Class.new(SuperClass) do
        include ShortLived
        
        lifetime { 10 + 10 }
        
        def threaded(*); end
      end
    end
    it "should define a method lifetime which returns the result of the block" do
      @short_lived_class.new(@window).lifetime.should == 20
    end
  end
  context 'lifetime given normally' do
    before(:each) do
      @short_lived_class = Class.new(SuperClass) do
        include ShortLived
        
        lifetime 30
        
        def threaded(*); end
      end
    end
    it "should define a method lifetime which returns the set value" do
      @short_lived_class.new(@window).lifetime.should == 30
    end
  end
  context 'no lifetime given – what now?' do
    before(:each) do
      @short_lived_class = test_class_with ShortLived
    end
    it "should raise a LifetimeMissingError" do
      lambda { @short_lived_class.new(@window) }.should raise_error(ShortLived::LifetimeMissingError)
    end
    it "should raise with the right message" do
      lambda { @short_lived_class.new(@window) }.should raise_error(ShortLived::LifetimeMissingError, <<-MESSAGE
        A ShortLived thing must define method
          lifetime lifetime = nil, &block
        with either params
          lifetime 74 # some value
        or
          lifetime { 50 + rand(50) } # some block
        to define how long the thing should live until it is destroyed.
      MESSAGE
      )
    end
  end
  
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
gosu_extensions-0.1.27 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.26 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.25 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.24 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.23 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.22 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.21 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.20 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.19 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.18 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.17 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.16 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.15 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.14 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.13 spec/lib/traits/short_lived_spec.rb
gosu_extensions-0.1.12 spec/lib/traits/short_lived_spec.rb