diff --git a/features/actions/echo.feature b/features/actions/echo.feature new file mode 100644 index 0000000..b3ba7a4 --- /dev/null +++ b/features/actions/echo.feature @@ -0,0 +1,12 @@ +Feature: `echo' task action + + Scenario: ouputs text + Given a recipe with: + """ + task :some_task do + echo 'hello' + end + """ + When I execute the recipe + Then the exit status must be 0 + And the output must contain exactly "hello\n" diff --git a/lib/producer/core.rb b/lib/producer/core.rb index 40054f9..96018fe 100644 --- a/lib/producer/core.rb +++ b/lib/producer/core.rb @@ -1,4 +1,5 @@ require 'producer/core/action' +require 'producer/core/actions/echo' require 'producer/core/actions/shell_command' require 'producer/core/cli' require 'producer/core/env' diff --git a/lib/producer/core/actions/echo.rb b/lib/producer/core/actions/echo.rb new file mode 100644 index 0000000..88454ed --- /dev/null +++ b/lib/producer/core/actions/echo.rb @@ -0,0 +1,11 @@ +module Producer + module Core + module Actions + class Echo < Action + def apply + env.output arguments.first + end + end + end + end +end diff --git a/lib/producer/core/task/dsl.rb b/lib/producer/core/task/dsl.rb index 2987ef7..fdcff71 100644 --- a/lib/producer/core/task/dsl.rb +++ b/lib/producer/core/task/dsl.rb @@ -10,7 +10,8 @@ module Producer end end - define_action :sh, Actions::ShellCommand + define_action :echo, Actions::Echo + define_action :sh, Actions::ShellCommand attr_accessor :actions diff --git a/spec/producer/core/actions/echo_spec.rb b/spec/producer/core/actions/echo_spec.rb new file mode 100644 index 0000000..0639480 --- /dev/null +++ b/spec/producer/core/actions/echo_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +module Producer::Core + describe Actions::Echo do + let(:env) { Env.new } + let(:text) { 'hello' } + subject(:echo) { Actions::Echo.new(env, text) } + + describe '#apply' do + before do + env.output = StringIO.new + end + + it 'outputs the string given as argument through env.output' do + expect(env).to receive(:output).with(text) + echo.apply + end + end + end +end + diff --git a/spec/producer/core/task/dsl_spec.rb b/spec/producer/core/task/dsl_spec.rb index dbf9f65..6d5575e 100644 --- a/spec/producer/core/task/dsl_spec.rb +++ b/spec/producer/core/task/dsl_spec.rb @@ -6,7 +6,7 @@ module Producer::Core let(:env) { double('env') } subject(:dsl) { Task::DSL.new &block } - %w[sh].each do |action| + %w[echo sh].each do |action| it "has `#{action}' action defined" do expect(dsl).to respond_to action.to_sym end