Sha256: 1a29300e3f9c6a68646505df64634f3b4a0418c1dec94990f1dbbe3cf4ba6220

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

class TestShell < Test::Unit::TestCase
  
  context "A shell instance, @shell" do
    setup do
      @shell = ChronoTrigger::Shell.new
    end
    
    should "return an empty array on call to triggers" do
      assert_equal [], @shell.triggers
    end

    should "raise an exception unless a block is provided to #trigger" do
      assert_raise(ChronoTrigger::ConfigurationException) { @shell.trigger("test trigger") }
    end

    context "when provided a valid block" do
      setup do
        @trigger = @shell.trigger("name") { runs { "x" } }
      end
      
      should "create a new trigger" do
        assert_equal 1, @shell.triggers.size
      end
      
      should "create a trigger that will run x with execute" do
        assert_equal "x", @shell.triggers.first.execute
      end
      
      context "and configured to run the next time shell.execute_triggers is called" do
        setup do
          ChronoTrigger::CronEntry.any_instance.stubs(:matches?).returns(true)
        end
        
        should "execute the code block" do
          @trigger.expects(:execute)
          @shell.execute_triggers
        end
      end #and configured to run the next time shell.execute_triggers is called
    end #when provided a valid block
    
    context "calling load_context with a valid trigger file" do
      setup do
        @shell.load_triggers(["test/triggers.rb"])
      end
      
      should "create 3 triggers" do
        assert_equal 3, @shell.triggers.size
      end
    end #calling load_context with a valid trigger file
  end #A shell instance, @shell
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chrono_trigger-0.2.1 test/test_shell.rb
chrono_trigger-0.2.0 test/test_shell.rb
chrono_trigger-0.1.7 test/test_shell.rb