Sha256: 651c38371365416cb4ddbc8a6400e1c41314f3fa9b9c732dd6784947f48de111

Contents?: true

Size: 1.75 KB

Versions: 12

Compression:

Stored size: 1.75 KB

Contents

require File.expand_path("#{File.dirname(__FILE__)}/../helper")

##
##
##

describe "Common features / functionality for StateFu::State & StateFu::Event" do

  include MySpecHelper
  Sprocket = StateFu::Sprocket
  before do
    @machine = StateFu::Machine.new
  end

  describe "calling Sprocket.new" do
    it "should create a new Sprocket given valid args" do
      sprocket = Sprocket.new(@machine, :flux, { :meta => :doodle })
      sprocket.should be_kind_of( Sprocket )
      sprocket.name.should == :flux
      sprocket.options[:meta].should == :doodle
      sprocket.machine.should == @machine
    end
  end

  describe "instance methods" do
    before do
      @sprocket = Sprocket.new(@machine, :flux, {:meta => "wibble"})
    end

    describe ".apply!" do

      it "should yield itself if the block's arity is 1" do
        yielded = false
        @sprocket.apply!{ |s| yielded = s  }
        yielded.should == @sprocket
      end

      it "should instance_eval the block if its arity is 0/-1" do
        yielded = false
        @sprocket.apply!{ yielded = self }
        yielded.should == @sprocket
      end
      
      it "should merge any options passed into .options" do
        opts    = @sprocket.options
        newopts =  { :size => "huge", :colour => "orange" }
        @sprocket.apply!( newopts )
        @sprocket.options.should == opts.merge(newopts)
      end

      it "should instance_eval the block if one is passed" do
        ref = nil
        @sprocket.apply!(){ ref = self }
        ref.should == @sprocket
      end

      it "should return itself" do
        @sprocket.apply!.should == @sprocket
      end
    end

    describe "to_sym" do
      it "should return its name" do
        @sprocket.to_sym.should == @sprocket.name
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
davidlee-state-fu-0.10.0 spec/units/sprocket_spec.rb
davidlee-state-fu-0.11.0 spec/units/sprocket_spec.rb
davidlee-state-fu-0.11.1 spec/units/sprocket_spec.rb
davidlee-state-fu-0.12.0 spec/units/sprocket_spec.rb
davidlee-state-fu-0.12.1 spec/units/sprocket_spec.rb
state-fu-0.13.4 spec/units/sprocket_spec.rb
state-fu-0.13.3 spec/units/sprocket_spec.rb
state-fu-0.13.1 spec/units/sprocket_spec.rb
state-fu-0.13.0 spec/units/sprocket_spec.rb
state-fu-0.12.3 spec/units/sprocket_spec.rb
state-fu-0.12.1 spec/units/sprocket_spec.rb
state-fu-0.11.1 spec/units/sprocket_spec.rb