提交 e4e42d0b 编写于 作者: Y yuuji.yaginuma

show relative path the rerun snippet of test runner in rails engine

Since the absolute path is not required to re-run the test,
modified so that unnecessary information is not displayed.

```ruby
# before
bin/rails test /path/to/blorgh/test/integration/navigation_test.rb:5

# after
bin/rails test test/integration/navigation_test.rb:5
```
上级 11fbcf84
......@@ -44,7 +44,7 @@ def filtered_results
end
def relative_path_for(file)
file.sub(/^#{Rails.root}\/?/, '')
file.sub(/^#{app_root}\/?/, '')
end
private
......@@ -66,5 +66,9 @@ def format_rerun_snippet(result)
"#{self.executable} #{relative_path_for(assertion_path)}"
end
def app_root
@app_root ||= defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
end
end
end
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
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 @@ def plugin_path
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
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册