spec/cany/specification_spec.rb in cany-0.0.2 vs spec/cany/specification_spec.rb in cany-0.1.0
- old
+ new
@@ -1,8 +1,9 @@
require 'spec_helper'
describe Cany::Specification do
+ let(:spec) { described_class.new {} }
describe '#new' do
it 'should have a name' do
spec = Cany::Specification.new do
name 'example'
end
@@ -53,11 +54,12 @@
it 'should be able to include recipes' do
spec = Cany::Specification.new do
use :bundler
end
- expect(spec.recipes).to eq [:bundler]
+ expect(spec.recipes.size).to eq 1
+ expect(spec.recipes[0]).to be_instance_of(Cany::Recipes::Bundler)
end
it 'should accept a block for own build steps' do
spec = Cany::Specification.new do
build do
@@ -72,8 +74,118 @@
binary do
install 'hans', 'otto'
end
end
expect(spec.binary).to be_a_kind_of Proc
+ end
+ end
+
+ context 'with a required cany version' do
+ let(:spec) { Cany::Specification.new { name 'test-spec' } }
+ subject { spec }
+
+ it 'pass if it matches cany\'s version' do
+ expect(Cany::VERSION).to receive(:to_s).at_least(:once).and_return '0.1.1'
+ spec.setup { require_cany '~> 0.1' }
+ end
+
+ it 'fail if cany\'s version is to old' do
+ expect(Cany::VERSION).to receive(:to_s).at_least(:once).and_return '0.0.1'
+ expect { spec.setup { require_cany '~> 0.1' } }.to raise_exception Cany::UnsupportedVersion, /.*require.*"~> 0\.1" but .* "0.0.1"/
+ end
+
+ it 'fail if cany\'s version is to new' do
+ expect(Cany::VERSION).to receive(:to_s).at_least(:once).and_return '1.0'
+ expect { spec.setup { require_cany '~> 0.1' } }.to raise_exception Cany::UnsupportedVersion, /.*require.*"~> 0\.1" but .* "1.0"/
+ end
+ end
+
+ context '#build_dependencies' do
+ subject { spec.build_dependencies }
+ let(:build_dep1) { Cany::Dependency.new situations: :build }
+ let(:runtime_dep1) { Cany::Dependency.new situations: :runtime }
+ let(:both_dep1) { Cany::Dependency.new situations: [:build, :runtime] }
+
+ it { should eq [] }
+
+ context 'with added build dependencies' do
+ before { spec.dependencies << build_dep1 }
+
+ it 'should include these deps' do
+ should match_array [build_dep1]
+ end
+ end
+
+ context 'with added runtime dependencies' do
+ before { spec.dependencies << runtime_dep1 }
+ it 'should not include' do
+ should match_array []
+ end
+ end
+
+ context 'with added build + runtime dependencies' do
+ before { spec.dependencies << both_dep1 }
+
+ it 'should include this dep' do
+ should match_array [both_dep1]
+ end
+ end
+ end
+
+ context '#runtime_dependencies' do
+ subject { spec.runtime_dependencies }
+ let(:build_dep1) { Cany::Dependency.new situations: :build }
+ let(:runtime_dep1) { Cany::Dependency.new situations: :runtime }
+ let(:both_dep1) { Cany::Dependency.new situations: [:build, :runtime] }
+
+ it { should eq [] }
+
+ context 'with added build dependencies' do
+ before { spec.dependencies << build_dep1 }
+
+ it 'should not include' do
+ should match_array []
+ end
+ end
+
+ context 'with added runtime dependencies' do
+ before { spec.dependencies << runtime_dep1 }
+ it 'should include these deps' do
+ should match_array [runtime_dep1]
+ end
+ end
+
+ context 'with added build + runtime dependencies' do
+ before { spec.dependencies << both_dep1 }
+
+ it 'should include this dep' do
+ should match_array [both_dep1]
+ end
+ end
+ end
+
+ describe '#setup_recipes' do
+ subject { spec.setup_recipes }
+
+ context 'with loaded recipes' do
+ before do
+ spec.setup do
+ use :bundler
+ use :rails
+ end
+ spec.system_recipe = Cany::Dpkg::DebHelperRecipe.new spec
+ end
+ it 'should instance any used recipes' do
+ expect_any_instance_of(Cany::Recipes::Rails).to receive(:inner=).with(kind_of(Cany::Dpkg::DebHelperRecipe)).and_call_original
+ expect_any_instance_of(Cany::Recipes::Bundler).to receive(:inner=).with(kind_of(Cany::Recipes::Rails))
+ subject
+ end
+
+ it 'should call prepare on all recipes' do
+ expect_any_instance_of(Cany::Dpkg::DebHelperRecipe).to receive(:prepare).and_call_original
+ expect_any_instance_of(Cany::Recipes::Bundler).to receive(:prepare).and_call_original
+ expect_any_instance_of(Cany::Recipes::Rails).to receive(:prepare).and_call_original
+ subject
+ end
end
end
end