berkshelf 2.0.18 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/.ruby-version +1 -1
  2. data/.travis.yml +4 -1
  3. data/CHANGELOG.md +2 -26
  4. data/Gemfile +12 -2
  5. data/README.md +9 -1
  6. data/berkshelf.gemspec +9 -18
  7. data/bin/berks +3 -13
  8. data/features/apply_command.feature +11 -9
  9. data/features/berksfile.feature +8 -10
  10. data/features/config.feature +1 -2
  11. data/features/configure_command.feature +13 -14
  12. data/features/contingent_command.feature +13 -1
  13. data/features/cookbook_command.feature +2 -4
  14. data/features/groups_install.feature +10 -2
  15. data/features/help.feature +1 -1
  16. data/features/init_command.feature +5 -7
  17. data/features/install_command.feature +157 -228
  18. data/features/json_formatter.feature +27 -15
  19. data/features/licenses.feature +18 -12
  20. data/features/list_command.feature +6 -1
  21. data/features/lockfile.feature +116 -72
  22. data/features/outdated_command.feature +3 -47
  23. data/features/package_command.feature +10 -7
  24. data/features/shelf/show.feature +2 -2
  25. data/features/shelf/uninstall.feature +2 -2
  26. data/features/show_command.feature +10 -3
  27. data/features/step_definitions/chef/config_steps.rb +12 -0
  28. data/features/step_definitions/chef_server_steps.rb +16 -16
  29. data/features/step_definitions/cli_steps.rb +3 -79
  30. data/features/step_definitions/config_steps.rb +43 -0
  31. data/features/step_definitions/environment_steps.rb +7 -0
  32. data/features/step_definitions/filesystem_steps.rb +12 -57
  33. data/features/step_definitions/gem_steps.rb +1 -2
  34. data/features/step_definitions/json_steps.rb +3 -1
  35. data/features/step_definitions/lockfile_steps.rb +4 -0
  36. data/features/step_definitions/utility_steps.rb +0 -19
  37. data/features/support/aruba.rb +12 -0
  38. data/features/support/env.rb +52 -57
  39. data/features/update_command.feature +37 -23
  40. data/features/upload_command.feature +96 -160
  41. data/generator_files/Berksfile.erb +2 -1
  42. data/generator_files/Vagrantfile.erb +3 -0
  43. data/generator_files/default_test.rb.erb +1 -1
  44. data/generator_files/helpers.rb.erb +1 -1
  45. data/lib/berkshelf.rb +43 -24
  46. data/lib/berkshelf/api_client.rb +67 -0
  47. data/lib/berkshelf/api_client/remote_cookbook.rb +42 -0
  48. data/lib/berkshelf/berksfile.rb +232 -420
  49. data/lib/berkshelf/cached_cookbook.rb +22 -10
  50. data/lib/berkshelf/chef/config.rb +1 -0
  51. data/lib/berkshelf/cli.rb +66 -68
  52. data/lib/berkshelf/commands/shelf.rb +1 -1
  53. data/lib/berkshelf/community_rest.rb +10 -17
  54. data/lib/berkshelf/config.rb +23 -27
  55. data/lib/berkshelf/cookbook_generator.rb +3 -4
  56. data/lib/berkshelf/cookbook_store.rb +74 -17
  57. data/lib/berkshelf/core_ext/file.rb +2 -2
  58. data/lib/berkshelf/core_ext/pathname.rb +7 -5
  59. data/lib/berkshelf/{cookbook_source.rb → dependency.rb} +47 -67
  60. data/lib/berkshelf/downloader.rb +49 -106
  61. data/lib/berkshelf/errors.rb +64 -71
  62. data/lib/berkshelf/formatters.rb +11 -9
  63. data/lib/berkshelf/formatters/human_readable.rb +9 -9
  64. data/lib/berkshelf/formatters/json.rb +14 -4
  65. data/lib/berkshelf/init_generator.rb +3 -3
  66. data/lib/berkshelf/installer.rb +136 -0
  67. data/lib/berkshelf/location.rb +91 -131
  68. data/lib/berkshelf/locations/git_location.rb +9 -11
  69. data/lib/berkshelf/locations/github_location.rb +1 -1
  70. data/lib/berkshelf/locations/path_location.rb +10 -27
  71. data/lib/berkshelf/lockfile.rb +92 -70
  72. data/lib/berkshelf/logger.rb +4 -7
  73. data/lib/berkshelf/mixin/config.rb +21 -4
  74. data/lib/berkshelf/resolver.rb +60 -150
  75. data/lib/berkshelf/resolver/graph.rb +44 -0
  76. data/lib/berkshelf/source.rb +55 -0
  77. data/lib/berkshelf/source_uri.rb +38 -0
  78. data/lib/berkshelf/version.rb +1 -1
  79. data/spec/config/knife.rb +1 -1
  80. data/spec/fixtures/cassettes/Berkshelf_Resolver/_initialize/adds_the_dependencies_of_the_dependency_as_dependencies.yml +3694 -0
  81. data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +1 -1
  82. data/spec/fixtures/lockfiles/default.lock +1 -1
  83. data/spec/spec_helper.rb +20 -121
  84. data/spec/support/chef_api.rb +3 -4
  85. data/spec/support/chef_server.rb +20 -11
  86. data/spec/support/git.rb +127 -0
  87. data/spec/support/kitchen.rb +12 -0
  88. data/spec/support/path_helpers.rb +69 -0
  89. data/spec/unit/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  90. data/spec/unit/berkshelf/api_client_spec.rb +57 -0
  91. data/spec/unit/berkshelf/berksfile_spec.rb +206 -324
  92. data/spec/unit/berkshelf/cached_cookbook_spec.rb +73 -38
  93. data/spec/unit/berkshelf/community_rest_spec.rb +30 -71
  94. data/spec/unit/berkshelf/config_spec.rb +3 -14
  95. data/spec/unit/berkshelf/cookbook_generator_spec.rb +1 -2
  96. data/spec/unit/berkshelf/cookbook_store_spec.rb +12 -7
  97. data/spec/unit/berkshelf/dependency_spec.rb +285 -0
  98. data/spec/unit/berkshelf/downloader_spec.rb +4 -183
  99. data/spec/unit/berkshelf/formatters/null_spec.rb +1 -1
  100. data/spec/unit/berkshelf/formatters_spec.rb +4 -2
  101. data/spec/unit/berkshelf/git_spec.rb +15 -15
  102. data/spec/unit/berkshelf/installer_spec.rb +39 -0
  103. data/spec/unit/berkshelf/location_spec.rb +87 -114
  104. data/spec/unit/berkshelf/locations/git_location_spec.rb +41 -53
  105. data/spec/unit/berkshelf/locations/path_location_spec.rb +13 -23
  106. data/spec/unit/berkshelf/lockfile_spec.rb +38 -40
  107. data/spec/unit/berkshelf/resolver/graph_spec.rb +44 -0
  108. data/spec/unit/berkshelf/resolver_spec.rb +34 -83
  109. data/spec/unit/berkshelf/source_spec.rb +23 -0
  110. data/spec/unit/berkshelf/source_uri_spec.rb +29 -0
  111. metadata +149 -188
  112. checksums.yaml +0 -7
  113. data/features/default_locations.feature +0 -127
  114. data/features/step_definitions/berksfile_steps.rb +0 -8
  115. data/features/step_definitions/configure_cli_steps.rb +0 -19
  116. data/features/vendor_install.feature +0 -19
  117. data/lib/berkshelf/core_ext/openuri.rb +0 -36
  118. data/lib/berkshelf/core_ext/rbzip2.rb +0 -8
  119. data/lib/berkshelf/locations/chef_api_location.rb +0 -228
  120. data/lib/berkshelf/locations/site_location.rb +0 -92
  121. data/lib/berkshelf/test.rb +0 -35
  122. data/spec/knife.rb.sample +0 -12
  123. data/spec/support/test_generators.rb +0 -27
  124. data/spec/unit/berkshelf/cli_spec.rb +0 -16
  125. data/spec/unit/berkshelf/cookbook_source_spec.rb +0 -358
  126. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +0 -46
  127. data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +0 -139
  128. data/spec/unit/berkshelf/locations/site_location_spec.rb +0 -19
