spec/hooks_spec.rb in maintain-0.1.6 vs spec/hooks_spec.rb in maintain-0.1.7
- old
+ new
@@ -2,11 +2,11 @@
require 'lib/maintain'
describe Maintain, "hooks" do
before :each do
- class MaintainTest
+ class ::MaintainTest
extend Maintain
end
end
it "should allow me to hook into entry and exit" do
@@ -39,6 +39,24 @@
maintain.state = :old
maintain.should_not_receive(:old_entered)
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
\ No newline at end of file