Merge branch 'layout-rc-config'
This commit is contained in:
commit
f9d905e498
39
features/run_control/layout.feature
Normal file
39
features/run_control/layout.feature
Normal file
@ -0,0 +1,39 @@
|
||||
Feature: `layout' run control keyword
|
||||
|
||||
Background:
|
||||
Given a file named my_layout.rb with:
|
||||
"""
|
||||
class MyLayout
|
||||
def initialize **options
|
||||
puts "testing_rc_layout_#{options.inspect}" if options.any?
|
||||
end
|
||||
|
||||
def register *_, **options
|
||||
puts "testing_rc_layout_register"
|
||||
end
|
||||
end
|
||||
"""
|
||||
|
||||
Scenario: configures a layout class
|
||||
Given a run control file with:
|
||||
"""
|
||||
layout MyLayout
|
||||
"""
|
||||
When I run uhwm with options -r./my_layout
|
||||
Then the output must contain "testing_rc_layout_register"
|
||||
|
||||
Scenario: configures a layout class with options
|
||||
Given a run control file with:
|
||||
"""
|
||||
layout MyLayout, foo: :bar
|
||||
"""
|
||||
When I run uhwm with options -r./my_layout
|
||||
Then the output must contain "testing_rc_layout_{:foo=>:bar}"
|
||||
|
||||
Scenario: configures a layout instance
|
||||
Given a run control file with:
|
||||
"""
|
||||
layout MyLayout.new
|
||||
"""
|
||||
When I run uhwm with options -r./my_layout
|
||||
Then the output must contain "testing_rc_layout_register"
|
@ -21,8 +21,8 @@ module Uh
|
||||
def_delegators :@output, :print, :puts
|
||||
|
||||
attr_reader :output, :keybinds
|
||||
attr_accessor :verbose, :debug, :rc_path, :layout_class, :modifier,
|
||||
:worker
|
||||
attr_accessor :verbose, :debug, :rc_path, :modifier, :worker,
|
||||
:layout, :layout_class
|
||||
|
||||
def initialize output
|
||||
@output = output
|
||||
|
@ -32,6 +32,18 @@ module Uh
|
||||
@env.keybinds[translate_keysym *keysyms] = block
|
||||
end
|
||||
|
||||
def layout arg, **options
|
||||
if arg.is_a? Class
|
||||
if options.any?
|
||||
@env.layout = arg.new options
|
||||
else
|
||||
@env.layout_class = arg
|
||||
end
|
||||
else
|
||||
@env.layout = arg
|
||||
end
|
||||
end
|
||||
|
||||
def worker type, **options
|
||||
@env.worker = [type, options]
|
||||
end
|
||||
|
@ -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
|
||||
|
@ -85,6 +85,31 @@ module Uh
|
||||
end
|
||||
end
|
||||
|
||||
describe '#layout' do
|
||||
context 'when given a class' do
|
||||
let(:layout_class) { Class.new }
|
||||
|
||||
it 'sets a layout class in the env' do
|
||||
rc.layout layout_class
|
||||
expect(env.layout_class).to be layout_class
|
||||
end
|
||||
|
||||
context 'when given options' do
|
||||
it 'instantiates the class with given options' do
|
||||
expect(layout_class).to receive(:new).with(foo: :bar)
|
||||
rc.layout layout_class, foo: :bar
|
||||
end
|
||||
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
|
||||
|
@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
||||
s.executables = s.files.grep(/\Abin\//) { |f| File.basename(f) }
|
||||
|
||||
s.add_dependency 'uh', '2.0.0.pre2'
|
||||
s.add_dependency 'uh-layout', '~> 0.2.3'
|
||||
s.add_dependency 'uh-layout', '~> 0.3.0'
|
||||
|
||||
s.add_development_dependency 'aruba', '~> 0.6'
|
||||
s.add_development_dependency 'cucumber', '~> 2.0'
|
||||
|
Loading…
x
Reference in New Issue
Block a user