From 00b703ac654776e5a554178bba10abd26b0743cb Mon Sep 17 00:00:00 2001 From: Jason Martin Date: Mon, 14 Jul 2014 02:56:17 +0000 Subject: [PATCH 1/2] ChefSpec does not support node attributes in assertions per http://stackoverflow.com/a/21763443 Add stub for golang cookbooks shell out to grep --- spec/unit/recipes/install_source_spec.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/unit/recipes/install_source_spec.rb b/spec/unit/recipes/install_source_spec.rb index a089330d..bf83eba3 100644 --- a/spec/unit/recipes/install_source_spec.rb +++ b/spec/unit/recipes/install_source_spec.rb @@ -1,8 +1,12 @@ require 'spec_helper' -describe_recipe 'consul::install_binary' do +describe_recipe 'consul::install_source' do + before do + stub_command("/usr/local/go/bin/go version | grep \"go1.2 \"").and_return(false) + end + it { expect(chef_run).to include_recipe('golang::default') } - it { expect(chef_run).to create_directory("#{node[:golang][:gohome]}/src/github.com/hashicorp") } + it { expect(chef_run).to create_directory('/opt/go/src/github.com/hashicorp') } it { expect(chef_run).to checkout_git('https://github.com/hashicorp/consul.git') } it { expect(chef_run.link('/usr/bin/local/consul')).to link_to('/opt/go/bin') } it { expect(chef_run).to include_recipe('consul::_service') } From 61855cdb3f416edca2be14cd1d3f8749a1825a20 Mon Sep 17 00:00:00 2001 From: Jason Martin Date: Mon, 14 Jul 2014 03:10:53 +0000 Subject: [PATCH 2/2] Fix unit tests --- spec/unit/attributes/default_spec.rb | 2 +- spec/unit/recipes/install_source_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/unit/attributes/default_spec.rb b/spec/unit/attributes/default_spec.rb index eeb5dfd6..e3a147e6 100644 --- a/spec/unit/attributes/default_spec.rb +++ b/spec/unit/attributes/default_spec.rb @@ -4,6 +4,6 @@ let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge(described_recipe) } context 'sets default attributes' do - it { expect(default_cookbook_attribute('base_url').to eq('https://dl.bintray.com/mitchellh/consul/'))} + it { expect(chef_run.node.consul.base_url).to eq('https://dl.bintray.com/mitchellh/consul/') } end end diff --git a/spec/unit/recipes/install_source_spec.rb b/spec/unit/recipes/install_source_spec.rb index bf83eba3..e4f815e5 100644 --- a/spec/unit/recipes/install_source_spec.rb +++ b/spec/unit/recipes/install_source_spec.rb @@ -7,7 +7,7 @@ it { expect(chef_run).to include_recipe('golang::default') } it { expect(chef_run).to create_directory('/opt/go/src/github.com/hashicorp') } - it { expect(chef_run).to checkout_git('https://github.com/hashicorp/consul.git') } - it { expect(chef_run.link('/usr/bin/local/consul')).to link_to('/opt/go/bin') } + it { expect(chef_run).to checkout_git('/opt/go/src/github.com/hashicorp/consul') } + it { expect(chef_run.link('/usr/local/bin/consul')).to link_to('/opt/go/bin/consul') } it { expect(chef_run).to include_recipe('consul::_service') } end