From 6f0d5aae9fca2806311860284e755995adec500f Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Fri, 21 Sep 2012 19:02:06 +0300 Subject: [PATCH] handle namespaced models in spec generators closes #279 --- lib/generators/rspec/decorator_generator.rb | 2 +- .../test_unit/decorator_generator.rb | 2 +- .../decorator/decorator_generator_spec.rb | 22 ++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/generators/rspec/decorator_generator.rb b/lib/generators/rspec/decorator_generator.rb index 8373634..6b97c33 100644 --- a/lib/generators/rspec/decorator_generator.rb +++ b/lib/generators/rspec/decorator_generator.rb @@ -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 diff --git a/lib/generators/test_unit/decorator_generator.rb b/lib/generators/test_unit/decorator_generator.rb index d2ab0c8..b0f3a28 100644 --- a/lib/generators/test_unit/decorator_generator.rb +++ b/lib/generators/test_unit/decorator_generator.rb @@ -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 diff --git a/spec/generators/decorator/decorator_generator_spec.rb b/spec/generators/decorator/decorator_generator_spec.rb index 503c77e..a96b50a 100644 --- a/spec/generators/decorator/decorator_generator_spec.rb +++ b/spec/generators/decorator/decorator_generator_spec.rb @@ -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