draper/spec/generators/decorator/decorator_generator_spec.rb

139 lines
4.6 KiB
Ruby
Raw Normal View History

require 'spec_helper'
require 'ammeter/init'
# Generators are not automatically loaded by Rails
require 'generators/decorator/decorator_generator'
describe Rails::Generators::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
before { run_generator ["YourModel"] }
2012-02-14 02:19:03 +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-10-09 08:51:40 +00:00
it { should contain "class YourModelDecorator < Draper::Decorator" }
2012-02-14 02:19:03 +00:00
end
end
context 'decorator name' do
2012-04-28 19:26:57 +00:00
before { run_generator ["YourModel", '-t=rspec'] }
2012-02-14 02:19:03 +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 }
it { should contain "describe YourModelDecorator" }
2012-02-14 02:19:03 +00:00
end
end
context 'parent decorator' do
2012-12-01 17:49:18 +00:00
describe 'decorator inherited from Draper::Decorator' do
before { run_generator ["YourModel"] }
subject { file('app/decorators/your_model_decorator.rb') }
it { should exist }
2012-10-09 08:51:40 +00:00
it { should contain "class YourModelDecorator < Draper::Decorator" }
end
2012-12-01 17:49:18 +00:00
describe "decorator inherited from ApplicationDecorator if it's present" do
before do
class ApplicationDecorator; end
run_generator ["YourModel"]
end
2012-06-08 23:14:48 +00:00
after do
Object.send(:remove_const, :ApplicationDecorator)
end
subject { file('app/decorators/your_model_decorator.rb') }
it { should exist }
it { should contain "class YourModelDecorator < ApplicationDecorator" }
end
end
2012-02-14 02:19:03 +00:00
context 'using rspec' do
before { run_generator ["YourModel", "-t=rspec"] }
2012-02-14 02:19:03 +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 }
it { should contain "describe YourModelDecorator" }
2012-02-14 02:19:03 +00:00
end
end
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"] }
2012-02-14 02:19:03 +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 }
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
2012-02-14 02:19:03 +00:00
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 < Draper::TestCase" }
end
end
2013-01-14 11:57:06 +00:00
context 'using minitest-rails' do
before { run_generator ["YourModel", "-t=mini_test"] }
describe 'test/decorators/your_model_decorator_test.rb' do
subject { file('test/decorators/your_model_decorator_test.rb') }
it { should exist }
it { should contain "class YourModelDecoratorTest < Draper::TestCase" }
end
end
context 'using minitest-rails with namespaced model' do
before { run_generator ["Namespace::YourModel", "-t=mini_test"] }
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 < Draper::TestCase" }
end
end
context 'using minitest-rails with spec syntax' do
before { run_generator ["YourModel", "-t=mini_test", "--spec"] }
describe 'test/decorators/your_model_decorator_test.rb' do
subject { file('test/decorators/your_model_decorator_test.rb') }
it { should exist }
it { should contain "describe YourModelDecorator" }
end
end
context 'using minitest-rails with spec syntax with namespaced model' do
before { run_generator ["Namespace::YourModel", "-t=mini_test", "--spec"] }
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 "describe Namespace::YourModelDecorator" }
end
end
2012-02-14 02:19:03 +00:00
end