1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Add a Test::Unit generator and hook to create default decorator tests

This commit is contained in:
Benny Wong 2011-10-19 22:54:35 -04:00
parent 19f1fc7b69
commit ca3cf912e0
4 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,17 @@
module TestUnit
class DecoratorGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
TEST_ROOT = 'test/decorators/'
APPLICATION_DECORATOR_TEST = 'application_decorator_test.rb'
APPLICATION_DECORATOR_TEST_PATH = TEST_ROOT + APPLICATION_DECORATOR_TEST
def build_model_and_application_decorator_tests
empty_directory TEST_ROOT
unless File.exists?(APPLICATION_DECORATOR_TEST_PATH)
template APPLICATION_DECORATOR_TEST, APPLICATION_DECORATOR_TEST_PATH
end
template 'decorator_test.rb', "#{TEST_ROOT}#{singular_name}_decorator_test.rb"
end
end
end

View file

@ -0,0 +1,11 @@
require 'test_helper'
class ApplicationDecoratorTest < ActiveSupport::TestCase
def setup
ApplicationController.new.set_current_view_context
end
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,12 @@
require 'test_helper'
class <%= singular_name.camelize %>DecoratorTest < ActiveSupport::TestCase
def setup
ApplicationController.new.set_current_view_context
end
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,28 @@
require 'spec_helper'
# Generators are not automatically loaded by Rails
require 'generators/test_unit/decorator_generator'
describe TestUnit::DecoratorGenerator do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path("../../../../tmp", __FILE__)
before { prepare_destination }
describe 'no arguments' do
before { run_generator %w(products) }
describe 'test/decorators/application_decorator_test.rb' do
subject { file('test/decorators/application_decorator_test.rb') }
it { should exist }
it { should contain "class ApplicationDecoratorTest < ActiveSupport::TestCase" }
end
describe 'test/decorators/products_decorator_test.rb' do
subject { file('test/decorators/products_decorator_test.rb') }
it { should exist }
it { should contain "class ProductsDecoratorTest < ActiveSupport::TestCase" }
end
end
end