Refactor Condition spec:
* Use more "classic" testing style for .evaluate; * Use described_class where useful.
This commit is contained in:
parent
88d5ab68b7
commit
dd5866c04e
@ -9,31 +9,15 @@ module Producer::Core
|
|||||||
|
|
||||||
describe '.evaluate' do
|
describe '.evaluate' do
|
||||||
let(:env) { double 'env' }
|
let(:env) { double 'env' }
|
||||||
let(:block) { proc { :some_condition_code } }
|
let(:block) { proc { some_test; :some_return_value } }
|
||||||
|
let(:some_test_class) { Class.new(Test) }
|
||||||
|
subject(:condition) { described_class.evaluate(env, &block) }
|
||||||
|
|
||||||
it 'builds a new DSL sandbox with given env and code' do
|
before { Condition::DSL.define_test(:some_test, some_test_class) }
|
||||||
expect(Condition::DSL)
|
|
||||||
.to receive(:new).with(env, &block).and_call_original
|
|
||||||
Condition.evaluate(env, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'evaluates the DSL sandbox code' do
|
it 'returns an evaluated condition' do
|
||||||
dsl = double('dsl').as_null_object
|
expect(condition.tests.first).to be_a Test
|
||||||
allow(Condition::DSL).to receive(:new) { dsl }
|
expect(condition.return_value).to eq :some_return_value
|
||||||
expect(dsl).to receive :evaluate
|
|
||||||
Condition.evaluate(env, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'builds a condition with its test and block return value' do
|
|
||||||
expect(Condition)
|
|
||||||
.to receive(:new).with([], :some_condition_code)
|
|
||||||
Condition.evaluate(env, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns the condition' do
|
|
||||||
condition = double 'task'
|
|
||||||
allow(Condition).to receive(:new) { condition }
|
|
||||||
expect(Condition.evaluate(env, &block)).to be condition
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -48,7 +32,7 @@ module Producer::Core
|
|||||||
|
|
||||||
context 'when a return value is given as argument' do
|
context 'when a return value is given as argument' do
|
||||||
let(:return_value) { :some_return_value }
|
let(:return_value) { :some_return_value }
|
||||||
subject(:condition) { Condition.new(tests, return_value) }
|
subject(:condition) { described_class.new(tests, return_value) }
|
||||||
|
|
||||||
it 'assigns the return value' do
|
it 'assigns the return value' do
|
||||||
expect(condition.return_value).to eq return_value
|
expect(condition.return_value).to eq return_value
|
||||||
@ -74,7 +58,7 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when there are no test' do
|
context 'when there are no test' do
|
||||||
subject(:condition) { Condition.new([], return_value) }
|
subject(:condition) { described_class.new([], return_value) }
|
||||||
|
|
||||||
context 'and return value is truthy' do
|
context 'and return value is truthy' do
|
||||||
let(:return_value) { :some_truthy_value }
|
let(:return_value) { :some_truthy_value }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user