diff --git a/features/task_target.feature b/features/task_target.feature new file mode 100644 index 0000000..19269e9 --- /dev/null +++ b/features/task_target.feature @@ -0,0 +1,11 @@ +Feature: `target' task keyword + + Scenario: returns the current target + Given a recipe with: + """ + target 'some_host.example' + + task(:echo_target) { echo target } + """ + When I execute the recipe + Then the output must contain "some_host.example" diff --git a/lib/producer/core/task.rb b/lib/producer/core/task.rb index 3ea952d..00a5451 100644 --- a/lib/producer/core/task.rb +++ b/lib/producer/core/task.rb @@ -13,6 +13,9 @@ module Producer end end + extend Forwardable + def_delegators :@env, :target + define_action :echo, Actions::Echo define_action :sh, Actions::ShellCommand diff --git a/spec/producer/core/task_spec.rb b/spec/producer/core/task_spec.rb index 5b2e877..1acaced 100644 --- a/spec/producer/core/task_spec.rb +++ b/spec/producer/core/task_spec.rb @@ -159,5 +159,13 @@ module Producer::Core expect(task.get :some_key).to eq :some_value end end + + describe '#target' do + before { env.target = :some_target } + + it 'returns current env target' do + expect(task.target).to eq :some_target + end + end end end