From dd5866c04e921bb3ca255e127fee9025894d633f Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 19 Jan 2014 17:50:39 +0000 Subject: [PATCH] Refactor Condition spec: * Use more "classic" testing style for .evaluate; * Use described_class where useful. --- spec/producer/core/condition_spec.rb | 36 ++++++++-------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/spec/producer/core/condition_spec.rb b/spec/producer/core/condition_spec.rb index 94c6f7c..dc9713e 100644 --- a/spec/producer/core/condition_spec.rb +++ b/spec/producer/core/condition_spec.rb @@ -8,32 +8,16 @@ module Producer::Core subject(:condition) { Condition.new(tests) } describe '.evaluate' do - let(:env) { double 'env' } - let(:block) { proc { :some_condition_code } } + let(:env) { double 'env' } + 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 - expect(Condition::DSL) - .to receive(:new).with(env, &block).and_call_original - Condition.evaluate(env, &block) - end + before { Condition::DSL.define_test(:some_test, some_test_class) } - it 'evaluates the DSL sandbox code' do - dsl = double('dsl').as_null_object - allow(Condition::DSL).to receive(:new) { dsl } - 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 + it 'returns an evaluated condition' do + expect(condition.tests.first).to be_a Test + expect(condition.return_value).to eq :some_return_value end end @@ -48,7 +32,7 @@ module Producer::Core context 'when a return value is given as argument' do 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 expect(condition.return_value).to eq return_value @@ -74,7 +58,7 @@ module Producer::Core end 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 let(:return_value) { :some_truthy_value }