mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Add MiniTest generators
This commit is contained in:
parent
1d7619f48f
commit
1fac02b65b
4 changed files with 69 additions and 0 deletions
20
lib/generators/mini_test/decorator_generator.rb
Normal file
20
lib/generators/mini_test/decorator_generator.rb
Normal 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
|
4
lib/generators/mini_test/templates/decorator_spec.rb
Normal file
4
lib/generators/mini_test/templates/decorator_spec.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'minitest_helper'
|
||||
|
||||
describe <%= class_name %>Decorator do
|
||||
end
|
4
lib/generators/mini_test/templates/decorator_test.rb
Normal file
4
lib/generators/mini_test/templates/decorator_test.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
require 'minitest_helper'
|
||||
|
||||
class <%= class_name %>DecoratorTest < Draper::TestCase
|
||||
end
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue