draper/spec/generators/decorator/decorator_generator_spec.rb

93 lines
2.8 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2017-02-23 16:18:59 +00:00
require 'dummy/config/environment'
require 'ammeter/init'
require 'generators/rails/decorator_generator'
describe Rails::Generators::DecoratorGenerator do
destination File.expand_path("../tmp", __FILE__)
before { prepare_destination }
after(:all) { FileUtils.rm_rf destination_root }
describe "the generated decorator" do
subject { file("app/decorators/your_model_decorator.rb") }
2012-02-14 02:19:03 +00:00
describe "naming" do
before { run_generator %w(YourModel) }
2012-02-14 02:19:03 +00:00
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "class YourModelDecorator" }
2012-02-14 02:19:03 +00:00
end
describe "namespacing" do
subject { file("app/decorators/namespace/your_model_decorator.rb") }
before { run_generator %w(Namespace::YourModel) }
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "class Namespace::YourModelDecorator" }
end
describe "inheritance" do
context "by default" do
before { run_generator %w(YourModel) }
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "class YourModelDecorator < Draper::Decorator" }
end
context "with the --parent option" do
before { run_generator %w(YourModel --parent=FooDecorator) }
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "class YourModelDecorator < FooDecorator" }
2012-06-08 23:14:48 +00:00
end
context "with an ApplicationDecorator" do
before do
allow_any_instance_of(Object).to receive(:require).with("application_decorator").and_return(
stub_const "ApplicationDecorator", Class.new
)
end
before { run_generator %w(YourModel) }
2012-02-14 02:19:03 +00:00
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "class YourModelDecorator < ApplicationDecorator" }
end
2012-02-14 02:19:03 +00:00
end
end
context "with -t=rspec" do
describe "the generated spec" do
subject { file("spec/decorators/your_model_decorator_spec.rb") }
describe "naming" do
before { run_generator %w(YourModel -t=rspec) }
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "describe YourModelDecorator" }
end
describe "namespacing" do
subject { file("spec/decorators/namespace/your_model_decorator_spec.rb") }
before { run_generator %w(Namespace::YourModel -t=rspec) }
2012-02-14 02:19:03 +00:00
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "describe Namespace::YourModelDecorator" }
end
2012-02-14 02:19:03 +00:00
end
end
context "with -t=test_unit" do
describe "the generated test" do
subject { file("test/decorators/your_model_decorator_test.rb") }
describe "naming" do
before { run_generator %w(YourModel -t=test_unit) }
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "class YourModelDecoratorTest < Draper::TestCase" }
end
2013-01-14 11:57:06 +00:00
describe "namespacing" do
subject { file("test/decorators/namespace/your_model_decorator_test.rb") }
before { run_generator %w(Namespace::YourModel -t=test_unit) }
2013-01-14 11:57:06 +00:00
2016-06-09 21:49:42 +00:00
it { is_expected.to contain "class Namespace::YourModelDecoratorTest < Draper::TestCase" }
end
2013-01-14 11:57:06 +00:00
end
end
2012-02-14 02:19:03 +00:00
end