@@ -3,50 +3,6 @@ Feature: Displaying outdated cookbooks
3
3
  I want to know what cookbooks are outdated before I run update
4
4
  So that I can decide whether to update everything at once
5
5
 
6
- Scenario: Running berks outdated with no version constraints
7
- Given I write to "Berksfile" with:
8
- """
9
- site :opscode
10
- cookbook 'berkshelf-cookbook-fixture'
11
- """
12
- When I successfully run `berks outdated`
13
- Then the output should contain:
14
- """
15
- Listing outdated cookbooks with newer versions available...
16
- """
17
- And the output should contain:
18
- """
19
- All cookbooks up to date
20
- """
21
-
22
- Scenario: Running berks outdated with satisfied version constraints
23
- Given I write to "Berksfile" with:
24
- """
25
- site :opscode
26
- cookbook 'berkshelf-cookbook-fixture', '>= 0.1'
27
- """
28
- When I run `berks outdated`
29
- Then the output should contain:
30
- """
31
- Listing outdated cookbooks with newer versions available...
32
- """
33
- And the output should contain:
34
- """
35
- All cookbooks up to date
36
- """
37
-
38
- Scenario: Running berks outdated with unsatisfied version constraints
39
- Given I write to "Berksfile" with:
40
- """
41
- site :opscode
42
- cookbook 'berkshelf-cookbook-fixture', '~> 0.1'
43
- """
44
- When I run `berks outdated`
45
- Then the output should contain:
46
- """
47
- Listing outdated cookbooks with newer versions available...
48
- """
49
- And the output should contain:
50
- """
51
- Cookbook 'berkshelf-cookbook-fixture (~> 0.1)' is outdated
52
- """
6
+ Scenario: the dependency is up to date
7
+ Scenario: the dependency has a no version constraint and there are new items
8
+ Scenario: the dependency has a version constraint and there are new items that satisfy it
@@ -8,7 +8,8 @@ Feature: Packaging a cookbook as a tarball for distribution
8
8
  | fake | 1.0.0 |
9
9
  And I write to "Berksfile" with:
10
10
  """
11
- site :opscode
11
+ source "http://localhost:26210"
12
+
12
13
  cookbook 'fake', '~> 1.0.0'
13
14
  """
14
15
  When I successfully run `berks package fake`
@@ -17,26 +18,26 @@ Feature: Packaging a cookbook as a tarball for distribution
17
18
  """
18
19
  Cookbook(s) packaged to
19
20
  """
20
- And the exit status should be 0
21
21
 
22
22
  Scenario: With the --output option
23
23
  Given the cookbook store has the cookbooks:
24
24
  | fake | 1.0.0 |
25
25
  And I write to "Berksfile" with:
26
26
  """
27
- site :opscode
27
+ source "http://localhost:26210"
28
+
28
29
  cookbook 'fake', '~> 1.0.0'
29
30
  """
30
31
  When I successfully run `berks package fake --output foo/bar`
31
32
  Then a file named "foo/bar/fake.tar.gz" should exist
32
- And the exit status should be 0
33
33
 
34
34
  Scenario: With an installed cookbook name
35
35
  Given the cookbook store has the cookbooks:
36
36
  | fake | 1.0.0 |
37
37
  And I write to "Berksfile" with:
38
38
  """
39
- site :opscode
39
+ source "http://localhost:26210"
40
+
40
41
  cookbook 'fake', '~> 1.0.0'
41
42
  """
42
43
  When I run `berks package non-existent`
@@ -45,12 +46,14 @@ Feature: Packaging a cookbook as a tarball for distribution
45
46
  """
46
47
  Cookbook 'non-existent' is not in your Berksfile
47
48
  """
48
- And the CLI should exit with the status code for error "CookbookNotFound"
49
+ And the exit status should be "CookbookNotFound"
49
50
 
50
51
  Scenario: With an invalid cookbook
51
52
  Given a cookbook named "cookbook with spaces"
52
53
  And I write to "Berksfile" with:
53
54
  """
55
+ source "http://localhost:26210"
56
+
54
57
  cookbook 'cookbook with spaces', path: './cookbook with spaces'
55
58
  """
56
59
  When I run `berks package`
@@ -58,4 +61,4 @@ Feature: Packaging a cookbook as a tarball for distribution
58
61
  """
59
62
  The cookbook 'cookbook with spaces' has invalid filenames:
60
63
  """
61
- And the CLI should exit with the status code for error "InvalidCookbookFiles"
64
+ And the exit status should be "InvalidCookbookFiles"
@@ -9,7 +9,7 @@ Feature: Displaying information about a cookbook in the Berkshelf shelf
9
9
  """
10
10
  Cookbook 'fake' is not in the Berkshelf shelf
11
11
  """
12
- And the CLI should exit with the status code for error "CookbookNotFound"
12
+ And the exit status should be "CookbookNotFound"
13
13
 
14
14
  Scenario: With cookbooks in the store
15
15
  Given the cookbook store has the cookbooks:
@@ -63,7 +63,7 @@ Feature: Displaying information about a cookbook in the Berkshelf shelf
63
63
  """
64
64
  Cookbook 'fake' (1.2.3) is not in the Berkshelf shelf
65
65
  """
66
- And the CLI should exit with the status code for error "CookbookNotFound"
66
+ And the exit status should be "CookbookNotFound"
67
67
 
68
68
  Scenario: With multiple cookbook versions installed
69
69
  Given the cookbook store has the cookbooks:
@@ -9,7 +9,7 @@ Feature: Removing a cookbook from the Berkshelf shelf
9
9
  """
10
10
  Cookbook 'fake' is not in the Berkshelf shelf
11
11
  """
12
- And the CLI should exit with the status code for error "CookbookNotFound"
12
+ And the exit status should be "CookbookNotFound"
13
13
 
14
14
  Scenario: With two cookbooks in the store
15
15
  Given the cookbook store has the cookbooks:
@@ -26,7 +26,6 @@ Feature: Removing a cookbook from the Berkshelf shelf
26
26
  | ekaf | 2.3.4 |
27
27
  And the exit status should be 0
28
28
 
29
-
30
29
  Scenario: With multiple cookbook versions installed
31
30
  Given the cookbook store has the cookbooks:
32
31
  | fake | 1.0.0 |
@@ -67,6 +66,7 @@ Feature: Removing a cookbook from the Berkshelf shelf
67
66
  | fake | 2.0.0 |
68
67
  And the exit status should be 0
69
68
 
69
+ @spawn
70
70
  Scenario: With contingencies
71
71
  Given the cookbook store contains a cookbook "fake" "1.0.0" with dependencies:
72
72
  | ekaf | 2.3.4 |
@@ -8,6 +8,8 @@ Feature: Displaying information about a cookbook defined by a Berksfile
8
8
  | fake | 1.0.0 |
9
9
  And I write to "Berksfile" with:
10
10
  """
11
+ source "http://localhost:26210"
12
+
11
13
  cookbook 'fake', '1.0.0'
12
14
  """
13
15
  When I successfully run `berks show fake`
@@ -26,6 +28,8 @@ Feature: Displaying information about a cookbook defined by a Berksfile
26
28
  | fake | 1.0.0 |
27
29
  And I write to "Berksfile" with:
28
30
  """
31
+ source "http://localhost:26210"
32
+
29
33
  cookbook 'fake', '1.0.0'
30
34
  """
31
35
  When I successfully run `berks show fake --format json`
@@ -46,13 +50,16 @@ Feature: Displaying information about a cookbook defined by a Berksfile
46
50
 
47
51
  ],
48
52
  "messages": [
49
-
53
+ "building universe..."
50
54
  ]
51
55
  }
52
56
  """
53
57
 
54
58
  Scenario: When the cookbook is not in the Berksfile
55
- Given an empty file named "Berksfile"
59
+ Given I write to "Berksfile" with:
60
+ """
61
+ source "http://localhost:26210"
62
+ """
56
63
  When I run `berks show fake`
57
64
  Then the output should contain "Cookbook 'fake' is not installed by your Berksfile"
58
- And the CLI should exit with the status code for error "CookbookNotFound"
65
+ And the exit status should be "CookbookNotFound"
@@ -0,0 +1,12 @@
1
+ Given(/^I do not have a Berkshelf config$/) do
2
+ FileUtils.rm_f(ENV['BERKSHELF_CONFIG'])
3
+ end
4
+
5
+ Given /^I do not have a Chef config$/ do
6
+ path = tmp_path.join('knife.rb').to_s
7
+ Berkshelf.chef_config = Berkshelf::Chef::Config.new(path)
8
+ Berkshelf::Chef::Config.instance.save
9
+
10
+ ENV['BERKSHELF_CHEF_CONFIG'] = path
11
+ set_env 'BERKSHELF_CHEF_CONFIG', path
12
+ end
@@ -1,12 +1,10 @@
1
1
  World(Berkshelf::RSpec::ChefAPI)
2
2
 
3
- Given /^the Chef server does not have the cookbooks:$/ do |cookbooks|
4
- cookbooks.raw.each do |name, version|
5
- purge_cookbook(name, version)
6
- end
3
+ Given(/^the Chef Server is empty$/) do
4
+ Berkshelf::RSpec::ChefServer.reset!
7
5
  end
8
6
 
9
- Given /^the Chef server has cookbooks:$/ do |cookbooks|
7
+ Given /^the Chef Server has cookbooks:$/ do |cookbooks|
10
8
  cookbooks.raw.each do |name, version|
11
9
  purge_cookbook(name, version)
12
10
  cb_path = generate_cookbook(tmp_path, name, version)
@@ -14,32 +12,34 @@ Given /^the Chef server has cookbooks:$/ do |cookbooks|
14
12
  end
15
13
  end
16
14
 
17
- Then /^the Chef server should have the cookbooks:$/ do |cookbooks|
15
+ Then /^the Chef Server should have the cookbooks:$/ do |cookbooks|
18
16
  cookbooks.raw.each do |name, version|
19
17
  expect(server_has_cookbook?(name, version)).to be_true
20
18
  end
21
19
  end
22
20
 
23
- Then /^the Chef server should not have the cookbooks:$/ do |cookbooks|
21
+ Then /^the Chef Server should not have the cookbooks:$/ do |cookbooks|
24
22
  cookbooks.raw.each do |name, version|
25
23
  expect(server_has_cookbook?(name, version)).to be_false
26
24
  end
27
25
  end
28
26
 
29
- Given(/^I have an environment named "(.*?)"$/) do |environment_name|
27
+ Then(/^the version locks in the "(.*?)" environment should be:$/) do |environment_name, version_locks|
28
+ environment_cookbook_versions = environment(environment_name).cookbook_versions
29
+ version_locks.hashes.each do |hash|
30
+ expect(environment_cookbook_versions[hash['cookbook']]).to eq(hash['version_lock'])
31
+ end
32
+ end
33
+
34
+ Given(/^The Chef Server has an environment named "(.*?)"$/) do |environment_name|
30
35
  delete_environment(environment_name)
31
36
  begin
32
37
  create_environment(environment_name)
33
38
  rescue Ridley::Errors::HTTPConflict; end
34
39
  end
35
40
 
36
- Then(/^the version locks in "(.*?)" should be:$/) do |environment_name, version_locks|
37
- environment_cookbook_versions = environment(environment_name).cookbook_versions
38
- version_locks.hashes.each do |hash|
39
- expect(environment_cookbook_versions[hash['cookbook']]).to eq(hash['version_lock'])
41
+ Given(/^The Chef Server does not have an environment named "(.*?)"$/) do |environment_name|
42
+ if environment_exists?(environment_name)
43
+ delete_environment(environment_name)
40
44
  end
41
45
  end
42
-
43
- Given(/^I do not have an environment named "(.*?)"$/) do |environment_name|
44
- delete_environment(environment_name) if environment_exists? environment_name
45
- end
@@ -1,80 +1,4 @@
1
- require 'aruba/api'
2
-
3
- World(Aruba::Api)
4
- World(Berkshelf::RSpec::FileSystemMatchers)
5
-
6
- Then /^I trace$/ do
7
- end
8
-
9
- When /^I sleep$/ do
10
- sleep 10
11
- end
12
-
13
- Then /^a file named "(.*?)" should exist in the current directory$/ do |filename|
14
- in_current_dir do
15
- expect(File.exists?(filename)).to be_true # not sure why Aruba's
16
- # #check_file_presence
17
- # doesn't work here. It
18
- # looks in the wrong
19
- # directory.
20
- end
21
- end
22
-
23
- Then /^the file "(.*?)" should contain in the current directory:$/ do |filename, string|
24
- in_current_dir do
25
- expect(File.read(filename)).to match(Regexp.new(string))
26
- end
27
- end
28
-
29
- When /^I run the init command with the cookbook "(.*?)" as the target$/ do |cookbook_name|
30
- run_simple(unescape("berks init #{cookbook_name}"), true)
31
- end
32
-
33
- When /^I run the init command with the directory "(.*?)" as the target$/ do |directory_name|
34
- run_simple(unescape("berks init #{directory_name}"), true)
35
- end
36
-
37
- When /^I run the init command with no value for the target$/ do
38
- run_simple(unescape("berks init"), true)
39
- end
40
-
41
- When /^I run the install command$/ do
42
- run_simple(unescape("berks install"), false)
43
- end
44
-
45
- When /^I run the install command with flags:$/ do |flags|
46
- run_simple(unescape("berks install #{flags.raw.join(" ")}"), false)
47
- end
48
-
49
- When /^I run the upload command$/ do
50
- run_simple(unescape("berks upload"), true)
51
- end
52
-
53
- When /^I run the upload command with flags:$/ do |flags|
54
- run_simple(unescape("berks upload #{flags.raw.join(" ")}"), false)
55
- end
56
-
57
- When /^I run the cookbook command to create "(.*?)"$/ do |name|
58
- run_simple(unescape("berks cookbook #{name}"), false)
59
- end
60
-
61
- When /^I (successfully )?run the apply command on "(.*?)"$/ do |successfully, environment_name|
62
- run_simple(unescape("berks apply #{environment_name}"), !!successfully)
63
- end
64
-
65
- When /^I (successfully )?run the apply command on "(.*?)" with flags:$/ do |successfully, environment_name, flags|
66
- run_simple(unescape("berks apply #{environment_name} #{flags.raw.join(" ")}"), !!successfully)
67
- end
68
-
69
- When /^I run the cookbook command to create "(.*?)" with options:$/ do |name, options|
70
- run_simple(unescape("berks cookbook #{name} #{options.raw.join(" ")}"))
71
- end
72
-
73
- When /^I run the "(.*?)" command interactively$/ do |command|
74
- run_interactive("berks #{command}")
75
- end
76
-
77
- Then /^the CLI should exit with the status code for error "(.*?)"$/ do |error_constant|
78
- exit_status = Berkshelf.const_get(error_constant).status_code
79
- assert_exit_status(exit_status)
1
+ Then /^the exit status should be "(.+)"$/ do |name|
2
+ code = Berkshelf.const_get(name).status_code
3
+ assert_exit_status(code)
80
4
  end
@@ -0,0 +1,43 @@
1
+ require 'tempfile'
2
+
3
+ Given /^I already have a Berkshelf config file$/ do
4
+ path = Tempfile.new('berkshelf').path
5
+ config = Berkshelf::Config.new(path)
6
+ config.save
7
+
8
+ Berkshelf.config = config
9
+
10
+ ENV['BERKSHELF_CONFIG'] = path
11
+ set_env 'BERKSHELF_CONFIG', path
12
+ end
13
+
14
+ Given /^I have a Berkshelf config file containing:$/ do |contents|
15
+ path = Berkshelf.config.path
16
+ FileUtils.mkdir_p(Pathname.new(path).dirname.to_s)
17
+
18
+ File.open(path, 'w+') { |f| f.write(contents) }
19
+
20
+ Berkshelf.config = Berkshelf::Config.from_file(path)
21
+ end
22
+
23
+ Then /^a Berkshelf config file should exist and contain:$/ do |table|
24
+ # Have to reload the config...
25
+ Berkshelf.config.reload
26
+
27
+ check_file_presence([Berkshelf.config.path], true)
28
+
29
+ table.raw.each do |key, value|
30
+ expect(Berkshelf.config[key]).to eq(value)
31
+ end
32
+ end
33
+
34
+ Then /^a Berkshelf config file should exist at "(.+)" and contain:$/ do |path, table|
35
+ check_file_presence([path], true)
36
+
37
+ path = File.expand_path(File.join('tmp', 'aruba', path))
38
+ Berkshelf.config = Berkshelf::Config.from_file(path)
39
+
40
+ table.raw.each do |key, value|
41
+ expect(Berkshelf.config[key]).to eq(value)
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ Given /^the environment variable (.+) is nil$/ do |variable|
2
+ set_env(variable, nil)
3
+ end
4
+
5
+ Given /^the environment variable (.+) is "(.+)"$/ do |variable, value|
6
+ set_env(variable, value)
7
+ end
@@ -2,15 +2,7 @@ require 'aruba/api'
2
2
 
3
3
  World(Aruba::Api)
4
4
  World(Berkshelf::RSpec::ChefAPI)
5
-
6
- Given /^I dynamically write to "(.+)" with:$/ do |file, contents|
7
- steps %{
8
- Given I write to "#{file}" with:
9
- """
10
- #{ERB.new(contents).result(binding)}
11
- """
12
- }
13
- end
5
+ World(Berkshelf::RSpec::FileSystemMatchers)
14
6
 
15
7
  Given /^a cookbook named "(.*?)"$/ do |name|
16
8
  steps %{
@@ -19,44 +11,17 @@ Given /^a cookbook named "(.*?)"$/ do |name|
19
11
  }
20
12
  end
21
13
 
22
- Given /^I do not have a Berksfile$/ do
23
- in_current_dir { FileUtils.rm_f(Berkshelf::DEFAULT_FILENAME) }
24
- end
25
-
26
- Given /^I do not have a Berksfile\.lock$/ do
27
- in_current_dir { FileUtils.rm_f("#{Berkshelf::DEFAULT_FILENAME}.lock") }
28
- end
29
-
30
- Given /^I have a default Berkshelf config file$/ do
31
- Berkshelf::Config.new.save
32
- end
33
-
34
- Given /^I have a Berkshelf config file containing:$/ do |contents|
35
- ::File.open(Berkshelf::Config.path, 'w+') do |f|
36
- f.write(contents)
37
- end
38
- end
39
-
40
- Given /^I do not have a Berkshelf config file$/ do
41
- remove_file Berkshelf::Config.path if ::File.exists? Berkshelf::Config.path
42
- end
43
-
44
- Given /^I do not have a Berkshelf config file at "(.+)"$/ do |path|
45
- remove_file(path) if File.exists?(path)
46
- end
47
-
48
-
49
14
  Given /^the cookbook "(.*?)" has the file "(.*?)" with:$/ do |cookbook_name, file_name, content|
50
15
  write_file(::File.join(cookbook_name, file_name), content)
51
16
  end
52
17
 
53
18
  Given /^the cookbook store has the cookbooks:$/ do |cookbooks|
54
19
  cookbooks.raw.each do |name, version, license|
55
- generate_cookbook(cookbook_store, name, version, license: license)
20
+ generate_cookbook(cookbook_store.storage_path, name, version, license: license)
56
21
  end
57
22
  end
58
23
 
59
- Given /^the cookbook store has the cookbooks installed by git:$/ do |cookbooks|
24
+ Given /^the cookbook store has the git cookbooks:$/ do |cookbooks|
60
25
  cookbooks.raw.each do |name, version, sha|
61
26
  folder = "#{name}-#{sha}"
62
27
  metadata = File.join(folder, 'metadata.rb')
@@ -70,12 +35,16 @@ Given /^the cookbook store has the cookbooks installed by git:$/ do |cookbooks|
70
35
  end
71
36
 
72
37
  Given /^the cookbook store contains a cookbook "(.*?)" "(.*?)" with dependencies:$/ do |name, version, dependencies|
73
- generate_cookbook(cookbook_store, name, version, dependencies: dependencies.raw)
38
+ generate_cookbook(cookbook_store.storage_path, name, version, dependencies: dependencies.raw)
39
+ end
40
+
41
+ Given(/^the cookbook store is empty$/) do
42
+ Berkshelf::CookbookStore.instance.clean!
74
43
  end
75
44
 
76
45
  Then /^the cookbook store should have the cookbooks:$/ do |cookbooks|
77
46
  cookbooks.raw.each do |name, version|
78
- expect(cookbook_store).to have_structure {
47
+ expect(cookbook_store.storage_path).to have_structure {
79
48
  directory "#{name}-#{version}" do
80
49
  file "metadata.rb" do
81
50
  contains version
@@ -85,9 +54,9 @@ Then /^the cookbook store should have the cookbooks:$/ do |cookbooks|
85
54
  end
86
55
  end
87
56
 
88
- Then /^the cookbook store should have the cookbooks installed by git:$/ do |cookbooks|
57
+ Then /^the cookbook store should have the git cookbooks:$/ do |cookbooks|
89
58
  cookbooks.raw.each do |name, version, sha1|
90
- expect(cookbook_store).to have_structure {
59
+ expect(cookbook_store.storage_path).to have_structure {
91
60
  directory "#{name}-#{sha1}" do
92
61
  file "metadata.rb" do
93
62
  contains version
@@ -99,21 +68,16 @@ end
99
68
 
100
69
  Then /^the cookbook store should not have the cookbooks:$/ do |cookbooks|
101
70
  cookbooks.raw.each do |name, version|
102
- expect(cookbook_store).to_not have_structure {
71
+ expect(cookbook_store.storage_path).to_not have_structure {
103
72
  directory "#{name}-#{version}"
104
73
  }
105
74
  end
106
75
  end
107
76
 
108
- Then /^I should have the cookbook "(.*?)"$/ do |name|
109
- expect(Pathname.new(current_dir).join(name)).to be_cookbook
110
- end
111
-
112
77
  Then /^I should have a new cookbook skeleton "(.*?)"$/ do |name|
113
78
  cb_path = Pathname.new(current_dir).join(name)
114
79
  expect(cb_path).to have_structure {
115
80
  directory "attributes"
116
- directory "definitions"
117
81
  directory "files" do
118
82
  directory "default"
119
83
  end
@@ -206,7 +170,6 @@ Then /^I should have a new cookbook skeleton "(.*?)" with no Bundler support$/ d
206
170
  cb_path = Pathname.new(current_dir).join(name)
207
171
  expect(cb_path).to have_structure {
208
172
  directory "attributes"
209
- directory "definitions"
210
173
  directory "files" do
211
174
  directory "default"
212
175
  end
@@ -287,11 +250,3 @@ Then /^the file "(.*?)" in the directory "(.*?)" should not contain:$/ do |file_
287
250
  end
288
251
  }
289
252
  end
290
-
291
- Then /^the current directory should have the following files:$/ do |files|
292
- check_file_presence(files.raw.map{|file_row| file_row[0]}, true)
293
- end
294
-
295
- Then /^the current directory should not have the following files:$/ do |files|
296
- check_file_presence(files.raw.map{|file_row| file_row[0]}, false)
297
- end