From a848e6b9369a71dde8c281161a47976670db7983 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Fri, 10 Apr 2015 07:11:29 +0000 Subject: [PATCH] Instantiate and assign a Layout in the Runner --- lib/uh/wm/runner.rb | 4 +++- spec/uh/wm/runner_spec.rb | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/uh/wm/runner.rb b/lib/uh/wm/runner.rb index cf16f54..bbeba0c 100644 --- a/lib/uh/wm/runner.rb +++ b/lib/uh/wm/runner.rb @@ -10,12 +10,14 @@ module Uh end end - attr_reader :env, :events, :manager + attr_reader :env, :events, :manager, :layout def initialize env, manager: nil, stopped: false + raise ArgumentError, 'missing env layout class' unless env.layout_class @env = env @events = Dispatcher.new @manager = manager || Manager.new(@events) + @layout = @env.layout_class.new @stopped = stopped end diff --git a/spec/uh/wm/runner_spec.rb b/spec/uh/wm/runner_spec.rb index 8a9a500..15cbbfa 100644 --- a/spec/uh/wm/runner_spec.rb +++ b/spec/uh/wm/runner_spec.rb @@ -1,8 +1,12 @@ +SomeLayout = Class.new + module Uh module WM RSpec.describe Runner do - let(:env) { Env.new(StringIO.new) } - subject(:runner) { described_class.new env } + let(:env) do + Env.new(StringIO.new).tap { |o| o.layout_class = SomeLayout } + end + subject(:runner) { described_class.new env } describe '.run' do subject(:run) { described_class.run env, stopped: true } @@ -49,6 +53,17 @@ module Uh it 'is not stopped' do expect(runner).not_to be_stopped end + + it 'assigns a new layout instance' do + expect(runner.layout).to be_an_instance_of SomeLayout + end + + context 'when the env has no layout set' do + before { env.layout_class = nil } + it 'raises an ArgumentError' do + expect { runner }.to raise_error WM::ArgumentError + end + end end describe '#stopped?' do