Declare macro in tasks
This commit is contained in:
parent
8ce8c2f054
commit
3dc414f188
@ -1,6 +1,6 @@
|
|||||||
Feature: `macro' recipe keyword
|
Feature: `macro' recipe keyword
|
||||||
|
|
||||||
Scenario: declares a new keyword accepting task code
|
Scenario: declares a new recipe keyword accepting task code
|
||||||
Given a recipe with:
|
Given a recipe with:
|
||||||
"""
|
"""
|
||||||
macro :hello do
|
macro :hello do
|
||||||
@ -12,6 +12,16 @@ Feature: `macro' recipe keyword
|
|||||||
When I successfully execute the recipe
|
When I successfully execute the recipe
|
||||||
Then the output must contain "hello macro"
|
Then the output must contain "hello macro"
|
||||||
|
|
||||||
|
Scenario: declares a new task keyword
|
||||||
|
Given a recipe with:
|
||||||
|
"""
|
||||||
|
macro(:hello) { echo 'hello macro' }
|
||||||
|
|
||||||
|
task(:some_task) { hello }
|
||||||
|
"""
|
||||||
|
When I successfully execute the recipe
|
||||||
|
Then the output must contain "hello macro"
|
||||||
|
|
||||||
Scenario: supports arguments
|
Scenario: supports arguments
|
||||||
Given a recipe with:
|
Given a recipe with:
|
||||||
"""
|
"""
|
||||||
|
@ -3,7 +3,11 @@ module Producer
|
|||||||
class Recipe
|
class Recipe
|
||||||
class << self
|
class << self
|
||||||
def define_macro(name, block)
|
def define_macro(name, block)
|
||||||
define_method(name) { |*args| task name, *args, &block }
|
[self, Task].each do |klass|
|
||||||
|
klass.class_eval do
|
||||||
|
define_method(name) { |*args| task name, *args, &block }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def compose_macro(name, macro, *base_args)
|
def compose_macro(name, macro, *base_args)
|
||||||
|
@ -49,10 +49,15 @@ module Producer::Core
|
|||||||
|
|
||||||
describe '#macro' do
|
describe '#macro' do
|
||||||
it 'defines the new recipe keyword' do
|
it 'defines the new recipe keyword' do
|
||||||
recipe.macro :hello
|
recipe.macro(:hello) { }
|
||||||
expect(recipe).to respond_to(:hello)
|
expect(recipe).to respond_to(:hello)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'defines the new task keyword' do
|
||||||
|
recipe.macro(:hello) { }
|
||||||
|
expect { recipe.task(:some_task) { hello } }.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
context 'when a defined macro is called' do
|
context 'when a defined macro is called' do
|
||||||
before { recipe.macro(:hello) { :some_macro_code } }
|
before { recipe.macro(:hello) { :some_macro_code } }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user