diff --git a/lib/producer/core/action.rb b/lib/producer/core/action.rb index d4f4bd2..6f67297 100644 --- a/lib/producer/core/action.rb +++ b/lib/producer/core/action.rb @@ -1,6 +1,11 @@ module Producer module Core class Action + require 'forwardable' + + extend Forwardable + def_delegator :@env, :output + attr_accessor :env, :arguments def initialize(env, *args) diff --git a/lib/producer/core/actions/echo.rb b/lib/producer/core/actions/echo.rb index 67da13b..4547179 100644 --- a/lib/producer/core/actions/echo.rb +++ b/lib/producer/core/actions/echo.rb @@ -3,7 +3,7 @@ module Producer module Actions class Echo < Action def apply - env.output.puts arguments.first + output.puts arguments.first end end end diff --git a/lib/producer/core/actions/shell_command.rb b/lib/producer/core/actions/shell_command.rb index 2117783..6431337 100644 --- a/lib/producer/core/actions/shell_command.rb +++ b/lib/producer/core/actions/shell_command.rb @@ -3,7 +3,7 @@ module Producer module Actions class ShellCommand < Action def apply - env.output.puts env.remote.execute(arguments.first) + output.puts env.remote.execute(arguments.first) end end end diff --git a/spec/producer/core/action_spec.rb b/spec/producer/core/action_spec.rb index ffa6ac8..65aab5e 100644 --- a/spec/producer/core/action_spec.rb +++ b/spec/producer/core/action_spec.rb @@ -17,5 +17,12 @@ module Producer::Core expect(action.arguments).to eq arguments end end + + describe '#output' do + it 'delegates to env output' do + expect(action.env).to receive(:output).with(:content) + action.output :content + end + end end end diff --git a/spec/producer/core/actions/echo_spec.rb b/spec/producer/core/actions/echo_spec.rb index af4d545..280dc55 100644 --- a/spec/producer/core/actions/echo_spec.rb +++ b/spec/producer/core/actions/echo_spec.rb @@ -7,7 +7,7 @@ module Producer::Core subject(:echo) { Actions::Echo.new(env, text) } describe '#apply' do - it 'writes the given string to env.output with a record separator' do + it 'writes the given string to env output with a record separator' do echo.apply expect(env.output.string).to eq "hello\n" end