2011-10-06 20:58:04 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
# Generators are not automatically loaded by Rails
|
|
|
|
require 'generators/draper/decorator/decorator_generator'
|
|
|
|
|
|
|
|
describe Draper::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 }
|
|
|
|
|
2012-02-14 02:19:03 +00:00
|
|
|
context 'decorator context' do
|
2012-03-31 15:36:27 +00:00
|
|
|
before { run_generator ["YourModel"] }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'app/decorators/your_model_decorator.rb' do
|
|
|
|
subject { file('app/decorators/your_model_decorator.rb') }
|
2012-02-14 02:19:03 +00:00
|
|
|
it { should exist }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "class YourModelDecorator < ApplicationDecorator" }
|
|
|
|
it { should contain "decorates :your_model" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-27 14:33:19 +00:00
|
|
|
context 'decorator name' do
|
2012-03-31 15:36:27 +00:00
|
|
|
before { run_generator ["YourModel"] }
|
2012-03-27 14:33:19 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'spec/decorators/your_model_decorator_spec.rb' do
|
|
|
|
subject { file('spec/decorators/your_model_decorator_spec.rb') }
|
2012-03-27 14:33:19 +00:00
|
|
|
it { should exist }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "describe YourModelDecorator" }
|
2012-03-27 14:33:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-14 02:19:03 +00:00
|
|
|
context 'default test framework' do
|
2012-03-31 15:36:27 +00:00
|
|
|
before { run_generator ["YourModel"] }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'spec/decorators/your_model_decorator_spec.rb' do
|
|
|
|
subject { file('spec/decorators/your_model_decorator_spec.rb') }
|
2012-02-14 02:19:03 +00:00
|
|
|
it { should exist }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "describe YourModelDecorator" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'using rspec' do
|
2012-03-31 15:36:27 +00:00
|
|
|
before { run_generator ["YourModel", "-t=rspec"] }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'spec/decorators/your_model_decorator_spec.rb' do
|
|
|
|
subject { file('spec/decorators/your_model_decorator_spec.rb') }
|
2012-02-14 02:19:03 +00:00
|
|
|
it { should exist }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "describe YourModelDecorator" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'using rspec' do
|
2012-03-31 15:36:27 +00:00
|
|
|
before { run_generator ["YourModel", "-t=test_unit"] }
|
2012-02-14 02:19:03 +00:00
|
|
|
|
2012-03-31 15:36:27 +00:00
|
|
|
describe 'test/decorators/YourModel_decorator_test.rb' do
|
|
|
|
subject { file('test/decorators/your_model_decorator_test.rb') }
|
2012-02-14 02:19:03 +00:00
|
|
|
it { should exist }
|
2012-03-31 15:36:27 +00:00
|
|
|
it { should contain "class YourModelDecoratorTest < ActiveSupport::TestCase" }
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
=begin
|
2011-10-06 20:58:04 +00:00
|
|
|
describe 'no arguments' do
|
|
|
|
before { run_generator %w(products) }
|
|
|
|
|
|
|
|
describe 'app/decorators/products_decorator.rb' do
|
|
|
|
subject { file('app/decorators/products_decorator.rb') }
|
|
|
|
it { should exist }
|
|
|
|
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
|
|
|
end
|
2012-02-14 02:19:03 +00:00
|
|
|
end
|
|
|
|
|
2012-03-03 14:01:19 +00:00
|
|
|
|
2012-02-14 02:19:03 +00:00
|
|
|
context 'simple' do
|
|
|
|
before { run_generator %w(products) }
|
|
|
|
|
|
|
|
describe 'app/decorators/products_decorator.rb' do
|
|
|
|
subject { file('app/decorators/products_decorator.rb') }
|
|
|
|
it { should exist }
|
|
|
|
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'using rspec' do
|
|
|
|
|
|
|
|
describe 'app/decorators/products_decorator.rb' do
|
|
|
|
subject { file('app/decorators/products_decorator.rb') }
|
|
|
|
it { should exist }
|
|
|
|
it { should contain "class ProductsDecorator < ApplicationDecorator" }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for "ApplicationDecoratorGenerator" do
|
|
|
|
describe 'app/decorators/application_decorator.rb' do
|
|
|
|
subject { file('app/decorators/application_decorator.rb') }
|
|
|
|
it { should exist }
|
|
|
|
it { should contain "class ApplicationDecorator < Draper::Base" }
|
|
|
|
end
|
|
|
|
end
|
2011-10-06 20:58:04 +00:00
|
|
|
|
2012-02-14 02:19:03 +00:00
|
|
|
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
|
2011-10-06 20:58:04 +00:00
|
|
|
end
|
2012-03-03 14:01:19 +00:00
|
|
|
=end
|