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 #11419 from simi/generator_generator_test
Added generated unit test for generator generator.
- Loading branch information
Showing
8 changed files
with
72 additions
and
1 deletion.
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
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
26 changes: 26 additions & 0 deletions
26
railties/lib/rails/generators/test_unit/generator/generator_generator.rb
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,26 @@ | ||
require 'rails/generators/test_unit' | ||
|
||
module TestUnit # :nodoc: | ||
module Generators # :nodoc: | ||
class GeneratorGenerator < Base # :nodoc: | ||
check_class_collision suffix: "GeneratorTest" | ||
|
||
class_option :namespace, type: :boolean, default: true, | ||
desc: "Namespace generator under lib/generators/name" | ||
|
||
def create_generator_files | ||
template 'generator_test.rb', File.join('test/lib/generators', class_path, "#{file_name}_generator_test.rb") | ||
end | ||
|
||
protected | ||
|
||
def generator_path | ||
if options[:namespace] | ||
File.join("generators", regular_class_path, file_name, "#{file_name}_generator") | ||
else | ||
File.join("generators", regular_class_path, "#{file_name}_generator") | ||
end | ||
end | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
railties/lib/rails/generators/test_unit/generator/templates/generator_test.rb
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,16 @@ | ||
require 'test_helper' | ||
require '<%= generator_path %>' | ||
|
||
<% module_namespacing do -%> | ||
class <%= class_name %>GeneratorTest < Rails::Generators::TestCase | ||
tests <%= class_name %>Generator | ||
destination Rails.root.join('tmp/generators') | ||
setup :prepare_destination | ||
|
||
# test "generator runs without errors" do | ||
# assert_nothing_raised do | ||
# run_generator ["arguments"] | ||
# end | ||
# 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
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