diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-12-10 08:40:23 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-12-10 08:40:23 +0100 |
commit | 3e5a1c2865f78236d4bc2e807b496267b99d8575 (patch) | |
tree | 66e99342a40795b2e5fd9a94b56ab44f549f2789 /railties/test | |
parent | 11fbcf84ac29d6040be1b0988d22054342ed74d4 (diff) | |
parent | e4e42d0b346065f1fce6caaea669c3e4bc42dfc8 (diff) | |
download | rails-3e5a1c2865f78236d4bc2e807b496267b99d8575.tar.gz rails-3e5a1c2865f78236d4bc2e807b496267b99d8575.tar.bz2 rails-3e5a1c2865f78236d4bc2e807b496267b99d8575.zip |
Merge pull request #22546 from y-yagi/show_relative_path_in_test_runner
show relative path the rerun snippet of test runner in rails engine
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/generators/plugin_test_helper.rb | 24 | ||||
-rw-r--r-- | railties/test/generators/plugin_test_runner_test.rb | 25 | ||||
-rw-r--r-- | railties/test/generators/test_runner_in_engine_test.rb | 31 |
3 files changed, 58 insertions, 22 deletions
diff --git a/railties/test/generators/plugin_test_helper.rb b/railties/test/generators/plugin_test_helper.rb new file mode 100644 index 0000000000..96c1b1d31f --- /dev/null +++ b/railties/test/generators/plugin_test_helper.rb @@ -0,0 +1,24 @@ +require 'abstract_unit' +require 'tmpdir' + +module PluginTestHelper + def create_test_file(name, pass: true) + plugin_file "test/#{name}_test.rb", <<-RUBY + require 'test_helper' + + class #{name.camelize}Test < ActiveSupport::TestCase + def test_truth + puts "#{name.camelize}Test" + assert #{pass}, 'wups!' + end + end + RUBY + end + + def plugin_file(path, contents, mode: 'w') + FileUtils.mkdir_p File.dirname("#{plugin_path}/#{path}") + File.open("#{plugin_path}/#{path}", mode) do |f| + f.puts contents + end + end +end diff --git a/railties/test/generators/plugin_test_runner_test.rb b/railties/test/generators/plugin_test_runner_test.rb index 0444e13865..716728819e 100644 --- a/railties/test/generators/plugin_test_runner_test.rb +++ b/railties/test/generators/plugin_test_runner_test.rb @@ -1,7 +1,8 @@ -require 'tmpdir' -require 'abstract_unit' +require 'generators/plugin_test_helper' class PluginTestRunnerTest < ActiveSupport::TestCase + include PluginTestHelper + def setup @destination_root = Dir.mktmpdir('bukkits') Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --skip-bundle` } @@ -100,24 +101,4 @@ class PluginTestRunnerTest < ActiveSupport::TestCase def run_test_command(arguments) Dir.chdir(plugin_path) { `bin/test #{arguments}` } end - - def create_test_file(name, pass: true) - plugin_file "test/#{name}_test.rb", <<-RUBY - require 'test_helper' - - class #{name.camelize}Test < ActiveSupport::TestCase - def test_truth - puts "#{name.camelize}Test" - assert #{pass}, 'wups!' - end - end - RUBY - end - - def plugin_file(path, contents, mode: 'w') - FileUtils.mkdir_p File.dirname("#{plugin_path}/#{path}") - File.open("#{plugin_path}/#{path}", mode) do |f| - f.puts contents - end - end end diff --git a/railties/test/generators/test_runner_in_engine_test.rb b/railties/test/generators/test_runner_in_engine_test.rb new file mode 100644 index 0000000000..641c5d0835 --- /dev/null +++ b/railties/test/generators/test_runner_in_engine_test.rb @@ -0,0 +1,31 @@ +require 'generators/plugin_test_helper' + +class TestRunnerInEngineTest < ActiveSupport::TestCase + include PluginTestHelper + + def setup + @destination_root = Dir.mktmpdir('bukkits') + Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --full --skip-bundle` } + plugin_file 'test/dummy/db/schema.rb', '' + end + + def teardown + FileUtils.rm_rf(@destination_root) + end + + def test_rerun_snippet_is_relative_path + create_test_file 'post', pass: false + + output = run_test_command('test/post_test.rb') + assert_match %r{Running:\n\nPostTest\nF\n\nwups!\n\nbin/rails test test/post_test.rb:6}, output + end + + private + def plugin_path + "#{@destination_root}/bukkits" + end + + def run_test_command(arguments) + Dir.chdir(plugin_path) { `bin/rails test #{arguments}` } + end +end |