class Test::Unit::TestAssertions::TestAssertEqual::TestSystemMessage

Public Instance Methods

inspect() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 292
def inspect
  "inspected"
end
test_different_encoding() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 387
          def test_different_encoding
            utf8_string = "こんにちは"
            unless utf8_string.respond_to?(:force_encoding)
              omit("encoding test is for Ruby >= 1.9")
            end
            ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
            message = <<-EOM.chomp
<#{utf8_string.inspect}>("UTF-8") expected but was
<#{ascii_8bit_string.inspect}>("ASCII-8BIT").
EOM
            check_fail(message) do
              assert_equal(utf8_string, ascii_8bit_string)
            end
          end
test_different_hash() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 402
          def test_different_hash
            designers = {
              "Ruby" => "Matz",
              "Lisp" => "John McCarthy",
            }
            categories = {
              "LL" => ["Ruby", "Python"],
              "Heavy" => ["C", "C++"],
            }
            message = <<-EOM.chomp
<{"Lisp"=>"John McCarthy", "Ruby"=>"Matz"}> expected but was
<{"Heavy"=>["C", "C++"], "LL"=>["Ruby", "Python"]}>.
EOM
            check_fail(message) do
              assert_equal(designers, categories)
            end
          end
test_different_type() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 224
          def test_different_type
            message = <<-EOM.chomp
<"111111"> expected but was
<111111>.

diff:
- "111111"
? -      -
+ 111111
EOM
            check_fail(message) do
              assert_equal("111111", 111111)
            end
          end
test_large_string() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 322
          def test_large_string
            message = <<-EOM.chomp
<#{AssertionMessage.convert("a\n" + "x" * 997)}> expected but was
<#{AssertionMessage.convert("x")}>.

diff:
+ x
- a
- #{"x" * 997}

folded diff:
+ x
- a
#{(["- " + ("x" * 78)] * 12).join("\n")}
- #{"x" * 61}
EOM
            check_fail(message) do
              assert_equal("a\n" + "x" * 997, "x")
            end

            message = <<-EOM.chomp
<#{AssertionMessage.convert("a\n" + "x" * 998)}> expected but was
<#{AssertionMessage.convert("x")}>.
EOM
            check_fail(message) do
              assert_equal("a\n" + "x" * 998, "x")
            end
          end
test_long_line() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 239
          def test_long_line
            expected = ["0123456789",
                        "1123456789",
                        "2123456789",
                        "3123456789",
                        "4123456789",
                        "5123456789",
                        "6123456789",
                        "7123456789",
                        "8123456789"].join
            actual =   ["0000000000",
                        "1123456789",
                        "2123456789",
                        "3123456789",
                        "4123456789",
                        "5123456789",
                        "6123456789",
                        "7123456789",
                        "8123456789"].join
            message = <<-EOM.chomp
<"#{expected}"> expected but was
<"#{actual}">.

diff:
- #{expected}
?  ^^^^^^^^^
+ #{actual}
?  ^^^^^^^^^

folded diff:
- 012345678911234567892123456789312345678941234567895123456789612345678971234567
?  ^^^^^^^^^
+ 000000000011234567892123456789312345678941234567895123456789612345678971234567
?  ^^^^^^^^^
  898123456789
EOM
            check_fail(message) do
              assert_equal(expected, actual)
            end
          end
test_max_diff_target_string_size() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 351
          def test_max_diff_target_string_size
            key = "TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"
            before_value = ENV[key]
            ENV[key] = "100"
            begin
              message = <<-EOM.chomp
<#{AssertionMessage.convert("a\n" + "x" * 97)}> expected but was
<#{AssertionMessage.convert("x")}>.

diff:
+ x
- a
- #{"x" * 97}

folded diff:
+ x
- a
#{(["- " + ("x" * 78)]).join("\n")}
- #{"x" * 19}
EOM
              check_fail(message) do
                assert_equal("a\n" + "x" * 97, "x")
              end

              message = <<-EOM.chomp
<#{AssertionMessage.convert("a\n" + "x" * 98)}> expected but was
<#{AssertionMessage.convert("x")}>.
EOM
              check_fail(message) do
                assert_equal("a\n" + "x" * 98, "x")
              end
            ensure
              ENV[key] = before_value
            end
          end
test_multi_lines_result() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 307
          def test_multi_lines_result
            message = <<-EOM.chomp
<#{AssertionMessage.convert("a\nb")}> expected but was
<#{AssertionMessage.convert("x")}>.

diff:
+ x
- a
- b
EOM
            check_fail(message) do
              assert_equal("a\nb", "x")
            end
          end
test_numeric() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 440
          def test_numeric
            numeric_family_class = Class.new(Numeric) do
              def inspect
                "inspect is called"
              end

              def to_s
                "to_s is called"
              end
            end
            numeric = numeric_family_class.new

            message = <<-MESSAGE.chomp
<to_s is called> expected but was
<"must be failed">.
            MESSAGE
            check_fail(message) do
              assert_equal(numeric, "must be failed")
            end
          end
test_recursive_hash() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 420
          def test_recursive_hash
            alice = {"name" => "Alice"}
            bob = {"name" => "Bob"}
            alice["followers"] = [bob]
            bob["followers"] = [alice]
            message = <<-EOM.chomp
<{"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}> expected but was
<{"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}>.

diff:
- {"followers"=>[{"followers"=>[{...}], "name"=>"Bob"}], "name"=>"Alice"}
?                                       -----------------
+ {"followers"=>[{"followers"=>[{...}], "name"=>"Alice"}], "name"=>"Bob"}
?                                                       +++++++++++++++++
EOM
            check_fail(message) do
              assert_equal(alice, bob)
            end
          end
test_same_inspected_objects() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 290
          def test_same_inspected_objects
            same_inspected_class = Class.new do
              def inspect
                "inspected"
              end
            end
            object1 = same_inspected_class.new
            object2 = same_inspected_class.new
            message = <<-EOM.chomp
<inspected> expected but was
<inspected>.
EOM
            check_fail(message) do
              assert_equal(object1, object2)
            end
          end
test_too_small_difference() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 280
          def test_too_small_difference
            message = <<-EOM.chomp
<1> expected but was
<2>.
EOM
            check_fail(message) do
              assert_equal(1, 2)
            end
          end
to_s() click to toggle source
# File test-unit-3.3.4/test/test-assertions.rb, line 446
def to_s
  "to_s is called"
end