Implement `test_macro' recipe keyword
This commit is contained in:
@@ -22,9 +22,9 @@ module Producer::Core
|
||||
end
|
||||
|
||||
describe '.define_test' do
|
||||
let(:some_test_class) { Test }
|
||||
let(:some_test) { Test }
|
||||
|
||||
before { described_class.define_test(:some_test, some_test_class) }
|
||||
before { described_class.define_test(:some_test, some_test) }
|
||||
|
||||
it 'defines a new test keyword' do
|
||||
expect(dsl).to respond_to :some_test
|
||||
@@ -41,19 +41,38 @@ module Producer::Core
|
||||
|
||||
it 'registers the test with current env' do
|
||||
dsl.some_test
|
||||
expect(dsl.tests.first.env).to be env
|
||||
expect(dsl.tests.last.env).to be env
|
||||
end
|
||||
|
||||
it 'registers the test with given arguments' do
|
||||
dsl.some_test :some, :args
|
||||
expect(dsl.tests.first.arguments).to eq [:some, :args]
|
||||
expect(dsl.tests.last.arguments).to eq [:some, :args]
|
||||
end
|
||||
|
||||
context 'when given test is callable' do
|
||||
let(:some_test) { proc {} }
|
||||
|
||||
before { dsl.some_test }
|
||||
|
||||
it 'registers a condition test' do
|
||||
expect(dsl.tests.last).to be_a Tests::ConditionTest
|
||||
end
|
||||
|
||||
it 'registers the test with given block' do
|
||||
expect(dsl.tests.last.condition_block).to be some_test
|
||||
end
|
||||
|
||||
it 'registers the test with given arguments' do
|
||||
dsl.some_test :some, :args
|
||||
expect(dsl.tests.last.condition_args).to eq [:some, :args]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a negated test keyword is called' do
|
||||
it 'registers a negated test' do
|
||||
dsl.no_some_test
|
||||
expect(dsl.tests.first).to be_negated
|
||||
expect(dsl.tests.last).to be_negated
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -81,6 +100,15 @@ module Producer::Core
|
||||
it 'returns the value returned by the assigned block' do
|
||||
expect(dsl.evaluate).to eq block.call
|
||||
end
|
||||
|
||||
context 'when arguments are given' do
|
||||
let(:block) { proc { |e| throw e } }
|
||||
|
||||
it 'passes arguments as block parameters' do
|
||||
expect { dsl.evaluate :some_argument }
|
||||
.to throw_symbol :some_argument
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -102,6 +102,16 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
describe '#test_macro' do
|
||||
it 'defines the new test' do
|
||||
condition_dsl = double 'condition dsl'
|
||||
test_block = proc {}
|
||||
expect(condition_dsl)
|
||||
.to receive(:define_test).with(:some_test, test_block)
|
||||
dsl.test_macro(:some_test, dsl: condition_dsl, &test_block)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#set' do
|
||||
it 'registers a key/value pair in env registry' do
|
||||
dsl.set :some_key, :some_value
|
||||
|
55
spec/producer/core/tests/condition_test_spec.rb
Normal file
55
spec/producer/core/tests/condition_test_spec.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
module Tests
|
||||
describe ConditionTest do
|
||||
let(:env) { double 'env' }
|
||||
let(:block) { proc { true } }
|
||||
let(:arguments) { [:some, :args] }
|
||||
subject(:test) { described_class.new(env, block, *arguments) }
|
||||
|
||||
it_behaves_like 'test'
|
||||
|
||||
describe '#verify' do
|
||||
context 'when condition is met' do
|
||||
it 'returns true' do
|
||||
expect(test.verify).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when condition is not met' do
|
||||
let(:block) { proc { false } }
|
||||
|
||||
it 'returns false' do
|
||||
expect(test.verify).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#condition' do
|
||||
it 'evaluates a conditon' do
|
||||
expect(Condition).to receive(:evaluate).with(env, *arguments, &block)
|
||||
test.condition
|
||||
end
|
||||
|
||||
it 'returns the evaluated condition' do
|
||||
condition = double 'condition'
|
||||
allow(Condition).to receive(:evaluate) { condition }
|
||||
expect(test.condition).to eq condition
|
||||
end
|
||||
end
|
||||
|
||||
describe '#condition_args' do
|
||||
it 'returns arguments for condition' do
|
||||
expect(test.condition_args).to eq arguments
|
||||
end
|
||||
end
|
||||
|
||||
describe '#condition_block' do
|
||||
it 'returns condition block' do
|
||||
expect(test.condition_block).to eq block
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user