Implement `echo' task action
This commit is contained in:
parent
f0e144cebd
commit
a675c9c910
12
features/actions/echo.feature
Normal file
12
features/actions/echo.feature
Normal file
@ -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"
|
@ -1,4 +1,5 @@
|
|||||||
require 'producer/core/action'
|
require 'producer/core/action'
|
||||||
|
require 'producer/core/actions/echo'
|
||||||
require 'producer/core/actions/shell_command'
|
require 'producer/core/actions/shell_command'
|
||||||
require 'producer/core/cli'
|
require 'producer/core/cli'
|
||||||
require 'producer/core/env'
|
require 'producer/core/env'
|
||||||
|
11
lib/producer/core/actions/echo.rb
Normal file
11
lib/producer/core/actions/echo.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module Producer
|
||||||
|
module Core
|
||||||
|
module Actions
|
||||||
|
class Echo < Action
|
||||||
|
def apply
|
||||||
|
env.output arguments.first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -10,6 +10,7 @@ module Producer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
define_action :echo, Actions::Echo
|
||||||
define_action :sh, Actions::ShellCommand
|
define_action :sh, Actions::ShellCommand
|
||||||
|
|
||||||
attr_accessor :actions
|
attr_accessor :actions
|
||||||
|
21
spec/producer/core/actions/echo_spec.rb
Normal file
21
spec/producer/core/actions/echo_spec.rb
Normal file
@ -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
|
||||||
|
|
@ -6,7 +6,7 @@ module Producer::Core
|
|||||||
let(:env) { double('env') }
|
let(:env) { double('env') }
|
||||||
subject(:dsl) { Task::DSL.new &block }
|
subject(:dsl) { Task::DSL.new &block }
|
||||||
|
|
||||||
%w[sh].each do |action|
|
%w[echo sh].each do |action|
|
||||||
it "has `#{action}' action defined" do
|
it "has `#{action}' action defined" do
|
||||||
expect(dsl).to respond_to action.to_sym
|
expect(dsl).to respond_to action.to_sym
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user