Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MiniTest generators #420

Merged
merged 1 commit into from
Jan 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/generators/mini_test/decorator_generator.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions lib/generators/mini_test/templates/decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'minitest_helper'

describe <%= class_name %>Decorator do
end
4 changes: 4 additions & 0 deletions lib/generators/mini_test/templates/decorator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'minitest_helper'

class <%= class_name %>DecoratorTest < Draper::TestCase
end
41 changes: 41 additions & 0 deletions spec/generators/decorator/decorator_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,45 @@ class ApplicationDecorator; end
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