Implement `layout' run control keyword

Allow configuration of the layout by specifying either a class or an
instance.
This commit is contained in:
Thibault Jouan
2015-04-26 00:59:24 +00:00
parent 7c06b52664
commit bf6f08e848
5 changed files with 69 additions and 10 deletions

View File

@@ -70,19 +70,27 @@ module Uh
end
describe '#layout' do
context 'when a layout class is set' do
let(:some_layout) { Class.new }
let(:some_layout_class) { Class.new }
before { env.layout_class = some_layout }
it 'returns the default layout' do
expect(env.layout).to be_an_instance_of ::Uh::Layout
end
it 'returns a new instance of this layout class' do
expect(env.layout).to be_an_instance_of some_layout
context 'when a layout is set' do
let(:some_layout) { some_layout_class.new }
before { env.layout = some_layout }
it 'returns the assigned layout' do
expect(env.layout).to be some_layout
end
end
context 'when a layout class is not set' do
it 'returns an instance of the default layout' do
expect(env.layout).to be_an_instance_of ::Uh::Layout
context 'when a layout class is set' do
before { env.layout_class = some_layout_class }
it 'returns a new instance of this layout class' do
expect(env.layout).to be_an_instance_of some_layout_class
end
end
end

View File

@@ -85,6 +85,22 @@ module Uh
end
end
describe '#layout' do
context 'when given a class' do
it 'sets a layout class in the env' do
rc.layout layout_class = Class.new
expect(env.layout_class).to be layout_class
end
end
context 'when given an object' do
it 'sets a layout instance in the env' do
rc.layout layout = Object.new
expect(env.layout).to eq layout
end
end
end
describe '#worker' do
it 'sets the worker type in the env' do
rc.worker :some_worker