Sha256: c78b823ac8d1ab94c86133e6ad6cc7c9d5b39f23d53567839e67cc5c71c059e8

Contents?: true

Size: 1.7 KB

Versions: 12

Compression:

Stored size: 1.7 KB

Contents

require 'assert'
require 'assert/assertions'

module Assert::Assertions

  class AssertKindOfTests < Assert::Context
    desc "the assert_kind_of helper"
    setup do
      desc = @desc = "assert kind of fail desc"
      args = @args = [ Array, "object", desc ]
      @test = Factory.test do
        assert_kind_of(String, "object") # pass
        assert_kind_of(*args)            # fail
      end
      @test.run
    end
    subject{ @test }

    should "produce results as expected" do
      assert_equal 2, subject.result_count
      assert_equal 1, subject.result_count(:pass)
      assert_equal 1, subject.result_count(:fail)
    end

    should "have a fail message with custom and generic explanations" do
      exp = "#{@args[2]}\nExpected #{@args[1].inspect} (#{@args[1].class}) to"\
            " be a kind of #{@args[0]}."
      assert_equal exp, subject.fail_results.first.message
    end

  end

  class AssertNotKindOfTests < Assert::Context
    desc "the assert_not_kind_of helper"
    setup do
      desc = @desc = "assert not kind of fail desc"
      args = @args = [ String, "object", desc ]
      @test = Factory.test do
        assert_not_kind_of(*args)           # fail
        assert_not_kind_of(Array, "object") # pass
      end
      @test.run
    end
    subject{ @test }

    should "produce results as expected" do
      assert_equal 2, subject.result_count
      assert_equal 1, subject.result_count(:pass)
      assert_equal 1, subject.result_count(:fail)
    end

    should "have a fail message with custom and generic explanations" do
      exp = "#{@args[2]}\n#{@args[1].inspect} not expected to be a kind of #{@args[0]}."
      assert_equal exp, subject.fail_results.first.message
    end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
assert-2.3.3 test/unit/assertions/assert_kind_of_tests.rb
assert-2.3.2 test/unit/assertions/assert_kind_of_tests.rb
assert-2.3.1 test/unit/assertions/assert_kind_of_tests.rb
assert-2.3.0 test/unit/assertions/assert_kind_of_tests.rb
assert-2.2.0 test/unit/assertions/assert_kind_of_tests.rb
assert-2.1.2 test/unit/assertions/assert_kind_of_tests.rb
assert-2.1.1 test/unit/assertions/assert_kind_of_tests.rb
assert-2.1.0 test/unit/assertions/assert_kind_of_tests.rb
assert-2.0.3 test/unit/assertions/assert_kind_of_tests.rb
assert-2.0.2 test/unit/assertions/assert_kind_of_tests.rb
assert-2.0.1 test/unit/assertions/assert_kind_of_tests.rb
assert-2.0.0 test/unit/assertions/assert_kind_of_tests.rb