mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Add a RSpec generator and hook to create default decorator specs
This commit is contained in:
parent
72f87569a3
commit
fa4f2ebbd5
5 changed files with 58 additions and 1 deletions
|
@ -13,5 +13,7 @@ module Draper
|
|||
end
|
||||
template 'decorator.rb', "#{DECORATORS_ROOT}#{singular_name}_decorator.rb"
|
||||
end
|
||||
|
||||
hook_for :test_framework
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
17
lib/generators/rspec/decorator_generator.rb
Normal file
17
lib/generators/rspec/decorator_generator.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Rspec
|
||||
class DecoratorGenerator < ::Rails::Generators::NamedBase
|
||||
source_root File.expand_path('../templates', __FILE__)
|
||||
|
||||
SPEC_ROOT = 'spec/decorators/'
|
||||
APPLICATION_DECORATOR_SPEC = 'application_decorator_spec.rb'
|
||||
APPLICATION_DECORATOR_SPEC_PATH = SPEC_ROOT + APPLICATION_DECORATOR_SPEC
|
||||
|
||||
def build_model_and_application_decorator_specs
|
||||
empty_directory SPEC_ROOT
|
||||
unless File.exists?(APPLICATION_DECORATOR_SPEC_PATH)
|
||||
template APPLICATION_DECORATOR_SPEC, APPLICATION_DECORATOR_SPEC_PATH
|
||||
end
|
||||
template 'decorator_spec.rb', "#{SPEC_ROOT}#{singular_name}_decorator_spec.rb"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ApplicationDecorator do
|
||||
before { ApplicationController.new.set_current_view_context }
|
||||
end
|
5
lib/generators/rspec/templates/decorator_spec.rb
Normal file
5
lib/generators/rspec/templates/decorator_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe <%= singular_name.camelize %>Decorator do
|
||||
before { ApplicationController.new.set_current_view_context }
|
||||
end
|
28
spec/generators/rspec/decorator_generator_spec.rb
Normal file
28
spec/generators/rspec/decorator_generator_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# Generators are not automatically loaded by Rails
|
||||
require 'generators/rspec/decorator_generator'
|
||||
|
||||
describe Rspec::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 'spec/decorators/application_decorator_spec.rb' do
|
||||
subject { file('spec/decorators/application_decorator_spec.rb') }
|
||||
it { should exist }
|
||||
it { should contain "describe ApplicationDecorator do" }
|
||||
end
|
||||
|
||||
describe 'spec/decorators/products_decorator_spec.rb' do
|
||||
subject { file('spec/decorators/products_decorator_spec.rb') }
|
||||
it { should exist }
|
||||
it { should contain "describe ProductsDecorator" }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue