Skip to content

Instantly share code, notes, and snippets.

@retr0h
Created November 2, 2012 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retr0h/4004735 to your computer and use it in GitHub Desktop.
Save retr0h/4004735 to your computer and use it in GitHub Desktop.
execute "create swapfile" do
command <<-eof
dd if=/dev/zero of=#{swap_location} bs=1M count=#{swap_size_megs} &&
chmod 600 #{swap_location} &&
mkswap #{swap_location}
eof
not_if { File.exists?("#{swap_location}") }
end
describe "create space" do
it "turns the file into swap" do
@chef_run.should execute_command "mkswap /var/swapfile"
end
end
###
Failures:
1) swap::default create space turns the file into swap
Failure/Error: @chef_run.should execute_command "mkswap /var/swapfile"
expected chef_run: recipe[swap::default] to execute command "mkswap /var/swapfile"
# ./cookbooks/swap/spec/swap_spec.rb:18:in `block (3 levels) in <top (required)>'
Finished in 0.00396 seconds
1 example, 1 failure
@acrmp
Copy link

acrmp commented Nov 3, 2012

You could do something like:

it "turns the file into swap" do
  swap_commands = @chef_run.resources.find do |r|
    r.resource_name == :execute and r.name == 'create swapfile'
  end.command.lines.map{|c| c.strip}
  swap_commands.should include 'mkswap /var/swapfile'
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment