From 78d3b1e5e9ab57f8ccbcd9587715283724559361 Mon Sep 17 00:00:00 2001 From: Anthony Scalisi Date: Mon, 20 Jul 2015 11:29:13 -0700 Subject: [PATCH] only install StatsD dependencies when git updated --- recipes/install.rb | 4 +++- spec/unit/recipes/default_spec.rb | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/recipes/install.rb b/recipes/install.rb index 1645813..6ef9abc 100644 --- a/recipes/install.rb +++ b/recipes/install.rb @@ -24,9 +24,11 @@ repository node['statsd']['repo'] revision node['statsd']['version'] action :sync + notifies :run, 'execute[install StatsD dependencies]', :immediately end -execute 'install dependencies' do +execute 'install StatsD dependencies' do command 'npm install -d' cwd node['statsd']['path'] + action :nothing end diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index d8cf5da..cdb0c22 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -9,6 +9,9 @@ cached(:upstart) do chef_run.template('/etc/init/statsd.conf') end + cached(:git) do + chef_run.git(node['statsd']['path']) + end %w(nodejs git).each do |recipe| it "includes the #{recipe} recipe" do @@ -24,8 +27,12 @@ ) end - it 'installs statsd dependencies' do - expect(chef_run).to run_execute('npm install -d') \ + it 'notifies to install statsd dependencies' do + expect(git).to notify('execute[install StatsD dependencies]').to(:run).immediately + end + + it 'only installs statsd dependencies if git notified' do + expect(chef_run).to_not run_execute('npm install -d') \ .with(cwd: node['statsd']['path']) end