diff --git a/features/condition_target.feature b/features/condition_target.feature new file mode 100644 index 0000000..b8eb8cb --- /dev/null +++ b/features/condition_target.feature @@ -0,0 +1,15 @@ +Feature: `target' condition keyword + + Scenario: returns the current target + Given a recipe with: + """ + target 'some_host.example' + + task :test_target do + condition { target == 'some_host.example' } + + echo 'OK' + end + """ + When I execute the recipe + Then the output must contain "OK" diff --git a/lib/producer/core/condition.rb b/lib/producer/core/condition.rb index 5d9fb66..633e05d 100644 --- a/lib/producer/core/condition.rb +++ b/lib/producer/core/condition.rb @@ -30,7 +30,7 @@ module Producer end extend Forwardable - def_delegators :@env, :get + def_delegators :@env, :get, :target define_test :`, Tests::ShellCommandStatus define_test :sh, Tests::ShellCommandStatus diff --git a/spec/producer/core/condition_spec.rb b/spec/producer/core/condition_spec.rb index 95498f3..02dc75d 100644 --- a/spec/producer/core/condition_spec.rb +++ b/spec/producer/core/condition_spec.rb @@ -182,5 +182,16 @@ module Producer::Core described_class.evaluate(env, []) { get :some_key } end end + + describe '#target' do + let(:env) { Env.new } + + before { env.target = :some_target } + + it 'returns current env target' do + condition = described_class.evaluate(env, []) { target == :some_target } + expect(condition).to be_met + end + end end end