Merge pull request #56 from bdotdub/master

Adding Test::Unit test generator
This commit is contained in:
Jeff Casimir 2011-10-19 20:38:28 -07:00
commit 494bb2438f
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