-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
4 changed files
with
63 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |