summaryrefslogtreecommitdiff
path: root/features/steps/knife_steps.rb
blob: 169dd5bcd26b8ade275df7eeb939bd68bfc2ead9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
When "I upload the '$cookbook_name' cookbook with knife" do |cookbook_name|
  cookbook_fixture = File.join(FEATURES_DATA, "cookbooks_not_uploaded_at_feature_start", cookbook_name)
  cookbook_dir = ::Tempfile.open("knife-cuke-cookbook-dir").path
  FileUtils.rm(cookbook_dir)
  FileUtils.mkdir_p(cookbook_dir)
  FileUtils.cp_r(cookbook_fixture, cookbook_dir)
  shell_out!("#{KNIFE_CMD} cookbook upload #{cookbook_name} -o #{cookbook_dir} -c #{KNIFE_CONFIG}")
end

When "I upload the '$cookbook_name' cookbook with knife from a repository with bad metadata\.rb" do |cookbook_name|
  cookbook_fixture = File.join(FEATURES_DATA, "cookbooks_repo_with_bad_metadata_rb", cookbook_name)
  cookbook_dir = ::Tempfile.open("knife-bad-cookbook-dir").path
  FileUtils.rm(cookbook_dir)
  FileUtils.mkdir_p(cookbook_dir)
  FileUtils.cp_r(cookbook_fixture, cookbook_dir)
  @knife_command_result = shell_out("#{KNIFE_CMD} cookbook upload #{cookbook_name} -o #{cookbook_dir} -c #{KNIFE_CONFIG}")
end

When "I run knife '$knife_subcommand'" do |knife_subcommand|
  @knife_command_result = shell_out("#{KNIFE_CMD} #{knife_subcommand} -c #{KNIFE_CONFIG}")
end

RSpec::Matchers.define :be_successful do
  match do |shell_out_result|
    shell_out_result.status.success?
  end
  failure_message_for_should do |shell_out_result|
    "Expected command #{shell_out_result.command} to exit successfully, but it exited with status #{shell_out_result.exitstatus}.\n"\
    "STDOUT OUTPUT:\n#{shell_out_result.stdout}\nSTDERR OUTPUT:\n#{shell_out_result.stderr}\n"
  end
  failure_message_for_should_not do |shell_out_result|
    "Expected command #{shell_out_result.command} to fail, but it exited with status #{shell_out_result.exitstatus}.\n"\
    "STDOUT OUTPUT:\n#{shell_out_result.stdout}\nSTDERR OUTPUT:\n#{shell_out_result.stderr}\n"
  end
  description do
    "The shell out command should exit 0"
  end
end

Then /^knife should succeed$/ do
  @knife_command_result.should be_successful
end

Then /^knife should not succeed$/ do
  @knife_command_result.should_not be_successful
end