[chef] Re: How to test a bash code snippet


Chronological Thread 
  • From: Mike < >
  • To: " " < >
  • Subject: [chef] Re: How to test a bash code snippet
  • Date: Tue, 9 Jul 2013 07:20:28 -0400

You might be looking for:

expct(chef_run).to execute_bash_script(command)

Ref https://github.com/acrmp/chefspec/blob/master/lib/chefspec/matchers/script.rb#L5

-M

On Monday, July 8, 2013, Rudi wrote:
I'd encourage you to submit a patch to chefspec to support script/bash resources if you're able.

I like the idea too but I'm not really able to (just not smart enough to be honest)

What I was initially looking for was something like 

expect(chef_run).to execute_bash(command)

But I don't think that exists right?




On Tue, Jul 9, 2013 at 7:51 AM, Daniel DeLeo < ');" target="_blank"> > wrote:

On Monday, July 8, 2013 at 3:47 PM, Rudi wrote:

Very nice! Thanks man.


On Tue, Jul 9, 2013 at 6:46 AM, John Dewey < ');" target="_blank"> > wrote:
Right, thats why you want to source the rvm script, before calling rvm.

code <<-EOH.gsub(/^\s+/, '')
  source ~/.rvm/scripts/rvm
  rvm use ruby-1.9.2-p290
  bundle --verbose
EOH

command = <<-EOH.gsub(/^\s+/, '')
  source ~/.rvm/scripts/rvm
  rvm use ruby-1.9.2-p290
  bundle --verbose
EOH

expect(chef_run).to execute_command(command)

On Monday, July 8, 2013 at 3:39 PM, Rudi wrote:

Hey John,

 can probably switch back to execute

The reason I left was I needed to pass in the "--login" flag. Without this it erred not being able to see rvm (non apt package).

The fact that an execute resource runs bin/sh as an intermediate step is an implementation detail (admittedly, one we're unlikely to change), so adding the `--login` flag to the bash resource is better chef code, in my opinion.

I'd encourage you to submit a patch to chefspec to support script/bash resources if you're able.


-- 
Daniel DeLeo





Archive powered by MHonArc 2.6.16.

§