class GeneratorsTest
Public Instance Methods
setup()
click to toggle source
# File railties/test/generators_test.rb, line 10 def setup @path = File.expand_path("lib", Quails.root) $LOAD_PATH.unshift(@path) end
teardown()
click to toggle source
# File railties/test/generators_test.rb, line 15 def teardown $LOAD_PATH.delete(@path) end
test_developer_options_are_overwritten_by_user_options()
click to toggle source
# File railties/test/generators_test.rb, line 200 def test_developer_options_are_overwritten_by_user_options Quails::Generators.options[:with_options] = { generate: false } self.class.class_eval(<<-end_eval, __FILE__, __LINE__ + 1) class WithOptionsGenerator < Quails::Generators::Base class_option :generate, default: true, type: :boolean end end_eval assert_equal false, WithOptionsGenerator.class_options[:generate].default ensure Quails::Generators.subclasses.delete(WithOptionsGenerator) end
test_fallbacks_for_generators_on_find_by_namespace()
click to toggle source
# File railties/test/generators_test.rb, line 162 def test_fallbacks_for_generators_on_find_by_namespace Quails::Generators.fallbacks[:remarkable] = :test_unit klass = Quails::Generators.find_by_namespace(:plugin, :remarkable) assert klass assert_equal "test_unit:plugin", klass.namespace ensure Quails::Generators.fallbacks.delete(:remarkable) end
test_fallbacks_for_generators_on_find_by_namespace_with_context()
click to toggle source
# File railties/test/generators_test.rb, line 171 def test_fallbacks_for_generators_on_find_by_namespace_with_context Quails::Generators.fallbacks[:remarkable] = :test_unit klass = Quails::Generators.find_by_namespace(:remarkable, :quails, :plugin) assert klass assert_equal "test_unit:plugin", klass.namespace ensure Quails::Generators.fallbacks.delete(:remarkable) end
test_fallbacks_for_generators_on_invoke()
click to toggle source
# File railties/test/generators_test.rb, line 180 def test_fallbacks_for_generators_on_invoke Quails::Generators.fallbacks[:shoulda] = :test_unit assert_called_with(TestUnit::Generators::ModelGenerator, :start, [["Account"], {}]) do Quails::Generators.invoke "shoulda:model", ["Account"] end ensure Quails::Generators.fallbacks.delete(:shoulda) end
test_find_by_namespace()
click to toggle source
# File railties/test/generators_test.rb, line 70 def test_find_by_namespace klass = Quails::Generators.find_by_namespace("quails:model") assert klass assert_equal "quails:model", klass.namespace end
test_find_by_namespace_in_subfolder()
click to toggle source
# File railties/test/generators_test.rb, line 94 def test_find_by_namespace_in_subfolder klass = Quails::Generators.find_by_namespace(:fixjour, :active_record) assert klass assert_equal "active_record:fixjour", klass.namespace end
test_find_by_namespace_with_base()
click to toggle source
# File railties/test/generators_test.rb, line 76 def test_find_by_namespace_with_base klass = Quails::Generators.find_by_namespace(:model, :quails) assert klass assert_equal "quails:model", klass.namespace end
test_find_by_namespace_with_context()
click to toggle source
# File railties/test/generators_test.rb, line 82 def test_find_by_namespace_with_context klass = Quails::Generators.find_by_namespace(:test_unit, nil, :model) assert klass assert_equal "test_unit:model", klass.namespace end
test_find_by_namespace_with_duplicated_name()
click to toggle source
# File railties/test/generators_test.rb, line 100 def test_find_by_namespace_with_duplicated_name klass = Quails::Generators.find_by_namespace(:foobar) assert klass assert_equal "foobar:foobar", klass.namespace end
test_find_by_namespace_with_generator_on_root()
click to toggle source
# File railties/test/generators_test.rb, line 88 def test_find_by_namespace_with_generator_on_root klass = Quails::Generators.find_by_namespace(:fixjour) assert klass assert_equal "fixjour", klass.namespace end
test_find_by_namespace_without_base_or_context_looks_into_quails_namespace()
click to toggle source
# File railties/test/generators_test.rb, line 106 def test_find_by_namespace_without_base_or_context_looks_into_quails_namespace assert Quails::Generators.find_by_namespace(:model) end
test_generator_multiple_suggestions()
click to toggle source
# File railties/test/generators_test.rb, line 39 def test_generator_multiple_suggestions name = :tas output = capture(:stdout) { Quails::Generators.invoke name } assert_match "Maybe you meant 'task', 'job' or", output end
test_generator_suggestions()
click to toggle source
# File railties/test/generators_test.rb, line 33 def test_generator_suggestions name = :migrationz output = capture(:stdout) { Quails::Generators.invoke name } assert_match "Maybe you meant 'migration'", output end
test_help_when_a_generator_with_required_arguments_is_invoked_without_arguments()
click to toggle source
# File railties/test/generators_test.rb, line 45 def test_help_when_a_generator_with_required_arguments_is_invoked_without_arguments output = capture(:stdout) { Quails::Generators.invoke :model, [] } assert_match(/Description:/, output) end
test_hide_namespace()
click to toggle source
# File railties/test/generators_test.rb, line 243 def test_hide_namespace assert_not_includes Quails::Generators.hidden_namespaces, "special:namespace" Quails::Generators.hide_namespace("special:namespace") assert_includes Quails::Generators.hidden_namespaces, "special:namespace" end
test_invoke_when_generator_is_not_found()
click to toggle source
# File railties/test/generators_test.rb, line 26 def test_invoke_when_generator_is_not_found name = :unknown output = capture(:stdout) { Quails::Generators.invoke name } assert_match "Could not find generator '#{name}'", output assert_match "`quails generate --help`", output end
test_invoke_with_config_values()
click to toggle source
# File railties/test/generators_test.rb, line 64 def test_invoke_with_config_values assert_called_with(Quails::Generators::ModelGenerator, :start, [["Account"], behavior: :skip]) do Quails::Generators.invoke :model, ["Account"], behavior: :skip end end
test_invoke_with_default_values()
click to toggle source
# File railties/test/generators_test.rb, line 58 def test_invoke_with_default_values assert_called_with(Quails::Generators::ModelGenerator, :start, [["Account"], {}]) do Quails::Generators.invoke :model, ["Account"] end end
test_invoke_with_nested_namespaces()
click to toggle source
# File railties/test/generators_test.rb, line 110 def test_invoke_with_nested_namespaces model_generator = Minitest::Mock.new model_generator.expect(:start, nil, [["Account"], {}]) assert_called_with(Quails::Generators, :find_by_namespace, ["namespace", "my:awesome"], returns: model_generator) do Quails::Generators.invoke "my:awesome:namespace", ["Account"] end model_generator.verify end
test_nested_fallbacks_for_generators()
click to toggle source
# File railties/test/generators_test.rb, line 189 def test_nested_fallbacks_for_generators Quails::Generators.fallbacks[:shoulda] = :test_unit Quails::Generators.fallbacks[:super_shoulda] = :shoulda assert_called_with(TestUnit::Generators::ModelGenerator, :start, [["Account"], {}]) do Quails::Generators.invoke "super_shoulda:model", ["Account"] end ensure Quails::Generators.fallbacks.delete(:shoulda) Quails::Generators.fallbacks.delete(:super_shoulda) end
test_no_color_sets_proper_shell()
click to toggle source
# File railties/test/generators_test.rb, line 155 def test_no_color_sets_proper_shell Quails::Generators.no_color! assert_equal Thor::Shell::Basic, Thor::Base.shell ensure Thor::Base.shell = Thor::Shell::Color end
test_quails_generators_does_not_show_active_record_hooks()
click to toggle source
# File railties/test/generators_test.rb, line 139 def test_quails_generators_does_not_show_active_record_hooks output = capture(:stdout) { Quails::Generators.help } assert_match(/ActiveRecord:/, output) assert_match(/^ active_record:fixjour$/, output) end
test_quails_generators_help_does_not_include_app_nor_plugin_new()
click to toggle source
# File railties/test/generators_test.rb, line 127 def test_quails_generators_help_does_not_include_app_nor_plugin_new output = capture(:stdout) { Quails::Generators.help } assert_no_match(/app\W/, output) assert_no_match(/[^:]plugin/, output) end
test_quails_generators_help_with_builtin_information()
click to toggle source
# File railties/test/generators_test.rb, line 119 def test_quails_generators_help_with_builtin_information output = capture(:stdout) { Quails::Generators.help } assert_match(/Quails:/, output) assert_match(/^ model$/, output) assert_match(/^ scaffold_controller$/, output) assert_no_match(/^ app$/, output) end
test_quails_generators_with_others_information()
click to toggle source
# File railties/test/generators_test.rb, line 133 def test_quails_generators_with_others_information output = capture(:stdout) { Quails::Generators.help } assert_match(/Fixjour:/, output) assert_match(/^ fixjour$/, output) end
test_quails_root_templates()
click to toggle source
# File railties/test/generators_test.rb, line 214 def test_quails_root_templates template = File.join(Quails.root, "lib", "templates", "active_record", "model", "model.rb") # Create template mkdir_p(File.dirname(template)) File.open(template, "w") { |f| f.write "empty" } capture(:stdout) do Quails::Generators.invoke :model, ["user"], destination_root: destination_root end assert_file "app/models/user.rb" do |content| assert_equal "empty", content end ensure rm_rf File.dirname(template) end
test_should_give_higher_preference_to_quails_generators()
click to toggle source
# File railties/test/generators_test.rb, line 50 def test_should_give_higher_preference_to_quails_generators assert File.exist?(File.join(@path, "generators", "model_generator.rb")) assert_called_with(Quails::Generators::ModelGenerator, :start, [["Account"], {}]) do warnings = capture(:stderr) { Quails::Generators.invoke :model, ["Account"] } assert warnings.empty? end end
test_simple_invoke()
click to toggle source
# File railties/test/generators_test.rb, line 19 def test_simple_invoke assert File.exist?(File.join(@path, "generators", "model_generator.rb")) assert_called_with(TestUnit::Generators::ModelGenerator, :start, [["Account"], {}]) do Quails::Generators.invoke("test_unit:model", ["Account"]) end end
test_source_paths_for_not_namespaced_generators()
click to toggle source
# File railties/test/generators_test.rb, line 232 def test_source_paths_for_not_namespaced_generators mspec = Quails::Generators.find_by_namespace :fixjour assert_includes mspec.source_paths, File.join(Quails.root, "lib", "templates", "fixjour") end
test_usage_with_embedded_ruby()
click to toggle source
# File railties/test/generators_test.rb, line 237 def test_usage_with_embedded_ruby require_relative "fixtures/lib/generators/usage_template/usage_template_generator" output = capture(:stdout) { Quails::Generators.invoke :usage_template, ["--help"] } assert_match(/:: 2 ::/, output) end