Evaluate run control file when present

This commit is contained in:
Thibault Jouan 2015-04-14 00:38:45 +00:00
parent 8165a1d4f5
commit 7493ab3284
4 changed files with 47 additions and 3 deletions

View File

@ -0,0 +1,10 @@
@mocked_home_directory
Feature: run control file evaluation
Scenario: evaluates the default run control file when it exists
Given a file named .uhwmrc.rb with:
"""
puts 'run control evaluation'
"""
When I start uhwm
Then the output must contain "run control evaluation"

View File

@ -19,6 +19,10 @@ Then /^the output must contain:$/ do |content|
uhwm_wait_output content.to_s
end
Then /^the output must contain "([^"]+)"$/ do |content|
uhwm_wait_output content.to_s
end
Then /^the output must contain current display$/ do
uhwm_wait_output ENV['DISPLAY']
end

View File

@ -4,6 +4,7 @@ module Uh
class << self
def run env, **options
runner = new env, **options
runner.evaluate_run_control
runner.register_event_hooks
runner.connect_manager
runner.run_until { runner.stopped? }
@ -30,6 +31,11 @@ module Uh
@stopped = true
end
def evaluate_run_control
rc_path = File.expand_path(@env.rc_path)
eval File.read(rc_path) if File.exist?(rc_path)
end
def register_event_hooks
register_manager_hooks
register_layout_event_hooks

View File

@ -1,3 +1,5 @@
require 'support/filesystem_helpers'
SomeLayout = Class.new do
define_method(:register) { |*args| }
end
@ -5,11 +7,16 @@ end
module Uh
module WM
RSpec.describe Runner do
let(:env) do
Env.new(StringIO.new).tap { |o| o.layout_class = SomeLayout }
end
include FileSystemHelpers
let(:env) { Env.new(StringIO.new) }
subject(:runner) { described_class.new env }
before do
env.layout_class = SomeLayout
env.rc_path = 'non_existent_run_control.rb'
end
describe '#initialize' do
it 'assigns the env' do
expect(runner.env).to be env
@ -52,6 +59,23 @@ module Uh
end
end
describe '#evaluate_run_control' do
context 'when run control file exists' do
it 'evaluates the run control file' do
with_file 'throw :run_control' do |f|
env.rc_path = f.path
expect { runner.evaluate_run_control }.to throw_symbol :run_control
end
end
end
context 'when run control file does not exist' do
it 'does not raise any error' do
expect { runner.evaluate_run_control }.not_to raise_error
end
end
end
describe '#register_event_hooks' do
it 'registers manager event hooks for logging' do
runner.register_event_hooks