Add MiniTest generators

This commit is contained in:
Andrew Haines 2013-01-14 11:57:06 +00:00
parent 1d7619f48f
commit 1fac02b65b
4 changed files with 69 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,4 @@
require 'minitest_helper'
describe <%= class_name %>Decorator do
end

View File

@ -0,0 +1,4 @@
require 'minitest_helper'
class <%= class_name %>DecoratorTest < Draper::TestCase
end

View File

@ -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