Best Test_xml_ruby code snippet using Assertions.diff
test-diff.rb
Source:test-diff.rb
...170 def test_ratio171 assert_ratio(0.75, "abcd", "bcde")172 assert_ratio(0.80, "efg", "eg")173 end174 def test_1_length_readable_diff175 differ = Test::Unit::Diff::ReadableDiffer.new(["0"], ["1"])176 def differ.cut_off_ratio177 0178 end179 def differ.default_ratio180 0181 end182 assert_equal("- 0\n" +183 "? ^\n" +184 "+ 1\n" +185 "? ^",186 differ.diff.join("\n"))187 end188 def test_same_contents_readable_diff189 assert_readable_diff(" aaa", ["aaa"], ["aaa"])190 assert_readable_diff(" aaa\n" \191 " bbb",192 ["aaa", "bbb"], ["aaa", "bbb"])193 end194 def test_deleted_readable_diff195 assert_readable_diff(" aaa\n" \196 "- bbb",197 ["aaa", "bbb"], ["aaa"])198 assert_readable_diff(" aaa\n" \199 "- bbb\n" \200 "- ccc\n" \201 "- ddd",202 ["aaa", "bbb", "ccc", "ddd"], ["aaa"])203 end204 def test_inserted_readable_diff205 assert_readable_diff(" aaa\n" \206 "+ bbb\n" \207 "+ ccc\n" \208 "+ ddd",209 ["aaa"], ["aaa", "bbb", "ccc", "ddd"])210 end211 def test_replace_readable_diff212 assert_readable_diff(" aaa\n" \213 "- bbb\n" \214 "+ BbB\n" \215 " ccc\n" \216 "- ddd\n" \217 "- efg\n" \218 "? -\n" \219 "+ eg",220 ["aaa", "bbb", "ccc", "ddd", "efg"],221 ["aaa", "BbB", "ccc", "eg"])222 assert_readable_diff("- abcd xyz abc\n" \223 "? -\n" \224 "+ abcd abcd xyz abc\n" \225 "? +++++",226 [" abcd xyz abc"],227 ["abcd abcd xyz abc"])228 end229 def test_difference_readable_diff230 assert_readable_diff("- 1 tests, 0 assertions, 1 failures, 0 pendings\n" \231 "? ^ ^\n" \232 "+ 1 tests, 0 assertions, 0 failures, 1 pendings\n" \233 "? ^ ^",234 ["1 tests, 0 assertions, 1 failures, 0 pendings"],235 ["1 tests, 0 assertions, 0 failures, 1 pendings"])236 end237 def test_complex_readable_diff238 assert_readable_diff(" aaa\n" \239 "- bbb\n" \240 "- ccc\n" \241 "+ \n" \242 "+ # \n" \243 " ddd",244 ["aaa", "bbb", "ccc", "ddd"],245 ["aaa", "", " # ", "ddd"])246 assert_readable_diff("- one1\n" \247 "? ^\n" \248 "+ ore1\n" \249 "? ^\n" \250 "- two2\n" \251 "- three3\n" \252 "? - -\n" \253 "+ tree\n" \254 "+ emu",255 ["one1", "two2", "three3"],256 ["ore1", "tree", "emu"])257 end258 def test_empty_readable_diff259 assert_readable_diff("", [""], [""])260 end261 def test_unified_diff262 assert_unified_diff("",263 ["one", "two", "three"],264 ["one", "two", "three"],265 "content 1",266 "content 2")267 assert_unified_diff("--- Original Sat Jan 26 23:30:50 1991\n" \268 "+++ Current Fri Jun 06 10:20:52 2003\n" \269 "@@ -1,4 +1,4 @@\n" \270 "+zero\n" \271 " one\n" \272 "-two\n" \273 "-three\n" \274 "+tree\n" \275 " four",276 ["one", "two", "three", "four"],277 ["zero", "one", "tree", "four"],278 "Original Sat Jan 26 23:30:50 1991",279 "Current Fri Jun 06 10:20:52 2003",280 :show_context => false)281 from = File.read(__FILE__).split(/\n/)282 to = from.dup283 target_line = __LINE__284 to[target_line - 1, 1] = []285 context = " def test_unified_diff"286 summary = "@@ -#{target_line - 3},7 +#{target_line - 3},6 @@ #{context}"287 assert_unified_diff((["--- revision 10",288 "+++ revision 11",289 summary] +290 from[target_line - 4, 3].collect {|line| " #{line}"} +291 ["-#{from[target_line - 1]}"] +292 from[target_line, 3].collect {|line| " #{line}"}293 ).join("\n"),294 from, to,295 "revision 10",296 "revision 11")297 end298 def test_empty_unified_diff299 assert_unified_diff("", [""], [""], "From", "To")300 assert_unified_diff("", [], [], "From", "To")301 end302 def test_diff_lines303 assert_diff_lines(["- ddd",304 "- efg",305 "? -",306 "+ eg"],307 ["aaa", "bbb", "ccc", "ddd", "efg"],308 ["aaa", "BbB", "ccc", "eg"],309 3, 5, 3, 4)310 end311 def test_diff_line312 assert_diff_line(["- abcDefghiJkl",313 "? ^ ^ ^",314 "+ abcdefGhijkl",315 "? ^ ^ ^"],316 "abcDefghiJkl",317 "abcdefGhijkl")318 assert_diff_line(["- bcDefghiJklx",319 "? ^ ^ ^ -",320 "+ abcdefGhijkl",321 "? + ^ ^ ^"],322 "bcDefghiJklx",323 "abcdefGhijkl")324 end325 def test_empty_diff_line326 assert_diff_line(["- ",327 "+ "],328 "", "")329 end330 def test_format_diff_point331 assert_format_diff_point(["- \tabcDefghiJkl",332 "? \t ^ ^ ^",333 "+ \t\tabcdefGhijkl",334 "? \t ^ ^ ^"],335 "\tabcDefghiJkl",336 "\t\tabcdefGhijkl",337 " ^ ^ ^ ",338 "+ ^ ^ ^ ")339 assert_format_diff_point(["- efg",340 "? ^",341 "+ eg"],342 "efg",343 "eg",344 " ^",345 "")346 end347 def test_interesting_line348 from = ["class X",349 " def find(x=0)",350 " body",351 " end",352 "end"]353 to = ["def xxx",354 " raise 'not call me'",355 "end"]356 assert_interesting_line(" def find(x=0)",357 from, to,358 2, 1)359 assert_interesting_line("def xxx",360 from, to,361 2, 0)362 assert_interesting_line("class X",363 from, to,364 0, 0)365 end366 private367 def assert_found_binary_search_ranges(numeric, ranges)368 assert_true(Test::Unit::Diff::UTF8Line.send(:binary_search_ranges,369 numeric,370 ranges))371 end372 def assert_not_found_binary_search_ranges(numeric, ranges)373 assert_false(Test::Unit::Diff::UTF8Line.send(:binary_search_ranges,374 numeric,375 ranges))376 end377 def assert_to_indexes(expected, to, &junk_predicate)378 matcher = Test::Unit::Diff::SequenceMatcher.new([""], to, &junk_predicate)379 assert_equal(expected, matcher.instance_variable_get("@to_indexes"))380 end381 def assert_find_best_match_position(expected, from, to,382 from_start, from_end,383 to_start, to_end, &junk_predicate)384 matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)385 assert_equal(expected, matcher.send(:find_best_match_position,386 from_start, from_end,387 to_start, to_end))388 end389 def assert_longest_match(expected, from, to,390 from_start, from_end,391 to_start, to_end, &junk_predicate)392 matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)393 assert_equal(expected, matcher.longest_match(from_start, from_end,394 to_start, to_end))395 end396 def assert_matches(expected, from, to, &junk_predicate)397 matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)398 assert_equal(expected, matcher.send(:matches))399 end400 def assert_blocks(expected, from, to, &junk_predicate)401 matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)402 assert_equal(expected, matcher.blocks)403 end404 def assert_operations(expected, from, to, &junk_predicate)405 matcher = Test::Unit::Diff::SequenceMatcher.new(from, to, &junk_predicate)406 assert_equal(expected, matcher.operations)407 end408 def assert_grouped_operations(expected, from, to)409 matcher = Test::Unit::Diff::SequenceMatcher.new(from, to)410 assert_equal(expected, matcher.grouped_operations)411 end412 def assert_ratio(expected, from, to)413 matcher = Test::Unit::Diff::SequenceMatcher.new(from, to)414 assert_in_delta(expected, 0.001, matcher.ratio)415 end416 def assert_readable_diff(expected, from, to)417 assert_equal(expected,418 Test::Unit::Diff.readable(from.join("\n"), to.join("\n")))419 end420 def assert_unified_diff(expected, from, to, from_label, to_label, options={})421 options = options.merge(:from_label => from_label,422 :to_label => to_label)423 assert_equal(expected,424 Test::Unit::Diff.unified(from.join("\n"), to.join("\n"),425 options))426 end427 def assert_diff_lines(expected, from, to,428 from_start, from_end,429 to_start, to_end)430 differ = Test::Unit::Diff::ReadableDiffer.new(from, to)431 result = []432 differ.instance_variable_set("@result", result)433 differ.send(:diff_lines,434 from_start, from_end,435 to_start, to_end)436 assert_equal(expected, result)437 end438 def assert_diff_line(expected, from_line, to_line)439 differ = Test::Unit::Diff::ReadableDiffer.new([""], [""])440 result = []441 differ.instance_variable_set("@result", result)442 differ.send(:diff_line, from_line, to_line)443 assert_equal(expected, result)444 end445 def assert_format_diff_point(expected, from_line, to_line, from_tags, to_tags)446 differ = Test::Unit::Diff::ReadableDiffer.new([""], [""])447 result = []448 differ.instance_variable_set("@result", result)449 differ.send(:format_diff_point,450 from_line, to_line,451 from_tags, to_tags)452 assert_equal(expected, result)453 end454 def assert_interesting_line(expected, from, to, from_start, to_start)455 differ = Test::Unit::Diff::UnifiedDiffer.new(from, to)456 assert_equal(expected, differ.send(:find_interesting_line,457 from_start, to_start,458 :define_line?))459 end460end...
test_unit_diff.rb
Source:test_unit_diff.rb
2require 'rubygems'3require 'minitest/autorun'4require 'stringio'5$TESTING = true6require 'unit_diff'7class TestUnitDiff < MiniTest::Unit::TestCase8 def setup9 @diff = UnitDiff.new10 end11 def test_input12 header = "Loaded suite ./blah\nStarted\nFF\nFinished in 0.035332 seconds.\n\n"13 input = "#{header} 1) Failure:\ntest_test1(TestBlah) [./blah.rb:25]:\n<\"line1\\nline2\\nline3\\n\"> expected but was\n<\"line4\\nline5\\nline6\\n\">.\n\n 2) Failure:\ntest_test2(TestBlah) [./blah.rb:29]:\n<\"line1\"> expected but was\n<\"line2\\nline3\\n\\n\">.\n\n2 tests, 2 assertions, 2 failures, 0 errors\n"14 # TODO: I think I'd like a separate footer array as well15 expected = [[[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n", "<\"line1\\nline2\\nline3\\n\"> expected but was\n", "<\"line4\\nline5\\nline6\\n\">.\n"],16 [" 2) Failure:\n", "test_test2(TestBlah) [./blah.rb:29]:\n", "<\"line1\"> expected but was\n", "<\"line2\\nline3\\n\\n\">.\n"]],17 ["\n", "2 tests, 2 assertions, 2 failures, 0 errors\n"]]18 util_unit_diff(header, input, expected, :parse_input)19 end20 def test_input_miniunit21 header = "Loaded suite -e\nStarted\nF\nFinished in 0.035332 seconds.\n\n"22 input = "#{header} 1) Failure:23test_blah(TestBlah) [./blah.rb:25]:24Expected ['a', 'b', 'c'], not ['a', 'c', 'b'].251 tests, 1 assertions, 1 failures, 0 errors26"27 expected = [[[" 1) Failure:\n",28 "test_blah(TestBlah) [./blah.rb:25]:\n",29 "Expected ['a', 'b', 'c'], not ['a', 'c', 'b'].\n"]],30 ["\n", "1 tests, 1 assertions, 1 failures, 0 errors\n"]]31 util_unit_diff(header, input, expected, :parse_input)32 end33 def test_input_miniunit_multiline34 header = "Loaded suite -e\nStarted\nF\nFinished in 0.035332 seconds.\n\n"35 input = "#{header} 1) Failure:36test_blah(TestBlah) [./blah.rb:25]:37Expected ['a',38 'b',39 'c'], not ['a',40 'c',41 'b'].421 tests, 1 assertions, 1 failures, 0 errors43"44 expected = [[[" 1) Failure:\n",45 "test_blah(TestBlah) [./blah.rb:25]:\n",46 "Expected ['a',\n 'b',\n 'c'], not ['a',\n 'c',\n 'b'].\n"]],47 ["\n", "1 tests, 1 assertions, 1 failures, 0 errors\n"]]48 util_unit_diff(header, input, expected, :parse_input)49 end50 def test_input_mspec51 header = <<-HEADER52Started53.......F54Finished in 0.1 seconds55 HEADER56 failure = <<-FAILURE571)58The unless expression should fail FAILED59Expected nil to equal "baz":60 FAILURE61 backtrace = <<-BACKTRACE62 PositiveExpectation#== at spec/mspec.rb:21763 main.__script__ {} at spec/language/unless_spec.rb:4964 Proc#call at kernel/core/proc.rb:12765 SpecRunner#it at spec/mspec.rb:36866 main.it at spec/mspec.rb:41267 main.__script__ {} at spec/language/unless_spec.rb:4868 Proc#call at kernel/core/proc.rb:12769 SpecRunner#describe at spec/mspec.rb:37870 main.describe at spec/mspec.rb:40871 main.__script__ at spec/language/unless_spec.rb:372 CompiledMethod#as_script at kernel/bootstrap/primitives.rb:4173 main.load at kernel/core/compile.rb:15074 main.__script__ {} at last_mspec.rb:1175 Array#each {} at kernel/core/array.rb:54576 Integer(Fixnum)#times at kernel/core/integer.rb:1577 Array#each at kernel/core/array.rb:54578 main.__script__ at last_mspec.rb:1679 CompiledMethod#as_script at kernel/bootstrap/primitives.rb:4180 main.load at kernel/core/compile.rb:15081 main.__script__ at kernel/loader.rb:14582 BACKTRACE83 footer = "\n8 examples, 1 failures\n"84 input = header + failure + backtrace + footer85 expected_backtrace = backtrace.split("\n").map {|l| "#{l}\n"}86 expected = [[["1)\n", "The unless expression should fail FAILED\n",87 "Expected nil to equal \"baz\":\n",88 *expected_backtrace]],89 ["\n", "8 examples, 1 failures\n"]]90 util_unit_diff(header, input, expected, :parse_input)91 end92 def test_input_mspec_multiline93 header = <<-HEADER94Started95.......F96Finished in 0.1 seconds97 HEADER98failure = <<-FAILURE991)100Compiler compiles a case without an argument FAILED101Expected #<TestGenerator [[:push, :false], [:gif, #<Label 5>], [:push_literal, "foo"], [:string_dup], [:goto, #<Label 19>], [:set_label, #<Label 5>], [:push, :nil], [:gif, #<Label 10>], [:push_literal, "foo"], [:string_dup], [:goto, #<Label 19>], [:set_label, #<Label 10>], [:push, 2], [:push, 1], [:send, :==, 1, false], [:gif, #<Label 17>], [:push_literal, "bar"], [:string_dup], [:goto, #<Label 19>], [:set_label, #<Label 17>], [:push_literal, "baz"], [:string_dup], [:set_label, #<Label 19>]]102to equal #<TestGenerator [[:push, false], [:gif, #<Label 5>], [:push, "foo"], [:string_dup], [:goto, #<Label 6>], [:set_label, #<Label 5>], [:push, nil], [:set_label, #<Label 6>], [:pop], [:push, nil], [:gif, #<Label 12>], [:push, "foo"], [:string_dup], [:goto, #<Label 13>], [:set_label, #<Label 12>], [:push, nil], [:set_label, #<Label 13>], [:pop], [:push, 2], [:push, 1], [:send, :==, 1], [:gif, #<Label 21>], [:push, "bar"], [:string_dup], [:goto, #<Label 23>], [:set_label, #<Label 21>], [:push_literal, "baz"], [:string_dup], [:set_label, #<Label 23>], [:sret]]:103 FAILURE104backtrace = <<-BACKTRACE105 PositiveExpectation#== at spec/mspec.rb:216106 main.gen at ./compiler2/spec/helper.rb:125107 main.__script__ {} at compiler2/spec/control_spec.rb:448108 BACKTRACE109 footer = "\n8 examples, 1 failures\n"110 input = header + failure + backtrace + footer111 expected_backtrace = backtrace.split("\n").map {|l| "#{l}\n"}112 expected_failure = failure.split("\n").map {|l| "#{l}\n"}113 expected = [[[*(expected_failure + expected_backtrace)]],114 ["\n", "8 examples, 1 failures\n"]]115 util_unit_diff(header, input, expected, :parse_input)116 end117 def test_unit_diff_empty # simulates broken pipe at the least118 util_unit_diff("", "", "")119 end120 def test_parse_diff_angles121 input = [" 1) Failure:\n",122 "test_test1(TestBlah) [./blah.rb:25]:\n",123 "<\"<html>\"> expected but was\n",124 "<\"<body>\">.\n"125 ]126 expected = [[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n"],127 ["<html>"],128 ["<body>"],129 []]130 assert_equal expected, @diff.parse_diff(input)131 end132 def test_parse_diff_miniunit133 input = [" 1) Failure:\n",134 "test_blah(TestBlah) [./blah.rb:25]:\n",135 "Expected ['a', 'b', 'c'], not ['a', 'c', 'b'].\n"]136 expected = [[" 1) Failure:\n", "test_blah(TestBlah) [./blah.rb:25]:\n"],137 ["['a', 'b', 'c']"],138 ["['a', 'c', 'b']"],139 []]140 assert_equal expected, @diff.parse_diff(input)141 end142 def test_parse_diff_miniunit_multiline143 input = [" 1) Failure:\n",144 "test_blah(TestBlah) [./blah.rb:25]:\n",145 "Expected ['a',\n'b',\n'c'], not ['a',\n'c',\n'b'].\n"]146 expected = [[" 1) Failure:\n", "test_blah(TestBlah) [./blah.rb:25]:\n"],147 ["['a',\n'b',\n'c']"],148 ["['a',\n'c',\n'b']"],149 []]150 assert_equal expected, @diff.parse_diff(input)151 end152 def test_parse_diff1153 input = [" 1) Failure:\n",154 "test_test1(TestBlah) [./blah.rb:25]:\n",155 "<\"line1\\nline2\\nline3\\n\"> expected but was\n",156 "<\"line4\\nline5\\nline6\\n\">.\n"157 ]158 expected = [[" 1) Failure:\n", "test_test1(TestBlah) [./blah.rb:25]:\n"], ["line1\\nline2\\nline3\\n"], ["line4\\nline5\\nline6\\n"], []]159 assert_equal expected, @diff.parse_diff(input)160 end161 def test_parse_diff2162 input = [" 2) Failure:\n",163 "test_test2(TestBlah) [./blah.rb:29]:\n",164 "<\"line1\"> expected but was\n",165 "<\"line2\\nline3\\n\\n\">.\n"166 ]167 expected = [[" 2) Failure:\n",168 "test_test2(TestBlah) [./blah.rb:29]:\n"],169 ["line1"],170 ["line2\\nline3\\n\\n"],171 []172 ]173 assert_equal expected, @diff.parse_diff(input)174 end175 def test_parse_diff3176 input = [" 13) Failure:\n",177 "test_case_stmt(TestRubyToRubyC) [./r2ctestcase.rb:1198]:\n",178 "Unknown expected data.\n",179 "<false> is not true.\n"]180 expected = [[" 13) Failure:\n", "test_case_stmt(TestRubyToRubyC) [./r2ctestcase.rb:1198]:\n", "Unknown expected data.\n"], ["<false> is not true.\n"], nil, []]181 assert_equal expected, @diff.parse_diff(input)182 end183 def test_parse_diff_suspect_equals184 input = ["1) Failure:\n",185 "test_util_capture(AssertionsTest) [test/test_zentest_assertions.rb:53]:\n",186 "<\"out\"> expected but was\n",187 "<\"out\">.\n"]188 expected = [["1) Failure:\n",189 "test_util_capture(AssertionsTest) [test/test_zentest_assertions.rb:53]:\n"],190 ["out"],191 ["out"], []]192 assert_equal expected, @diff.parse_diff(input)193 end194 def test_parse_diff_NOT_suspect_equals195 input = ["1) Failure:\n",196 "test_util_capture(AssertionsTest) [test/test_zentest_assertions.rb:53]:\n",197 "<\"out\"> expected but was\n",198 "<\"out\\n\">.\n"]199 expected = [["1) Failure:\n",200 "test_util_capture(AssertionsTest) [test/test_zentest_assertions.rb:53]:\n"],201 ["out"],202 ["out\\n"], []]203 assert_equal expected, @diff.parse_diff(input)204 end205 def test_parse_diff_mspec206 input = ["1)\n", "The unless expression should fail FAILED\n",207 "Expected nil to equal \"baz\":\n",208 " PositiveExpectation#== at spec/mspec.rb:217\n"]209 expected = [["1)\n", "The unless expression should fail FAILED\n"],210 ["nil"],211 ["\"baz\""],212 [" PositiveExpectation#== at spec/mspec.rb:217"]]213 assert_equal expected, @diff.parse_diff(input)214 end215 def test_parse_diff_mspec_multiline216 input = ["1)\n", "The unless expression should fail FAILED\n",217 "Expected #<TestGenerator [[:push, :true],\n", " [:dup]\n", "]\n",218 "to equal #<TestGenerator [[:pop],\n", " [:dup]\n", "]:\n",219 " PositiveExpectation#== at spec/mspec.rb:217\n"]220 expected = [["1)\n", "The unless expression should fail FAILED\n"],221 ["#<TestGenerator [[:push, :true],\n", " [:dup]\n", "]"],222 ["#<TestGenerator [[:pop],\n", " [:dup]\n", "]"],223 [" PositiveExpectation#== at spec/mspec.rb:217"]]224 assert_equal expected, @diff.parse_diff(input)225 end226 def test_unit_diff_angles227 header = "Loaded suite ./blah\nStarted\nF\nFinished in 0.035332 seconds.\n\n"228 input = "#{header} 1) Failure:\ntest_test1(TestBlah) [./blah.rb:25]:\n<\"<html>\"> expected but was\n<\"<body>\">.\n\n1 tests, 1 assertions, 1 failures, 0 errors\n"229 expected = "1) Failure:230test_test1(TestBlah) [./blah.rb:25]:231--- expected232+++ actual233@@ -1 +1 @@234-<html>235+<body>2361 tests, 1 assertions, 1 failures, 0 errors"237 util_unit_diff(header, input, expected)238 end239 def test_unit_diff1240 header = "Loaded suite ./blah241Started242F243Finished in 0.035332 seconds.244"245 input = "#{header} 1) Failure:\ntest_test1(TestBlah) [./blah.rb:25]:\n<\"line1\\nline2\\nline3\\n\"> expected but was\n<\"line4\\nline5\\nline6\\n\">.\n\n1 tests, 1 assertions, 1 failures, 0 errors\n"246 expected = "1) Failure:\ntest_test1(TestBlah) [./blah.rb:25]:\n--- expected\n+++ actual\n@@ -1,4 +1,4 @@\n-line1\n-line2\n-line3\n+line4\n+line5\n+line6\n \n\n1 tests, 1 assertions, 1 failures, 0 errors"247 util_unit_diff(header, input, expected)248 end249 def test_unit_diff2250 header = "Loaded suite ./blah\nStarted\nFF\nFinished in 0.035332 seconds.\n\n"251 input = "#{header} 1) Failure:\ntest_test1(TestBlah) [./blah.rb:25]:\n<\"line1\\nline2\\nline3\\n\"> expected but was\n<\"line4\\nline5\\nline6\\n\">.\n\n 2) Failure:\ntest_test2(TestBlah) [./blah.rb:29]:\n<\"line1\"> expected but was\n<\"line2\\nline3\\n\\n\">.\n\n2 tests, 2 assertions, 2 failures, 0 errors\n"252 expected = "1) Failure:\ntest_test1(TestBlah) [./blah.rb:25]:\n--- expected\n+++ actual\n@@ -1,4 +1,4 @@\n-line1\n-line2\n-line3\n+line4\n+line5\n+line6\n \n\n2) Failure:\ntest_test2(TestBlah) [./blah.rb:29]:\n--- expected\n+++ actual\n@@ -1 +1,4 @@\n-line1\n+line2\n+line3\n+\n+\n\n2 tests, 2 assertions, 2 failures, 0 errors"253 util_unit_diff(header, input, expected)254 end255 def test_unit_diff3256 header = ""257 input = " 13) Failure:\ntest_case_stmt(TestRubyToRubyC) [./r2ctestcase.rb:1198]:\nUnknown expected data.\n<false> is not true.\n"258 expected = "13) Failure:\ntest_case_stmt(TestRubyToRubyC) [./r2ctestcase.rb:1198]:\nUnknown expected data.\n<false> is not true."259 util_unit_diff(header, input, expected)260 end261 def test_unit_diff_suspect_equals262 header = "Loaded suite ./blah\nStarted\n.............................................F............................................\nFinished in 0.834671 seconds.\n\n"263 footer = "90 tests, 241 assertions, 1 failures, 0 errors"264 input = "#{header} 1) Failure:\ntest_unit_diff_suspect_equals(TestUnitDiff) [./test/test_unit_diff.rb:122]:\n<\"out\"> expected but was\n<\"out\">.\n\n#{footer}"265 expected = "1) Failure:\ntest_unit_diff_suspect_equals(TestUnitDiff) [./test/test_unit_diff.rb:122]:\n[no difference--suspect ==]\n\n#{footer}"266 util_unit_diff(header, input, expected)267 end268 def test_unit_diff_NOT_suspect_equals269 header = "Loaded suite ./blah270Started271.272Finished in 0.0 seconds.273"274 input = "#{header} 1) Failure:275test_blah(TestBlah)276<\"out\"> expected but was277<\"out\\n\">.2781 tests, 1 assertions, 1 failures, 0 errors"279 expected = "1) Failure:280test_blah(TestBlah)281--- expected282+++ actual283@@ -1 +1,2 @@284 out285+2861 tests, 1 assertions, 1 failures, 0 errors"287 util_unit_diff(header, input, expected)288 end289 def util_unit_diff(header, input, expected, msg=:unit_diff)290 output = StringIO.new("")291 actual = @diff.send(msg, StringIO.new(input), output)292 assert_equal header, output.string, "header output"293 assert_equal expected, actual294 end295end...
diff
Using AI Code Generation
1 assert_equal([1, 2], @list[0, 2])2 assert_equal([1, 2], @list[0, 3])3 assert_equal(nil, @list[100])4 assert_equal(nil, @list[-1])5 assert_equal([], @list[100, 0])6 assert_equal([], @list[-3, 0])7 assert_equal(true, @list.include?(1))8 assert_equal(false, @list.include?(5))9 assert_equal(true, @list.all? { |v| v.class == Integer })10 assert_equal(false, @list.all? { |v| v.odd? })11 assert_equal(true, @list.any? { |v| v.odd? })12 assert_equal(false, @
diff
Using AI Code Generation
1assert_equal(1, 1, "1 is not equal to 1")2assert_equal(2, 2, "2 is not equal to 2")3assert_equal(3, 3, "3 is not equal to 3")4assert_equal(4, 4, "4 is not equal to 4")5assert_equal(5, 5, "5 is not equal to 5")6assert_equal(6, 6, "6 is not equal to 6")7assert_equal(7, 7, "7 is not equal to 7")8assert_equal(8, 8, "8 is not equal to 8")9assert_equal(9, 9, "9 is not equal to 9")10assert_equal(10, 10, "10 is not equal to 10")11assert_equal(11, 11, "11 is not equal to 11")12assert_equal(12, 12, "12 is not equal to 12")13assert_equal(13, 13, "13 is not equal to 13")14assert_equal(14, 14, "14 is not equal to 14")15assert_equal(15, 15, "15 is not equal to 15")16assert_equal(16, 16, "16 is not equal to 16")17assert_equal(17, 17, "17 is not equal to 17")18assert_equal(18, 18, "18 is not equal to 18")19assert_equal(19, 19, "19 is not equal to 19")20assert_equal(20, 20, "20 is not equal to 20")21assert_equal(21, 21, "21 is not equal to 21")22assert_equal(22, 22, "22 is not equal to 22")23assert_equal(23, 23, "23 is not equal to 23")24assert_equal(24, 24, "24 is not equal to 24")25assert_equal(25, 25, "25 is not equal to 25")26assert_equal(26, 26, "26 is not equal to 26")27assert_equal(27, 27, "27 is not equal to 27")28assert_equal(28, 28, "28 is not equal to 28")29assert_equal(29, 29,
diff
Using AI Code Generation
1assert_equal("a", "b", "a is not equal to b")2assert_not_equal("a", "a", "a is equal to a")3assert_not_nil("a", "a is nil")4assert_not_nil(nil, "nil is not nil")5assert_not_same("a", "a", "a is same as a")6assert_not_same("a", "b", "a is not same as b")7assert_same("a", "a", "a is not same as a")8assert_same("a", "b", "a is same as b")9assert_nil("a", "a is not nil")10assert_nil(nil, "nil is nil")11assert_block("a is not true") { "a" }12assert_nothing_raised("a is not true") { "a" }13assert_raise(RuntimeError, "a is not true") { "a" }14assert_nothing_thrown("a is not true") { "a" }15assert_throws(:a, "a is not true") { "a" }16assert_instance_of(String, "a", "a is not an instance of String")17assert_kind_of(String, "a", "a is not a kind of String")18assert_respond_to("a", :length, "a does not respond to length")19assert_match(/a/, "a", "a does not match a")20assert_no_match(/a/, "b", "b matches a")21assert_in_delta(1, 2, 0.5, "1 is not in delta of 2")22assert_in_epsilon(1, 2, 0.5, "1 is not in epsilon of 2")23assert_includes([1,2,3], 2, "2 is not included in [1,2,3]")24assert_operator(1, :<, 2, "1 is not less than 2")25assert_predicate(1, :<, "1 is not less than 2")26assert_send([1, :<, 2], "1 is not less than 2")27assert_silent("a is not true") { "a" }28assert_output("a", "b") { "a" }29assert_empty([], "[] is not empty")30assert_empty([1], "[1] is not empty")31assert_empty("a", "'a
diff
Using AI Code Generation
1 assert_equal "n", diff("Now is the time", "no way!")2 assert_equal "n", diff("Now is the time", "no way!")3 assert_equal "n", diff("Now is the time", "no way!")4 assert_equal "n", diff("Now is the time", "no way!")5 assert_equal "n", diff("Now is the time", "no way!")6 assert_equal "n", diff("Now is the time", "no way!")7 assert_equal "n", diff("Now is the time", "no way!")8 assert_equal "n", diff("Now is the time", "no way!")
diff
Using AI Code Generation
1assert_equal(1, 1)2assert_equal(1, 2)3assert_raise(ArgumentError) do4assert_raise(ArgumentError) do5assert_raise(ArgumentError) do6assert_same(1, 1)7assert_same(1, 2)8assert_not_same(1, 1)9assert_not_same(1, 2)10assert_match(/abc/, 'abc')11assert_match(/abc/, 'xyz')12assert_no_match(/abc/, 'abc')13assert_no_match(/abc/, 'xyz')14assert_in_delta(1.0, 1.0, 0.0)15assert_in_delta(1.0, 2.0, 0.0)16assert_not_in_delta(1.0, 1.0, 0.0)17assert_not_in_delta(1.0, 2.0, 0.0)18assert_in_epsilon(1.0, 1.0, 0.0)19assert_in_epsilon(1.0, 2.0, 0.0)20assert_not_in_epsilon(1.0, 1.0, 0.0)21assert_not_in_epsilon(1.0, 2.0, 0.0)22assert_includes([1, 2, 3], 1)23assert_includes([1, 2, 3], 4)24assert_not_includes([1, 2, 3], 1)25assert_not_includes([1, 2, 3], 4)26assert_empty([])27assert_empty([1])28assert_not_empty([])29assert_not_empty([1])30assert_operator(1, :<, 2)31assert_operator(1, :<, 1)32assert_not_operator(1, :<, 2)33assert_not_operator(1, :<, 1)34assert_respond_to(1, :to_s)35assert_respond_to(1, :to_i)36assert_not_respond_to(1, :to_s)37assert_not_respond_to(1, :to_i)38assert_kind_of(Integer, 1
diff
Using AI Code Generation
1", diff("a2", diff("a3", diff("a4", diff("a5", diff("a6", diff("a7", diff("a8", diff("a9", diff("a10", diff("a
diff
Using AI Code Generation
1", diff("a2", diff("a3", diff("a4", diff("a5", diff("a6", diff("a7assert_same("a", "b", "a is same as b")8assert_nil("a", "a is not nil")9assert_nil(nil, "nil is nil")10assert_block("a is not true") { "a" }11assert_nothing_raised("a is not true") { "a" }12assert_raise(RuntimeError, "a is not true") { "a" }13assert_nothing_thrown("a is not true") { "a" }14assert_throws(:a, "a is not true") { "a" }15assert_instance_of(String, "a", "a is not an instance of String")16assert_kind_of(String, "a", "a is not a kind of String")17assert_respond_to("a", :length, "a does not respond to length")18assert_match(/a/, "a", "a does not match a")19assert_no_match(/a/, "b", "b matches a")20assert_in_delta(1, 2, 0.5, "1 is not in delta of 2")21assert_in_epsilon(1, 2, 0.5, "1 is not in epsilon of 2")22assert_includes([1,2,3], 2, "2 is not included in [1,2,3]")23assert_operator(1, :<, 2, "1 is not less than 2")24assert_predicate(1, :<, "1 is not less than 2")25assert_send([1, :<, 2], "1 is not less than 2")26assert_silent("a is not true") { "a" }27assert_output("a", "b") { "a" }28assert_empty([], "[] is not empty")29assert_empty([1], "[1] is not empty")30assert_empty("a", "'a
diff
Using AI Code Generation
1", diff("a2", diff("a3", diff("a4", diff("a5", diff("a6", diff("a7", diff("a8", diff("a9", diff("a10", diff("a
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!