Sha256: cbd8c38ec9eefca35b3732fa9e8d4bc58c4a6bbc47860b4e52ddc2732c7718bf

Contents?: true

Size: 1.42 KB

Versions: 15

Compression:

Stored size: 1.42 KB

Contents

# Hooks on state entrance / exit. Needs more attention.

require 'lib/maintain'

describe Maintain, "hooks" do
  before :each do
    class ::MaintainTest
      extend Maintain
    end
  end

  it "should allow me to hook into entry and exit" do
    lambda {
      MaintainTest.maintain :state do
        state :new, :enter => :new_entered
        state :old, :enter => :old_entered
        on :enter, :new, :new_entered
        on :exit, :old do
          self.old_entered
        end
      end
    }.should_not raise_error
  end

  it "should execute hooks when states are entered and exited" do
    MaintainTest.maintain :state do
      state :new
      state :old
      on :enter, :new, :new_entered
      on :enter, :old do
        self.old_entered
      end
    end

    maintain = MaintainTest.new
    maintain.should_receive(:new_entered)
    maintain.state = :new
    maintain.should_receive(:old_entered).once
    maintain.state = :old
    maintain.state = :old
  end

  describe "guarding" do
    it "should prevent hooks from running when they return false" do
      MaintainTest.maintain :state do
        state :new
        state :old
        on :enter, :new, :new_entered, :if => :run_hook?
      end

      maintain = MaintainTest.new
      def maintain.run_hook?
        false
      end
      maintain.should_not_receive(:new_entered)
      maintain.state = :new
      maintain.state = :old
      maintain.state = :old
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
maintain-0.2.17 spec/hooks_spec.rb
maintain-0.2.16 spec/hooks_spec.rb
maintain-0.2.15 spec/hooks_spec.rb
maintain-0.2.14 spec/hooks_spec.rb
maintain-0.2.13 spec/hooks_spec.rb
maintain-0.2.12 spec/hooks_spec.rb
maintain-0.2.11 spec/hooks_spec.rb
maintain-0.2.10 spec/hooks_spec.rb
maintain-0.2.9 spec/hooks_spec.rb
maintain-0.2.8 spec/hooks_spec.rb
maintain-0.2.6 spec/hooks_spec.rb
maintain-0.2.5 spec/hooks_spec.rb
maintain-0.2.4 spec/hooks_spec.rb
maintain-0.2.2 spec/hooks_spec.rb
maintain-0.2.1 spec/hooks_spec.rb