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.
This commit is contained in:
@@ -49,6 +49,10 @@ module Producer::Core
|
||||
it 'defines a new test keyword' do
|
||||
expect(dsl).to respond_to :some_test
|
||||
end
|
||||
|
||||
it 'defines the negated test' do
|
||||
expect(dsl).to respond_to :no_some_test
|
||||
end
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
@@ -96,6 +100,16 @@ module Producer::Core
|
||||
dsl.evaluate
|
||||
expect(dsl.tests).to include(some_test)
|
||||
end
|
||||
|
||||
context 'when keyword is prefixed with "no_"' do
|
||||
let(:block) { proc { no_some_test :some, :args } }
|
||||
|
||||
it 'builds a negated test' do
|
||||
expect(some_test_class)
|
||||
.to receive(:new).with(env, :some, :args, negated: true)
|
||||
dsl.evaluate
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -14,6 +14,18 @@ module Producer::Core
|
||||
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
|
||||
@@ -27,5 +39,45 @@ module Producer::Core
|
||||
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
|
||||
|
@@ -10,7 +10,7 @@ module Producer::Core
|
||||
expect(has_env).to be_a Test
|
||||
end
|
||||
|
||||
describe '#success?' do
|
||||
describe '#verify' do
|
||||
let(:environment) { double('environment') }
|
||||
|
||||
before do
|
||||
@@ -19,22 +19,22 @@ module Producer::Core
|
||||
|
||||
it 'stringifies the queried variable name' do
|
||||
expect(environment).to receive(:has_key?).with(kind_of(String))
|
||||
has_env.success?
|
||||
has_env.verify
|
||||
end
|
||||
|
||||
it 'upcases the queried variable name' do
|
||||
expect(environment).to receive(:has_key?).with('SOME_VARIABLE_NAME')
|
||||
has_env.success?
|
||||
has_env.verify
|
||||
end
|
||||
|
||||
it 'returns true when remote environment var is defined' do
|
||||
allow(environment).to receive(:has_key?) { true }
|
||||
expect(has_env.success?).to be true
|
||||
expect(has_env.verify).to be true
|
||||
end
|
||||
|
||||
it 'returns false when remote environment var is not defined' do
|
||||
allow(environment).to receive(:has_key?) { false }
|
||||
expect(has_env.success?).to be false
|
||||
expect(has_env.verify).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -10,18 +10,18 @@ module Producer::Core
|
||||
expect(has_file).to be_a Test
|
||||
end
|
||||
|
||||
describe '#success?', :ssh do
|
||||
describe '#verify', :ssh do
|
||||
before { sftp_story }
|
||||
|
||||
it 'delegates the call on remote FS' do
|
||||
expect(env.remote.fs).to receive(:has_file?).with(filepath)
|
||||
has_file.success?
|
||||
has_file.verify
|
||||
end
|
||||
|
||||
it 'returns the file existence' do
|
||||
existence = double('existence')
|
||||
allow(env.remote.fs).to receive(:has_file?) { existence }
|
||||
expect(has_file.success?).to be existence
|
||||
expect(has_file.verify).to be existence
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user