Thibault Jouan 35621e1f5f Implement condition DSL negated test prefix (no_*)
* Allow no_* to be used for every tests in condition DSL:
  condition { no_has_env :shell, '/bin/sh' };
* Modify Test constructor to accept negated: named argument, implement
  #negated? and #pass?;
* Rename #success? to #verify in all test classes.
2013-12-19 20:22:44 +00:00

84 lines
2.1 KiB
Ruby

require 'spec_helper'
module Producer::Core
describe Test do
let(:env) { double 'env' }
let(:arguments) { [:some, :arguments] }
subject(:test) { Test.new(env, *arguments) }
describe '#initialize' do
it 'assigns the env' do
expect(test.instance_eval { @env }).to be env
end
it 'assigns the arguments' do
expect(test.instance_eval { @arguments }).to eq arguments
end
it 'assigns negated as false by default' do
expect(test.instance_eval { @negated }).to be false
end
context 'when negated option is true' do
subject(:test) { Test.new(env, *arguments, negated: true) }
it 'assigns negated as true' do
expect(test.instance_eval { @negated }).to be true
end
end
end
describe '#env' do
it 'returns the assigned env' do
expect(test.env).to be env
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) }
it 'returns true' do
expect(test.negated?).to be true
end
end
end
describe '#pass?' do
it 'returns true when #verify is true' do
allow(test).to receive(:verify) { true }
expect(test.pass?).to be true
end
it 'returns false when #verify is false' do
allow(test).to receive(:verify) { false }
expect(test.pass?).to be false
end
context 'when test is negated' do
subject(:test) { Test.new(env, *arguments, negated: true) }
it 'returns false when #verify is true' do
allow(test).to receive(:verify) { true }
expect(test.pass?).to be false
end
it 'returns true when #verify is false' do
allow(test).to receive(:verify) { false }
expect(test.pass?).to be true
end
end
end
end
end