diff --git a/spec/producer/core/test_spec.rb b/spec/producer/core/test_spec.rb index 7d09295..b995df8 100644 --- a/spec/producer/core/test_spec.rb +++ b/spec/producer/core/test_spec.rb @@ -2,82 +2,6 @@ require 'spec_helper' module Producer::Core describe Test do - let(:env) { Env.new } - let(:arguments) { [:some, :arguments] } - subject(:test) { Test.new(env, *arguments) } - - describe '#initialize' do - it 'assigns the env' do - expect(test.env).to be env - end - - it 'assigns the arguments' do - expect(test.arguments).to eq arguments - end - - it 'assigns negated as false by default' do - expect(test).to_not be_negated - end - - context 'when negated option is true' do - subject(:test) { described_class.new(env, *arguments, negated: true) } - - it 'assigns negated as true' do - expect(test).to be_negated - end - end - end - - describe '#remote' do - it 'returns env remote' do - expect(test.remote).to be test.env.remote - end - end - - describe '#fs' do - it 'returns env remote fs' do - expect(test.fs).to be test.env.remote.fs - end - end - - describe '#negated?' do - it 'returns false' do - expect(test.negated?).to be false - end - - context 'when test is negated' do - subject(:test) { described_class.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) { described_class.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 + it_behaves_like 'test' end end diff --git a/spec/producer/core/tests/file_contains_spec.rb b/spec/producer/core/tests/file_contains_spec.rb index 5d9377c..b19b911 100644 --- a/spec/producer/core/tests/file_contains_spec.rb +++ b/spec/producer/core/tests/file_contains_spec.rb @@ -8,9 +8,7 @@ module Producer::Core let(:content) { 'some_content' } subject(:test) { FileContains.new(env, filepath, content) } - it 'is a kind of test' do - expect(test).to be_a Test - end + it_behaves_like 'test' describe '#verify' do let(:fs) { double 'fs' } diff --git a/spec/producer/core/tests/has_dir_spec.rb b/spec/producer/core/tests/has_dir_spec.rb index 765c17d..8840dce 100644 --- a/spec/producer/core/tests/has_dir_spec.rb +++ b/spec/producer/core/tests/has_dir_spec.rb @@ -7,9 +7,7 @@ module Producer::Core let(:path) { 'some_directory' } subject(:has_dir) { HasDir.new(env, path) } - it 'is a kind of test' do - expect(has_dir).to be_a Test - end + it_behaves_like 'test' describe '#verify', :ssh do before { sftp_story } diff --git a/spec/producer/core/tests/has_env_spec.rb b/spec/producer/core/tests/has_env_spec.rb index 505161a..3085048 100644 --- a/spec/producer/core/tests/has_env_spec.rb +++ b/spec/producer/core/tests/has_env_spec.rb @@ -7,9 +7,7 @@ module Producer::Core let(:variable_name) { :some_variable_name } subject(:has_env) { HasEnv.new(env, variable_name) } - it 'is a kind of test' do - expect(has_env).to be_a Test - end + it_behaves_like 'test' describe '#verify' do let(:environment) { double 'environment' } diff --git a/spec/producer/core/tests/has_file_spec.rb b/spec/producer/core/tests/has_file_spec.rb index 5ec1749..bc8be8e 100644 --- a/spec/producer/core/tests/has_file_spec.rb +++ b/spec/producer/core/tests/has_file_spec.rb @@ -7,9 +7,7 @@ module Producer::Core let(:filepath) { 'some_file' } subject(:has_file) { HasFile.new(env, filepath) } - it 'is a kind of test' do - expect(has_file).to be_a Test - end + it_behaves_like 'test' describe '#verify', :ssh do before { sftp_story } diff --git a/spec/support/shared_test.rb b/spec/support/shared_test.rb new file mode 100644 index 0000000..d46eee6 --- /dev/null +++ b/spec/support/shared_test.rb @@ -0,0 +1,81 @@ +module Producer::Core + shared_examples 'test' do + let(:env) { Env.new } + let(:arguments) { [:some, :arguments] } + subject(:test) { described_class.new(env, *arguments) } + + describe '#initialize' do + it 'assigns the env' do + expect(test.env).to be env + end + + it 'assigns the arguments' do + expect(test.arguments).to eq arguments + end + + it 'assigns negated as false by default' do + expect(test).to_not be_negated + end + + context 'when negated option is true' do + subject(:test) { described_class.new(env, *arguments, negated: true) } + + it 'assigns negated as true' do + expect(test).to be_negated + end + end + end + + describe '#remote' do + it 'returns env remote' do + expect(test.remote).to be test.env.remote + end + end + + describe '#fs' do + it 'returns env remote fs' do + expect(test.fs).to be test.env.remote.fs + end + end + + describe '#negated?' do + it 'returns false' do + expect(test.negated?).to be false + end + + context 'when test is negated' do + subject(:test) { described_class.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) { described_class.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