Improve Test spec:

* Use attributes readers instead of instance_eval;
* Refactor.
This commit is contained in:
Thibault Jouan 2014-01-20 02:00:24 +00:00
parent 780bb9041d
commit 82f8eac319

View File

@ -8,32 +8,26 @@ module Producer::Core
describe '#initialize' do
it 'assigns the env' do
expect(test.instance_eval { @env }).to be env
expect(test.env).to be env
end
it 'assigns the arguments' do
expect(test.instance_eval { @arguments }).to eq arguments
expect(test.arguments).to eq arguments
end
it 'assigns negated as false by default' do
expect(test.instance_eval { @negated }).to be false
expect(test).to_not be_negated
end
context 'when negated option is true' do
subject(:test) { Test.new(env, *arguments, negated: true) }
subject(:test) { described_class.new(env, *arguments, negated: true) }
it 'assigns negated as true' do
expect(test.instance_eval { @negated }).to be true
expect(test).to be_negated
end
end
end
describe '#env' do
it 'returns the assigned env' do
expect(test.env).to be env
end
end
describe '#remote' do
it 'returns env remote' do
expect(test.remote).to be test.env.remote
@ -46,19 +40,13 @@ module Producer::Core
end
end
describe '#arguments' do
it 'returns the assigned arguments' do
expect(test.arguments).to eq arguments
end
end
describe '#negated?' do
it 'returns false' do
expect(test.negated?).to be false
end
context 'when test is negated' do
subject(:test) { Test.new(env, *arguments, negated: true) }
subject(:test) { described_class.new(env, *arguments, negated: true) }
it 'returns true' do
expect(test.negated?).to be true
@ -78,7 +66,7 @@ module Producer::Core
end
context 'when test is negated' do
subject(:test) { Test.new(env, *arguments, negated: true) }
subject(:test) { described_class.new(env, *arguments, negated: true) }
it 'returns false when #verify is true' do
allow(test).to receive(:verify) { true }