Sha256: dd200e099fde09927681d82c8af6b614196941f3f800979a8c5ca52efeb0a643

Contents?: true

Size: 1.95 KB

Versions: 6

Compression:

Stored size: 1.95 KB

Contents

require 'assert'
require 'assert/assertions'

require 'assert/utils'

module Assert::Assertions

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

    desc "`assert_respond_to`"
    setup do
      desc = @desc = "assert respond to fail desc"
      args = @args = [ :abs, "1", desc ]
      @test = Factory.test do
        assert_respond_to(:abs, 1) # pass
        assert_respond_to(*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]}\n"\
            "Expected #{Assert::U.show(@args[1], @c)} (#{@args[1].class})"\
            " to respond to `#{@args[0]}`."
      assert_equal exp, test_run_results(:fail).first.message
    end

  end

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

    desc "`assert_not_respond_to`"
    setup do
      desc = @desc = "assert not respond to fail desc"
      args = @args = [ :abs, 1, desc ]
      @test = Factory.test do
        assert_not_respond_to(*args)     # fail
        assert_not_respond_to(:abs, "1") # 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]}\n"\
            "Expected #{Assert::U.show(@args[1], @c)} (#{@args[1].class})"\
            " to not respond to `#{@args[0]}`."
      assert_equal exp, test_run_results(:fail).first.message
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
assert-2.16.5 test/unit/assertions/assert_respond_to_tests.rb
assert-2.16.4 test/unit/assertions/assert_respond_to_tests.rb
assert-2.16.3 test/unit/assertions/assert_respond_to_tests.rb
assert-2.16.2 test/unit/assertions/assert_respond_to_tests.rb
assert-2.16.1 test/unit/assertions/assert_respond_to_tests.rb
assert-2.16.0 test/unit/assertions/assert_respond_to_tests.rb