diff --git a/lib/generators/mini_test/decorator_generator.rb b/lib/generators/mini_test/decorator_generator.rb new file mode 100644 index 0000000..cedea48 --- /dev/null +++ b/lib/generators/mini_test/decorator_generator.rb @@ -0,0 +1,20 @@ +require 'generators/mini_test' + +module MiniTest + module Generators + class DecoratorGenerator < Base + def self.source_root + File.expand_path('../templates', __FILE__) + end + + class_option :spec, :type => :boolean, :default => false, :desc => "Use MiniTest::Spec DSL" + + check_class_collision suffix: "DecoratorTest" + + def create_test_file + template_type = options[:spec] ? "spec" : "test" + template "decorator_#{template_type}.rb", File.join("test/decorators", class_path, "#{singular_name}_decorator_test.rb") + end + end + end +end diff --git a/lib/generators/mini_test/templates/decorator_spec.rb b/lib/generators/mini_test/templates/decorator_spec.rb new file mode 100644 index 0000000..dee5750 --- /dev/null +++ b/lib/generators/mini_test/templates/decorator_spec.rb @@ -0,0 +1,4 @@ +require 'minitest_helper' + +describe <%= class_name %>Decorator do +end diff --git a/lib/generators/mini_test/templates/decorator_test.rb b/lib/generators/mini_test/templates/decorator_test.rb new file mode 100644 index 0000000..e651afe --- /dev/null +++ b/lib/generators/mini_test/templates/decorator_test.rb @@ -0,0 +1,4 @@ +require 'minitest_helper' + +class <%= class_name %>DecoratorTest < Draper::TestCase +end diff --git a/spec/generators/decorator/decorator_generator_spec.rb b/spec/generators/decorator/decorator_generator_spec.rb index d1d62c1..ad8550f 100644 --- a/spec/generators/decorator/decorator_generator_spec.rb +++ b/spec/generators/decorator/decorator_generator_spec.rb @@ -93,4 +93,45 @@ describe Rails::Generators::DecoratorGenerator do it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" } end end + + context 'using minitest-rails' do + before { run_generator ["YourModel", "-t=mini_test"] } + + describe 'test/decorators/your_model_decorator_test.rb' do + subject { file('test/decorators/your_model_decorator_test.rb') } + it { should exist } + it { should contain "class YourModelDecoratorTest < Draper::TestCase" } + end + end + + context 'using minitest-rails with namespaced model' do + before { run_generator ["Namespace::YourModel", "-t=mini_test"] } + + describe 'test/decorators/your_model_decorator_test.rb' do + subject { file('test/decorators/namespace/your_model_decorator_test.rb') } + it { should exist } + it { should contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" } + end + end + + context 'using minitest-rails with spec syntax' do + before { run_generator ["YourModel", "-t=mini_test", "--spec"] } + + describe 'test/decorators/your_model_decorator_test.rb' do + subject { file('test/decorators/your_model_decorator_test.rb') } + it { should exist } + it { should contain "describe YourModelDecorator" } + end + end + + context 'using minitest-rails with spec syntax with namespaced model' do + before { run_generator ["Namespace::YourModel", "-t=mini_test", "--spec"] } + + describe 'test/decorators/your_model_decorator_test.rb' do + subject { file('test/decorators/namespace/your_model_decorator_test.rb') } + it { should exist } + it { should contain "describe Namespace::YourModelDecorator" } + end + end + end