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


Chronological Thread 
  • From: Rudi < >
  • To:
  • Subject: [chef] Re: Re: How to test a bash code snippet
  • Date: Tue, 9 Jul 2013 05:44:46 +0800

Thanks Daniel - that's makes good sense and I"ll update code for that.

I'm still not sure the best way to test the actual bash code being run by chef_run though?


On Mon, Jul 8, 2013 at 11:56 PM, Daniel Condomitti < " target="_blank"> > wrote:
This isn't directly related to your testing but you can just run `bundle check` and it will tell you if any gems need to be installed or upgraded. If you're only testing for xpath 0.1.4's existence then if another gem gets upgraded you won't be able to boot your application.

On Monday, July 8, 2013 at 10:56 AM, Rudi wrote:

Hi,

I'm using chefspec with chef 11 and have this working piece of code but
don't know how to test it.

I hope this is the correct place to ask for any suggestions on this?

I also have a crude file exists check so that bundle doesn't run every chef_run.

bash "install with bundler" do
  user "vagrant"
  cwd "/vagrant"
  flags "--login"
  code <<-EOH
  rvm use ruby-1.9.2-p290
  bundle --verbose
  EOH
  # xpath is the last in the list of 125 required gems for this application (gem list --local)
  # If this gem is here we assume bundle has already run successfully.
  not_if { ::File.exists?('/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/xpath-0.1.4') }
end


Prior to this code I was testing the execute command with this:

describe 'main::install_bundle' do
  let (:chef_run) { ChefSpec::ChefRunner.new.converge 'main::install_bundle' }

  it "installs with bundler" do
    expect(chef_run).to execute_command("cd /vagrant && rvm use ruby-1.9.2-p290 && bundle --verbose")
  end
end

But I need the "--login" flag so that rvm can select ruby 1.9.2 so I changed to the bash resource.

FYI ..chef is running with ruby 1.9.3 but the Rails app uses 1.9.2 on the /vagrant box (it's some old coder I need to maintain).

Thanks!






Archive powered by MHonArc 2.6.16.

§