Sha256: 3f4bd7cc0ce90c3397fb6f2142b83ef726afa645b98fae9279f572a0dc073d0b

Contents?: true

Size: 985 Bytes

Versions: 3

Compression:

Stored size: 985 Bytes

Contents

require 'assert'
require 'cap-util/unset_var'

module CapUtil::UnsetVar

  class UnitTests < Assert::Context
    desc "CapUtil::UnsetVar"
    setup do
      @var_name = 'test'
      @unset = CapUtil::UnsetVar.new(@var_name)
    end
    subject{ @unset }

    should "be a proc" do
      assert_kind_of ::Proc, subject
    end

    should "raise `Halted` when called" do
      assert_raises(CapUtil::Halted) { subject.call }
    end

    should "raise with a default msg based on the variable name" do
      exp_msg = ":#{@var_name} var not set."
      begin
        subject.call
      rescue CapUtil::Halted => err
        assert_match exp_msg, err.message
      end
    end

    should "accept a custom msg to raise with" do
      exp_msg = ":#{@var_name} var not set (a custom err msg)."
      unset = CapUtil::UnsetVar.new(@var_name, exp_msg)
      begin
        unset.call
      rescue CapUtil::Halted => err
        assert_match exp_msg, err.message
      end
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cap-util-1.5.2 test/unit/unset_var_tests.rb
cap-util-1.5.1 test/unit/unset_var_tests.rb
cap-util-1.5.0 test/unit/unset_var_tests.rb