2014-12-30 04:17:30 -05:00
|
|
|
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
|
2015-01-23 20:35:13 -05:00
|
|
|
|
2015-01-29 09:03:08 -05:00
|
|
|
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
|
|
|
|
|
2015-01-23 20:35:13 -05:00
|
|
|
test "parse the filename and line" do
|
2015-01-29 10:39:43 -05:00
|
|
|
file = "test/test_unit/runner_test.rb"
|
|
|
|
absolute_file = __FILE__
|
|
|
|
options = @options.parse(["#{file}:20"])
|
|
|
|
assert_equal absolute_file, options[:filename]
|
2015-01-23 20:35:13 -05:00
|
|
|
assert_equal 20, options[:line]
|
|
|
|
|
2015-01-29 10:39:43 -05:00
|
|
|
options = @options.parse(["#{file}:"])
|
|
|
|
assert_equal [absolute_file], options[:patterns]
|
2015-01-23 20:35:13 -05:00
|
|
|
assert_nil options[:line]
|
|
|
|
|
2015-01-29 10:39:43 -05:00
|
|
|
options = @options.parse([file])
|
|
|
|
assert_equal [absolute_file], options[:patterns]
|
2015-01-23 20:35:13 -05:00
|
|
|
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
|
2015-01-24 06:10:46 -05:00
|
|
|
|
|
|
|
test "run all tests in a directory" do
|
2015-01-29 10:39:43 -05:00
|
|
|
dir = Pathname.new(__dir__).basename.to_s
|
|
|
|
options = @options.parse([dir])
|
2015-01-24 06:10:46 -05:00
|
|
|
|
2015-01-29 10:00:43 -05:00
|
|
|
assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns]
|
2015-01-24 06:10:46 -05:00
|
|
|
assert_nil options[:filename]
|
|
|
|
assert_nil options[:line]
|
|
|
|
end
|
2015-01-29 09:03:08 -05:00
|
|
|
|
2015-01-29 10:39:43 -05:00
|
|
|
test "run multiple folders" do
|
2015-01-29 10:00:43 -05:00
|
|
|
application_dir = File.expand_path("#{__dir__}/../application")
|
2015-01-29 10:39:43 -05:00
|
|
|
|
|
|
|
options = @options.parse([Pathname.new(__dir__).basename.to_s, Pathname.new(application_dir).basename.to_s])
|
2015-01-29 10:00:43 -05:00
|
|
|
|
|
|
|
assert_equal ["#{__dir__}/**/*_test.rb", "#{application_dir}/**/*_test.rb"], options[:patterns]
|
|
|
|
assert_nil options[:filename]
|
|
|
|
assert_nil options[:line]
|
2015-01-29 10:07:32 -05:00
|
|
|
|
|
|
|
runner = Rails::TestRunner.new(options)
|
|
|
|
assert runner.test_files.size > 0
|
2015-01-29 10:00:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "run multiple files and run one file by line" do
|
|
|
|
line = __LINE__
|
2015-01-29 10:39:43 -05:00
|
|
|
options = @options.parse([Pathname.new(__dir__).basename.to_s, "#{__FILE__}:#{line}"])
|
2015-01-29 10:00:43 -05:00
|
|
|
|
|
|
|
assert_equal ["#{__dir__}/**/*_test.rb"], options[:patterns]
|
|
|
|
assert_equal __FILE__, options[:filename]
|
|
|
|
assert_equal line, options[:line]
|
2015-01-29 10:07:32 -05:00
|
|
|
|
|
|
|
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]
|
2015-01-29 09:03:08 -05:00
|
|
|
end
|
2014-12-30 04:17:30 -05:00
|
|
|
end
|