Merge pull request #280 from nashby/fix-issue-279

handle namespaced models in spec generators
This commit is contained in:
Steve Klabnik 2012-09-21 14:45:30 -07:00
commit 984f33fc12
3 changed files with 23 additions and 3 deletions

View File

@ -3,7 +3,7 @@ module Rspec
source_root File.expand_path('../templates', __FILE__)
def create_spec_file
template 'decorator_spec.rb', File.join('spec/decorators', "#{singular_name}_decorator_spec.rb")
template 'decorator_spec.rb', File.join('spec/decorators', class_path, "#{singular_name}_decorator_spec.rb")
end
end
end

View File

@ -3,7 +3,7 @@ module TestUnit
source_root File.expand_path('../templates', __FILE__)
def create_test_file
template 'decorator_test.rb', File.join('test/decorators', "#{singular_name}_decorator_test.rb")
template 'decorator_test.rb', File.join('test/decorators', class_path, "#{singular_name}_decorator_test.rb")
end
end
end

View File

@ -65,7 +65,17 @@ describe Rails::Generators::DecoratorGenerator do
end
end
context 'using rspec' do
context 'using rspec with namespaced model' do
before { run_generator ["Namespace::YourModel", "-t=rspec"] }
describe 'spec/decorators/your_model_decorator_spec.rb' do
subject { file('spec/decorators/namespace/your_model_decorator_spec.rb') }
it { should exist }
it { should contain "describe Namespace::YourModelDecorator" }
end
end
context 'using test-unit' do
before { run_generator ["YourModel", "-t=test_unit"] }
describe 'test/decorators/YourModel_decorator_test.rb' do
@ -74,4 +84,14 @@ describe Rails::Generators::DecoratorGenerator do
it { should contain "class YourModelDecoratorTest < ActiveSupport::TestCase" }
end
end
context 'using test-unit with namespaced model' do
before { run_generator ["Namespace::YourModel", "-t=test_unit"] }
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 < ActiveSupport::TestCase" }
end
end
end