2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "generators/plugin_test_helper"
|
2015-11-16 18:49:46 -05:00
|
|
|
|
|
|
|
class PluginTestRunnerTest < ActiveSupport::TestCase
|
2015-12-07 01:16:18 -05:00
|
|
|
include PluginTestHelper
|
|
|
|
|
2015-11-16 18:49:46 -05:00
|
|
|
def setup
|
2016-08-06 13:16:09 -04:00
|
|
|
@destination_root = Dir.mktmpdir("bukkits")
|
2017-11-08 16:39:35 -05:00
|
|
|
Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --skip-bundle` }
|
2016-08-06 13:16:09 -04:00
|
|
|
plugin_file "test/dummy/db/schema.rb", ""
|
2015-11-16 18:49:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
FileUtils.rm_rf(@destination_root)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_run_single_file
|
2016-08-06 13:16:09 -04:00
|
|
|
create_test_file "foo"
|
|
|
|
create_test_file "bar"
|
2015-11-16 18:49:46 -05:00
|
|
|
assert_match "1 runs, 1 assertions, 0 failures", run_test_command("test/foo_test.rb")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_run_multiple_files
|
2016-08-06 13:16:09 -04:00
|
|
|
create_test_file "foo"
|
|
|
|
create_test_file "bar"
|
2015-11-16 18:49:46 -05:00
|
|
|
assert_match "2 runs, 2 assertions, 0 failures", run_test_command("test/foo_test.rb test/bar_test.rb")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mix_files_and_line_filters
|
2016-08-06 13:16:09 -04:00
|
|
|
create_test_file "account"
|
|
|
|
plugin_file "test/post_test.rb", <<-RUBY
|
2020-03-29 19:30:52 -04:00
|
|
|
require "test_helper"
|
2015-11-16 18:49:46 -05:00
|
|
|
|
|
|
|
class PostTest < ActiveSupport::TestCase
|
|
|
|
def test_post
|
|
|
|
puts 'PostTest'
|
|
|
|
assert true
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_line_filter_does_not_run_this
|
|
|
|
assert true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
run_test_command("test/account_test.rb test/post_test.rb:4").tap do |output|
|
|
|
|
assert_match "AccountTest", output
|
|
|
|
assert_match "PostTest", output
|
|
|
|
assert_match "2 runs, 2 assertions", output
|
2015-11-16 18:49:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_multiple_line_filters
|
2016-08-06 13:16:09 -04:00
|
|
|
create_test_file "account"
|
|
|
|
create_test_file "post"
|
2015-11-16 18:49:46 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
run_test_command("test/account_test.rb:4 test/post_test.rb:4").tap do |output|
|
|
|
|
assert_match "AccountTest", output
|
|
|
|
assert_match "PostTest", output
|
2015-11-16 18:49:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_output_inline_by_default
|
2016-08-06 13:16:09 -04:00
|
|
|
create_test_file "post", pass: false
|
2015-11-16 18:49:46 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
output = run_test_command("test/post_test.rb")
|
2016-02-15 09:56:11 -05:00
|
|
|
expect = %r{Running:\n\nPostTest\nF\n\nFailure:\nPostTest#test_truth \[[^\]]+test/post_test.rb:6\]:\nwups!\n\nbin/test (/private)?#{plugin_path}/test/post_test.rb:4}
|
2015-12-19 06:04:39 -05:00
|
|
|
assert_match expect, output
|
2015-11-16 18:49:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_only_inline_failure_output
|
2016-08-06 13:16:09 -04:00
|
|
|
create_test_file "post", pass: false
|
2015-11-16 18:49:46 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
output = run_test_command("test/post_test.rb")
|
2017-07-29 20:02:51 -04:00
|
|
|
assert_match %r{Finished in.*\n1 runs, 1 assertions}, output
|
2015-11-16 18:49:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_fail_fast
|
2016-08-06 13:16:09 -04:00
|
|
|
create_test_file "post", pass: false
|
2015-11-16 18:49:46 -05:00
|
|
|
|
|
|
|
assert_match(/Interrupt/,
|
2016-08-06 13:16:09 -04:00
|
|
|
capture(:stderr) { run_test_command("test/post_test.rb --fail-fast") })
|
2015-11-16 18:49:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_raise_error_when_specified_file_does_not_exist
|
2016-08-06 13:16:09 -04:00
|
|
|
error = capture(:stderr) { run_test_command("test/not_exists.rb") }
|
2015-11-16 18:49:46 -05:00
|
|
|
assert_match(%r{cannot load such file.+test/not_exists\.rb}, error)
|
|
|
|
end
|
|
|
|
|
2016-09-26 23:12:12 -04:00
|
|
|
def test_executed_only_once
|
|
|
|
create_test_file "foo"
|
2016-10-28 23:05:58 -04:00
|
|
|
result = run_test_command("test/foo_test.rb")
|
2016-09-26 23:12:12 -04:00
|
|
|
assert_equal 1, result.scan(/1 runs, 1 assertions, 0 failures/).length
|
|
|
|
end
|
|
|
|
|
2017-01-23 01:05:46 -05:00
|
|
|
def test_warnings_option
|
|
|
|
plugin_file "test/models/warnings_test.rb", <<-RUBY
|
2020-03-29 19:30:52 -04:00
|
|
|
require "test_helper"
|
2017-01-23 01:05:46 -05:00
|
|
|
def test_warnings
|
|
|
|
a = 1
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
assert_match(/warning: assigned but unused variable/,
|
|
|
|
capture(:stderr) { run_test_command("test/models/warnings_test.rb -w") })
|
|
|
|
end
|
|
|
|
|
2017-09-03 18:15:58 -04:00
|
|
|
def test_run_rake_test
|
|
|
|
create_test_file "foo"
|
|
|
|
result = Dir.chdir(plugin_path) { `rake test TEST=test/foo_test.rb` }
|
|
|
|
assert_match "1 runs, 1 assertions, 0 failures", result
|
|
|
|
end
|
|
|
|
|
2015-11-16 18:49:46 -05:00
|
|
|
private
|
|
|
|
def plugin_path
|
|
|
|
"#{@destination_root}/bukkits"
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_test_command(arguments)
|
|
|
|
Dir.chdir(plugin_path) { `bin/test #{arguments}` }
|
|
|
|
end
|
|
|
|
end
|