Refactor generator for TestUnit, RSpec (#816)

* Refactor generator for TestUnit

* Refactor generators for RSpec

* Refactor source_root for cosme
This commit is contained in:
yhirano 2017-07-20 22:51:30 +09:00 committed by Cliff Braton
parent 607f03e908
commit cfe4d33733
5 changed files with 16 additions and 11 deletions

View File

@ -1,7 +1,7 @@
module Draper
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path("templates", __dir__)
desc 'Creates an ApplicationDecorator, if none exists.'

View File

@ -4,7 +4,7 @@ module MiniTest
module Generators
class DecoratorGenerator < Base
def self.source_root
File.expand_path('../templates', __FILE__)
File.expand_path("templates", __dir__)
end
class_option :spec, type: :boolean, default: false, desc: "Use MiniTest::Spec DSL"

View File

@ -1,7 +1,7 @@
module Rails
module Generators
class DecoratorGenerator < NamedBase
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)
check_class_collision suffix: "Decorator"
class_option :parent, type: :string, desc: "The parent class for the generated decorator"

View File

@ -1,9 +1,11 @@
module Rspec
class DecoratorGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
module Generators
class DecoratorGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path("templates", __dir__)
def create_spec_file
template 'decorator_spec.rb', File.join('spec/decorators', class_path, "#{singular_name}_decorator_spec.rb")
def create_spec_file
template 'decorator_spec.rb', File.join('spec/decorators', class_path, "#{singular_name}_decorator_spec.rb")
end
end
end
end

View File

@ -1,9 +1,12 @@
module TestUnit
class DecoratorGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
module Generators
class DecoratorGenerator < ::Rails::Generators::NamedBase
source_root File.expand_path("templates", __dir__)
check_class_collision suffix: "DecoratorTest"
def create_test_file
template 'decorator_test.rb', File.join('test/decorators', class_path, "#{singular_name}_decorator_test.rb")
def create_test_file
template 'decorator_test.rb', File.join('test/decorators', class_path, "#{singular_name}_decorator_test.rb")
end
end
end
end