From c5532e06d9ef8b75f7443019aa1f34a3b697efdc Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 30 Dec 2014 10:17:30 +0100 Subject: spike of a `OptionParser` backed test runner. --- railties/test/test_unit/runner_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 railties/test/test_unit/runner_test.rb (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb new file mode 100644 index 0000000000..cfc1d897b9 --- /dev/null +++ b/railties/test/test_unit/runner_test.rb @@ -0,0 +1,21 @@ +require 'abstract_unit' +require 'rails/test_unit/runner' + +class TestUnitTestRunnerTest < ActiveSupport::TestCase + setup do + @options = Rails::TestRunner::Options + end + + test "shows the filtered backtrace by default" do + options = @options.parse([]) + assert_not options[:backtrace] + end + + test "has --backtrace (-b) option to show the full backtrace" do + options = @options.parse(["-b"]) + assert options[:backtrace] + + options = @options.parse(["--backtrace"]) + assert options[:backtrace] + end +end -- cgit v1.2.3 From d1a5460e3eb939d8de780df9a6530b02fe6d5614 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Fri, 23 Jan 2015 20:35:13 -0500 Subject: Better file:line parsing and filter method by file too --- railties/test/test_unit/runner_test.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index cfc1d897b9..fa906d4080 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -18,4 +18,30 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase options = @options.parse(["--backtrace"]) assert options[:backtrace] end + + test "parse the filename and line" do + options = @options.parse(["foobar.rb:20"]) + assert_equal File.expand_path("foobar.rb"), options[:filename] + assert_equal 20, options[:line] + + options = @options.parse(["foobar.rb:"]) + assert_equal File.expand_path("foobar.rb"), options[:filename] + assert_nil options[:line] + + options = @options.parse(["foobar.rb"]) + assert_equal File.expand_path("foobar.rb"), options[:filename] + assert_nil options[:line] + end + + test "find_method on same file" do + options = @options.parse(["#{__FILE__}:#{__LINE__}"]) + runner = Rails::TestRunner.new(options) + assert_equal "test_find_method_on_same_file", runner.find_method + end + + test "find_method on a different file" do + options = @options.parse(["foobar.rb:#{__LINE__}"]) + runner = Rails::TestRunner.new(options) + assert_nil runner.find_method + end end -- cgit v1.2.3 From ff79441d49a52a2669e147cd8264a2dc6e452b80 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Sat, 24 Jan 2015 11:41:33 +0100 Subject: add tests for our minitest reporter. --- railties/test/test_unit/reporter_test.rb | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 railties/test/test_unit/reporter_test.rb (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/reporter_test.rb b/railties/test/test_unit/reporter_test.rb new file mode 100644 index 0000000000..587a0f878b --- /dev/null +++ b/railties/test/test_unit/reporter_test.rb @@ -0,0 +1,76 @@ +require 'abstract_unit' +require 'rails/test_unit/reporter' + +class TestUnitReporterTest < ActiveSupport::TestCase + class ExampleTest < Minitest::Test + def woot; end + end + + setup do + @output = StringIO.new + @reporter = Rails::TestUnitReporter.new @output + end + + test "prints rerun snippet to run a single failed test" do + @reporter.results << failed_test + @reporter.report + + assert_match %r{^bin/rails test .*test/test_unit/reporter_test.rb:6$}, @output.string + assert_rerun_snippet_count 1 + end + + test "prints rerun snippet for every failed test" do + @reporter.results << failed_test + @reporter.results << failed_test + @reporter.results << failed_test + @reporter.report + + assert_rerun_snippet_count 3 + end + + test "does not print snippet for successful and skipped tests" do + skip "confirm the expected behavior with Arthur" + @reporter.results << passing_test + @reporter.results << skipped_test + @reporter.report + assert_rerun_snippet_count 0 + end + + test "prints rerun snippet for skipped tests if run in verbose mode" do + skip "confirm the expected behavior with Arthur" + verbose = Rails::TestUnitReporter.new @output, verbose: true + verbose.results << skipped_test + verbose.report + + assert_rerun_snippet_count 1 + end + + private + def assert_rerun_snippet_count(snippet_count) + assert_equal snippet_count, @output.string.scan(%r{^bin/rails test }).size + end + + def failed_test + ft = ExampleTest.new(:woot) + ft.failures << begin + raise Minitest::Assertion, "boo" + rescue Minitest::Assertion => e + e + end + ft + end + + def passing_test + ExampleTest.new(:woot) + end + + def skipped_test + st = ExampleTest.new(:woot) + st.failures << begin + raise Minitest::Skip + rescue Minitest::Assertion => e + e + end + st + end +end -- cgit v1.2.3 From 613bdd9d4c6b024cbc26186f1ad443faa6cdffb1 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Sat, 24 Jan 2015 12:10:46 +0100 Subject: get rid of NAMED_PATTERNS in favor of running a whole directory --- railties/test/test_unit/runner_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index fa906d4080..be226e3aa5 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -44,4 +44,12 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase runner = Rails::TestRunner.new(options) assert_nil runner.find_method end + + test "run all tests in a directory" do + options = @options.parse([__dir__]) + + assert_equal "#{__dir__}/**/*_test.rb", options[:pattern] + assert_nil options[:filename] + assert_nil options[:line] + end end -- cgit v1.2.3 From 090c83672f333d6a4d87752ca1f980bfb6be6849 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Thu, 29 Jan 2015 15:03:08 +0100 Subject: `-e` / `--environment` for the test runner. --- railties/test/test_unit/runner_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index be226e3aa5..cd0c66a5f7 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -19,6 +19,16 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase assert options[:backtrace] end + test "tests run in the test environment by default" do + options = @options.parse([]) + assert_equal "test", options[:environment] + end + + test "can run in a specific environment" do + options = @options.parse(["-e development"]) + assert_equal "development", options[:environment] + end + test "parse the filename and line" do options = @options.parse(["foobar.rb:20"]) assert_equal File.expand_path("foobar.rb"), options[:filename] @@ -52,4 +62,8 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase assert_nil options[:filename] assert_nil options[:line] end + + test "run multiple files" do + skip "needs implementation" + end end -- cgit v1.2.3 From b58c0914f4d85faa39f22eb3408970ac8a176913 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Thu, 29 Jan 2015 10:00:43 -0500 Subject: Run multiple files on runner --- railties/test/test_unit/runner_test.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index cd0c66a5f7..9690893a0e 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -58,12 +58,26 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase test "run all tests in a directory" do options = @options.parse([__dir__]) - assert_equal "#{__dir__}/**/*_test.rb", options[:pattern] + assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns] assert_nil options[:filename] assert_nil options[:line] end test "run multiple files" do - skip "needs implementation" + application_dir = File.expand_path("#{__dir__}/../application") + options = @options.parse([__dir__, application_dir]) + + assert_equal ["#{__dir__}/**/*_test.rb", "#{application_dir}/**/*_test.rb"], options[:patterns] + assert_nil options[:filename] + assert_nil options[:line] + end + + test "run multiple files and run one file by line" do + line = __LINE__ + options = @options.parse([__dir__, "#{__FILE__}:#{line}"]) + + assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns] + assert_equal __FILE__, options[:filename] + assert_equal line, options[:line] end end -- cgit v1.2.3 From 3cc783b6bf20da27079038e7c52ce214f1042df3 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Thu, 29 Jan 2015 10:07:32 -0500 Subject: Add tests for runner#test_files method --- railties/test/test_unit/runner_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index 9690893a0e..94f338344d 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -70,6 +70,9 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase assert_equal ["#{__dir__}/**/*_test.rb", "#{application_dir}/**/*_test.rb"], options[:patterns] assert_nil options[:filename] assert_nil options[:line] + + runner = Rails::TestRunner.new(options) + assert runner.test_files.size > 0 end test "run multiple files and run one file by line" do @@ -79,5 +82,16 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns] assert_equal __FILE__, options[:filename] assert_equal line, options[:line] + + runner = Rails::TestRunner.new(options) + assert_equal [__FILE__], runner.test_files, 'Only returns the file that running by line' + end + + test "running multiple files passing line number" do + line = __LINE__ + options = @options.parse(["foobar.rb:8", "#{__FILE__}:#{line}"]) + + assert_equal __FILE__, options[:filename], 'Returns the last file' + assert_equal line, options[:line] end end -- cgit v1.2.3 From de94929d70d94fd8bb20791bf544ee483db8ddc1 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Thu, 29 Jan 2015 10:39:43 -0500 Subject: Fix relative dir call on test runner --- railties/test/test_unit/runner_test.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index 94f338344d..e8623bef67 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -30,16 +30,18 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase end test "parse the filename and line" do - options = @options.parse(["foobar.rb:20"]) - assert_equal File.expand_path("foobar.rb"), options[:filename] + file = "test/test_unit/runner_test.rb" + absolute_file = __FILE__ + options = @options.parse(["#{file}:20"]) + assert_equal absolute_file, options[:filename] assert_equal 20, options[:line] - options = @options.parse(["foobar.rb:"]) - assert_equal File.expand_path("foobar.rb"), options[:filename] + options = @options.parse(["#{file}:"]) + assert_equal [absolute_file], options[:patterns] assert_nil options[:line] - options = @options.parse(["foobar.rb"]) - assert_equal File.expand_path("foobar.rb"), options[:filename] + options = @options.parse([file]) + assert_equal [absolute_file], options[:patterns] assert_nil options[:line] end @@ -56,16 +58,18 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase end test "run all tests in a directory" do - options = @options.parse([__dir__]) + dir = Pathname.new(__dir__).basename.to_s + options = @options.parse([dir]) assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns] assert_nil options[:filename] assert_nil options[:line] end - test "run multiple files" do + test "run multiple folders" do application_dir = File.expand_path("#{__dir__}/../application") - options = @options.parse([__dir__, application_dir]) + + options = @options.parse([Pathname.new(__dir__).basename.to_s, Pathname.new(application_dir).basename.to_s]) assert_equal ["#{__dir__}/**/*_test.rb", "#{application_dir}/**/*_test.rb"], options[:patterns] assert_nil options[:filename] @@ -77,7 +81,7 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase test "run multiple files and run one file by line" do line = __LINE__ - options = @options.parse([__dir__, "#{__FILE__}:#{line}"]) + options = @options.parse([Pathname.new(__dir__).basename.to_s, "#{__FILE__}:#{line}"]) assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns] assert_equal __FILE__, options[:filename] -- cgit v1.2.3 From f78708c180868d54e9b86e5d406b69e3de50f503 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Fri, 30 Jan 2015 14:54:41 +0100 Subject: use `bin/rails t` runner in `test_runner_test.rb`. --- railties/test/test_unit/runner_test.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index e8623bef67..fa5442c15c 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -58,8 +58,7 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase end test "run all tests in a directory" do - dir = Pathname.new(__dir__).basename.to_s - options = @options.parse([dir]) + options = @options.parse([__dir__]) assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns] assert_nil options[:filename] @@ -69,7 +68,7 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase test "run multiple folders" do application_dir = File.expand_path("#{__dir__}/../application") - options = @options.parse([Pathname.new(__dir__).basename.to_s, Pathname.new(application_dir).basename.to_s]) + options = @options.parse([__dir__, application_dir]) assert_equal ["#{__dir__}/**/*_test.rb", "#{application_dir}/**/*_test.rb"], options[:patterns] assert_nil options[:filename] @@ -81,7 +80,7 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase test "run multiple files and run one file by line" do line = __LINE__ - options = @options.parse([Pathname.new(__dir__).basename.to_s, "#{__FILE__}:#{line}"]) + options = @options.parse([__dir__, "#{__FILE__}:#{line}"]) assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns] assert_equal __FILE__, options[:filename] -- cgit v1.2.3 From 6ccbeb458a5698db6242d7bd326ef9d9bd23c7b6 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Fri, 30 Jan 2015 16:19:37 +0100 Subject: move `ENV["BACKTRACE"]` support into the TestRunner. --- railties/test/test_unit/runner_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/runner_test.rb b/railties/test/test_unit/runner_test.rb index fa5442c15c..c040c71635 100644 --- a/railties/test/test_unit/runner_test.rb +++ b/railties/test/test_unit/runner_test.rb @@ -1,7 +1,10 @@ require 'abstract_unit' +require 'env_helpers' require 'rails/test_unit/runner' class TestUnitTestRunnerTest < ActiveSupport::TestCase + include EnvHelpers + setup do @options = Rails::TestRunner::Options end @@ -19,6 +22,13 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase assert options[:backtrace] end + test "show full backtrace using BACKTRACE environment variable" do + switch_env "BACKTRACE", "true" do + options = @options.parse([]) + assert options[:backtrace] + end + end + test "tests run in the test environment by default" do options = @options.parse([]) assert_equal "test", options[:environment] -- cgit v1.2.3 From f10c7e184939064be9e4995551efc3ebc3a8b883 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Tue, 3 Feb 2015 21:54:50 -0500 Subject: Fix reporter test and verbose mode --- railties/test/test_unit/reporter_test.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'railties/test/test_unit') diff --git a/railties/test/test_unit/reporter_test.rb b/railties/test/test_unit/reporter_test.rb index 587a0f878b..77883612f5 100644 --- a/railties/test/test_unit/reporter_test.rb +++ b/railties/test/test_unit/reporter_test.rb @@ -12,7 +12,7 @@ class TestUnitReporterTest < ActiveSupport::TestCase end test "prints rerun snippet to run a single failed test" do - @reporter.results << failed_test + @reporter.record(failed_test) @reporter.report assert_match %r{^bin/rails test .*test/test_unit/reporter_test.rb:6$}, @output.string @@ -20,26 +20,24 @@ class TestUnitReporterTest < ActiveSupport::TestCase end test "prints rerun snippet for every failed test" do - @reporter.results << failed_test - @reporter.results << failed_test - @reporter.results << failed_test + @reporter.record(failed_test) + @reporter.record(failed_test) + @reporter.record(failed_test) @reporter.report assert_rerun_snippet_count 3 end test "does not print snippet for successful and skipped tests" do - skip "confirm the expected behavior with Arthur" - @reporter.results << passing_test - @reporter.results << skipped_test + @reporter.record(passing_test) + @reporter.record(skipped_test) @reporter.report assert_rerun_snippet_count 0 end test "prints rerun snippet for skipped tests if run in verbose mode" do - skip "confirm the expected behavior with Arthur" verbose = Rails::TestUnitReporter.new @output, verbose: true - verbose.results << skipped_test + verbose.record(skipped_test) verbose.report assert_rerun_snippet_count 1 -- cgit v1.2.3