spec/cliver_spec.rb in cliver-0.1.5 vs spec/cliver_spec.rb in cliver-0.2.0
- old
+ new
@@ -1,31 +1,203 @@
# encoding: utf-8
require 'cliver'
+require 'spec_helper'
describe Cliver do
- it { should respond_to :assert }
+ # The setup. Your test will likeley interact with subject.
+ let(:action) { Cliver.public_send(method, *args, &block) }
+ subject { action }
- it { should respond_to :dependency_unmet? }
- context '#dependency_unmet?' do
- let(:requirements) { [] }
- let(:detector) { proc { } }
- subject { Cliver.dependency_unmet?(executable, *requirements, &detector) }
- context 'when dependency is met' do
- let(:executable) { 'ruby' }
+ # These can get overridden in context blocks
+ let(:method) { raise ArgumentError, 'spec didn\'t specify :method' }
+ let(:args) { raise ArgumentError, 'spec didn\'t specify :args' }
+ let(:block) { version_map.method(:fetch) }
+
+ before(:each) do
+ File.stub(:executable?) { |path| executables.include? path }
+ # Cliver::Dependency.any_instance.stub(:detect_version) do |arg|
+ # version_map[arg]
+ # end
+ end
+
+ let(:options) do
+ {
+ :path => path,
+ :executable => executable,
+ }
+ end
+ let(:executables) { version_map.keys }
+ let(:args) do
+ args = [Array(executable)]
+ args.concat Array(requirement)
+ args << options
+ end
+
+ let(:path) { 'foo/bar:baz/bingo' }
+ let(:executable) { 'doodle' }
+ let(:requirement) { '~>1.1'}
+
+ context 'when first-found version is sufficient' do
+
+ let(:version_map) do
+ {'baz/bingo/doodle' => '1.2.1'}
+ end
+
+ context '::assert' do
+ let(:method) { :assert }
+ it 'should not raise' do
+ expect { action }.to_not raise_exception
+ end
+ end
+
+ context '::dependency_unmet?' do
+ let(:method) { :dependency_unmet? }
it { should be_false }
end
- context 'when dependency is present, but wrong version' do
- let(:executable) { 'ruby' }
- let(:requirements) { ['~> 0.1.0'] }
- let(:detector) { proc { RUBY_VERSION.sub('p', '.') } }
- it { should_not be_false }
- it { should match 'Dependency Version Mismatch:' }
- it { should match "expected .+ 'ruby' to be #{requirements}" }
+ context '::detect' do
+ let(:method) { :detect }
+ it { should eq 'baz/bingo/doodle' }
end
- context 'when dependency is not present' do
- let(:executable) { 'ruxxxby' }
- it { should_not be_false }
- it { should match 'Dependency Not Found:' }
- it { should match "'#{executable}' could not be found" }
+ context '::detect!' do
+ let(:method) { :detect! }
+ it 'should not raise' do
+ expect { action }.to_not raise_exception
+ end
+ it { should eq 'baz/bingo/doodle' }
+ end
+ end
+
+ context 'when first-found version insufficient' do
+ let(:version_map) do
+ {'baz/bingo/doodle' => '1.0.1'}
+ end
+ context '::assert' do
+ let(:method) { :assert }
+ it 'should raise' do
+ expect { action }.to raise_exception Cliver::Dependency::VersionMismatch
+ end
+ end
+ context '::dependency_unmet?' do
+ let(:method) { :dependency_unmet? }
+ it { should be_true }
+ end
+ context '::detect' do
+ let(:method) { :detect }
+ it { should be_nil }
+ end
+ context '::detect!' do
+ let(:method) { :detect! }
+ it 'should not raise' do
+ expect { action }.to raise_exception Cliver::Dependency::VersionMismatch
+ end
+ end
+
+ context 'and when sufficient version found later on path' do
+ let(:version_map) do
+ {
+ 'foo/bar/doodle' => '0.0.1',
+ 'baz/bingo/doodle' => '1.1.0',
+ }
+ end
+ context '::assert' do
+ let(:method) { :assert }
+ it 'should raise' do
+ expect { action }.to raise_exception Cliver::Dependency::VersionMismatch
+ end
+ end
+ context '::dependency_unmet?' do
+ let(:method) { :dependency_unmet? }
+ it { should be_true }
+ end
+ context '::detect' do
+ let(:method) { :detect }
+ it { should eq 'baz/bingo/doodle'}
+ end
+ context '::detect!' do
+ let(:method) { :detect! }
+ it 'should not raise' do
+ expect { action }.to_not raise_exception
+ end
+ it { should eq 'baz/bingo/doodle' }
+ end
+ end
+ end
+
+ context 'when no found version' do
+ let(:version_map) { {} }
+
+ context '::assert' do
+ let(:method) { :assert }
+ it 'should raise' do
+ expect { action }.to raise_exception Cliver::Dependency::NotFound
+ end
+ end
+ context '::dependency_unmet?' do
+ let(:method) { :dependency_unmet? }
+ it { should be_true }
+ end
+ context '::detect' do
+ let(:method) { :detect }
+ it { should be_nil }
+ end
+ context '::detect!' do
+ let(:method) { :detect! }
+ it 'should not raise' do
+ expect { action }.to raise_exception Cliver::Dependency::NotFound
+ end
+ end
+ end
+
+ context 'with fallback executable names' do
+ let(:executable) { ['primary', 'fallback'] }
+ let(:requirement) { '~> 1.1' }
+ context 'when primary exists after secondary in path' do
+ context 'and primary sufficient' do
+ let(:version_map) do
+ {
+ 'baz/bingo/primary' => '1.1',
+ 'foo/bar/fallback' => '1.1'
+ }
+ end
+ context '::detect' do
+ let(:method) { :detect }
+ it { should eq 'baz/bingo/primary' }
+ end
+ end
+ context 'and primary insufficient' do
+ let(:version_map) do
+ {
+ 'baz/bingo/primary' => '2.1',
+ 'foo/bar/fallback' => '1.1'
+ }
+ end
+ context 'the secondary' do
+ context '::detect' do
+ let(:method) { :detect }
+ it { should eq 'foo/bar/fallback' }
+ end
+ end
+ end
+ end
+ context 'when primary does not exist in path' do
+ context 'and sufficient secondary does' do
+ let(:version_map) do
+ {
+ 'foo/bar/fallback' => '1.1'
+ }
+ end
+ context '::detect' do
+ let(:method) { :detect }
+ it { should eq 'foo/bar/fallback' }
+ end
+ end
+ end
+
+ context 'neither found' do
+ context '::detect' do
+ let(:version_map) { {} }
+ let(:method) { :detect }
+ it { should be_nil }
+ end
end
end
end