Sha256: d4c4e6642239a0a9084266bf783d0a967a01d85e564ad5067b4415938d277948

Contents?: true

Size: 1.07 KB

Versions: 25

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'
require 'sugar-high/properties'

class CruiseShip
  extend Properties
  
  property :direction
  property :speed, is(0..300)
end

describe 'Properties pack' do
  let (:ship) { CruiseShip.new }

  before do
    ship.add_direction_listener(lambda {|x| puts "Oy... someone changed the direction to #{x}"})  
  end
  
  it 'should listen and react when changing direction' do
    ship.direction = "north"
  end
  
  it 'should listen and react when changing speed' do
    ship.add_speed_listener(lambda {|x| puts "Oy... someone changed the speed to #{x}"})
    ship.add_speed_listener(lambda {|x| puts "Yo, dude... someone changed the speed to #{x}"})
  end

  it 'should reflect on speed settings if in range or not' do    
    ship.speed = 200
    ship.speed = 300
    ship.speed = 301
    ship.speed = -1
    ship.speed = 2000
    
    puts ship.direction
    puts ship.speed    
  end
  
  it 'should remove listener' do
    ship.remove_speed_listener(1)
    ship.speed = 200
    ship.speed = 350    
    
    puts ship.direction
    puts ship.speed        
  end
end


Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
sugar-high-0.6.3 spec/sugar-high/properties_spec.rb
sugar-high-0.6.2.1 spec/sugar-high/properties_spec.rb
sugar-high-0.6.1 spec/sugar-high/properties_spec.rb
sugar-high-0.6.0 spec/sugar-high/properties_spec.rb
sugar-high-0.5.5 spec/sugar-high/properties_spec.rb
sugar-high-0.5.4 spec/sugar-high/properties_spec.rb
sugar-high-0.5.3 spec/sugar-high/properties_spec.rb
sugar-high-0.5.1 spec/sugar-high/properties_spec.rb
sugar-high-0.5.0 spec/sugar-high/properties_spec.rb
sugar-high-0.4.9.5 spec/sugar-high/properties_spec.rb
sugar-high-0.4.9.3 spec/sugar-high/properties_spec.rb
sugar-high-0.4.9.2 spec/sugar-high/properties_spec.rb
sugar-high-0.4.9.1 spec/sugar-high/properties_spec.rb
sugar-high-0.4.9 spec/sugar-high/properties_spec.rb
sugar-high-0.4.8 spec/sugar-high/properties_spec.rb
sugar-high-0.4.7 spec/sugar-high/properties_spec.rb
sugar-high-0.4.6.4 spec/sugar-high/properties_spec.rb
sugar-high-0.4.6.3 spec/sugar-high/properties_spec.rb
sugar-high-0.4.6.2 spec/sugar-high/properties_spec.rb
sugar-high-0.4.6.1 spec/sugar-high/properties_spec.rb