Sha256: d8f95bcc06c9f0210f5d64cb38864c68fe5a449b06cbce2b7ac5b7a2963bce3a

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 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

4 entries across 4 versions & 1 rubygems

Version Path
sugar-high-0.7.3 spec/sugar-high/properties_spec.rb
sugar-high-0.7.2 spec/sugar-high/properties_spec.rb
sugar-high-0.7.1 spec/sugar-high/properties_spec.rb
sugar-high-0.7.0 spec/sugar-high/properties_spec.rb