Sha256: 25eeb9bac547793b0f2a4801cb703ffc13cc3ead7fc60b4123b6e06b14a55844

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

require "assert"
require "assert/assertions"

require "assert/utils"

module Assert::Assertions

  class AssertMatchTests < Assert::Context
    include Assert::Test::TestHelpers

    desc "`assert_match`"
    setup do
      desc = @desc = "assert match fail desc"
      args = @args = ["not", "a string", desc]
      @test = Factory.test do
        assert_match(/a/, "a string") # pass
        assert_match(*args)           # fail
      end
      @c = @test.config
      @test.run(&test_run_callback)
    end
    subject{ @test }

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

    should "have a fail message with custom and generic explanations" do
      exp = "#{@args[2]}\nExpected #{Assert::U.show(@args[1], @c)}"\
            " to match #{Assert::U.show(@args[0], @c)}."
      assert_equal exp, test_run_results(:fail).first.message
    end

  end

  class AssertNotMatchTests < Assert::Context
    include Assert::Test::TestHelpers

    desc "`assert_not_match`"
    setup do
      desc = @desc = "assert not match fail desc"
      args = @args = [/a/, "a string", desc]
      @test = Factory.test do
        assert_not_match(*args)             # fail
        assert_not_match("not", "a string") # pass
      end
      @c = @test.config
      @test.run(&test_run_callback)
    end
    subject{ @test }

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

    should "have a fail message with custom and generic explanations" do
      exp = "#{@args[2]}\nExpected #{Assert::U.show(@args[1], @c)}"\
            " to not match #{Assert::U.show(@args[0], @c)}."
      assert_equal exp, test_run_results(:fail).first.message
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
assert-2.17.0 test/unit/assertions/assert_match_tests.rb