Sha256: 2c871e27ca962036076a59e239343761abacda3bfdeeec3d9896401b148acc7f

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require "assert"
require "assert/assertions"

require "assert/utils"

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

    desc "`assert_match`"
    subject {
      args = args1
      Factory.test do
        assert_match(/a/, "a string") # pass
        assert_match(*args)           # fail
      end
    }

    let(:desc1) { "assert match fail desc" }
    let(:args1) { ["not", "a string", desc1] }
    let(:config1) { subject.config }

    should "produce results as expected" do
      subject.run(&test_run_callback)

      assert_that(test_run_result_count).equals(2)
      assert_that(test_run_result_count(:pass)).equals(1)
      assert_that(test_run_result_count(:fail)).equals(1)

      exp =
        "#{args1[2]}\nExpected #{Assert::U.show(args1[1], config1)}"\
        " to match #{Assert::U.show(args1[0], config1)}."
      assert_that(test_run_results(:fail).first.message).equals(exp)
    end
  end

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

    desc "`assert_not_match`"
    subject {
      args = args1
      Factory.test do
        assert_not_match(*args)             # fail
        assert_not_match("not", "a string") # pass
      end
    }

    let(:desc1) { "assert not match fail desc" }
    let(:args1) { [/a/, "a string", desc1] }
    let(:config1) { subject.config }

    should "produce results as expected" do
      subject.run(&test_run_callback)

      assert_that(test_run_result_count).equals(2)
      assert_that(test_run_result_count(:pass)).equals(1)
      assert_that(test_run_result_count(:fail)).equals(1)

      exp =
        "#{args1[2]}\nExpected #{Assert::U.show(args1[1], config1)}"\
        " to not match #{Assert::U.show(args1[0], config1)}."
      assert_that(test_run_results(:fail).first.message).equals(exp)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
assert-2.19.0 test/unit/assertions/assert_match_tests.rb
assert-2.18.4 test/unit/assertions/assert_match_tests.rb