librarian 0.0.24 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/.travis.yml +7 -1
  2. data/CHANGELOG.md +19 -1
  3. data/README.md +2 -9
  4. data/Rakefile +0 -11
  5. data/lib/librarian.rb +0 -8
  6. data/lib/librarian/action/base.rb +6 -4
  7. data/lib/librarian/chef/cli.rb +1 -1
  8. data/lib/librarian/chef/integration/knife.rb +4 -0
  9. data/lib/librarian/chef/manifest_reader.rb +14 -2
  10. data/lib/librarian/chef/source/local.rb +2 -0
  11. data/lib/librarian/chef/source/site.rb +49 -41
  12. data/lib/librarian/cli.rb +32 -17
  13. data/lib/librarian/dependency.rb +1 -9
  14. data/lib/librarian/dsl.rb +6 -3
  15. data/lib/librarian/dsl/receiver.rb +10 -12
  16. data/lib/librarian/dsl/target.rb +5 -10
  17. data/lib/librarian/environment.rb +41 -2
  18. data/lib/librarian/lockfile.rb +0 -4
  19. data/lib/librarian/lockfile/compiler.rb +0 -4
  20. data/lib/librarian/lockfile/parser.rb +0 -4
  21. data/lib/librarian/logger.rb +46 -0
  22. data/lib/librarian/manifest.rb +1 -9
  23. data/lib/librarian/resolution.rb +5 -3
  24. data/lib/librarian/resolver.rb +6 -1
  25. data/lib/librarian/resolver/implementation.rb +18 -8
  26. data/lib/librarian/source/git.rb +2 -0
  27. data/lib/librarian/source/git/repository.rb +9 -5
  28. data/lib/librarian/source/local.rb +12 -2
  29. data/lib/librarian/spec.rb +4 -4
  30. data/lib/librarian/spec_change_set.rb +7 -4
  31. data/lib/librarian/specfile.rb +3 -8
  32. data/lib/librarian/version.rb +1 -1
  33. data/librarian.gemspec +3 -9
  34. data/spec/functional/chef/cli_spec.rb +194 -0
  35. data/spec/functional/chef/source/site_spec.rb +11 -10
  36. data/spec/functional/source/git/repository_spec.rb +1 -1
  37. data/spec/support/cli_macro.rb +122 -0
  38. data/spec/support/with_env_macro.rb +20 -0
  39. data/spec/unit/config/database_spec.rb +2 -2
  40. data/spec/unit/dependency_spec.rb +6 -0
  41. data/spec/unit/dsl_spec.rb +16 -37
  42. data/spec/unit/environment_spec.rb +95 -0
  43. data/spec/unit/manifest_spec.rb +6 -0
  44. data/spec/unit/resolver_spec.rb +41 -0
  45. metadata +7 -42
  46. data/config/cucumber.yaml +0 -1
  47. data/features/chef/cli/init.feature +0 -11
  48. data/features/chef/cli/install.feature +0 -64
  49. data/features/chef/cli/show.feature +0 -77
  50. data/features/chef/cli/version.feature +0 -11
  51. data/features/support/env.rb +0 -9
  52. data/lib/librarian/helpers/debug.rb +0 -35
@@ -1,7 +1,5 @@
1
1
  require 'open3'
2
2
 
3
- require 'librarian/helpers/debug'
4
-
5
3
  module Librarian
6
4
  module Source
7
5
  class Git
@@ -41,8 +39,6 @@ module Librarian
41
39
  end
42
40
  end
43
41
 
44
- include Helpers::Debug
45
-
46
42
  attr_accessor :environment, :path
47
43
  private :environment=, :path=
48
44
 
@@ -77,7 +73,7 @@ module Librarian
77
73
 
78
74
  def checkout!(reference, options ={ })
79
75
  command = %W(checkout #{reference} --quiet)
80
- command << "--force" if options[:force]
76
+ command << "--force" if options[:force]
81
77
  run!(command, :chdir => true)
82
78
  end
83
79
 
@@ -207,6 +203,14 @@ module Librarian
207
203
  end
208
204
  end
209
205
 
206
+ def debug(*args, &block)
207
+ environment.logger.debug(*args, &block)
208
+ end
209
+
210
+ def relative_path_to(path)
211
+ environment.logger.relative_path_to(path)
212
+ end
213
+
210
214
  end
211
215
  end
212
216
  end
@@ -1,4 +1,3 @@
1
- require 'librarian/helpers/debug'
2
1
  require 'librarian/support/abstract_method'
3
2
 
4
3
  module Librarian
@@ -8,7 +7,6 @@ module Librarian
8
7
  # #environment
9
8
  module Local
10
9
 
11
- include Helpers::Debug
12
10
  include Support::AbstractMethod
13
11
 
14
12
  abstract_method :path, :fetch_version, :fetch_dependencies
@@ -46,6 +44,18 @@ module Librarian
46
44
 
47
45
  abstract_method :manifest? # (name, path) -> boolean
48
46
 
47
+ def info(*args, &block)
48
+ environment.logger.info(*args, &block)
49
+ end
50
+
51
+ def debug(*args, &block)
52
+ environment.logger.debug(*args, &block)
53
+ end
54
+
55
+ def relative_path_to(path)
56
+ environment.logger.relative_path_to(path)
57
+ end
58
+
49
59
  end
50
60
  end
51
61
  end
@@ -1,11 +1,11 @@
1
1
  module Librarian
2
2
  class Spec
3
3
 
4
- attr_accessor :source, :dependencies
5
- private :source=, :dependencies=
4
+ attr_accessor :sources, :dependencies
5
+ private :sources=, :dependencies=
6
6
 
7
- def initialize(source, dependencies)
8
- self.source = source
7
+ def initialize(sources, dependencies)
8
+ self.sources = sources
9
9
  self.dependencies = dependencies
10
10
  end
11
11
 
@@ -1,5 +1,4 @@
1
1
  require 'librarian/helpers'
2
- require 'librarian/helpers/debug'
3
2
 
4
3
  require 'librarian/manifest_set'
5
4
  require 'librarian/resolution'
@@ -8,8 +7,6 @@ require 'librarian/spec'
8
7
  module Librarian
9
8
  class SpecChangeSet
10
9
 
11
- include Helpers::Debug
12
-
13
10
  attr_accessor :environment
14
11
  private :environment=
15
12
  attr_reader :spec, :lock
@@ -71,7 +68,7 @@ module Librarian
71
68
  def explicit_removed_dependency_names
72
69
  @explicit_removed_dependency_names ||= removed_dependency_names.reject do |name|
73
70
  lock_manifest = lock_manifests_index[name]
74
- lock_manifest.source == spec.source
71
+ spec.sources.include?(lock_manifest.source)
75
72
  end.to_set
76
73
  end
77
74
 
@@ -166,5 +163,11 @@ module Librarian
166
163
  end
167
164
  end
168
165
 
166
+ private
167
+
168
+ def debug(*args, &block)
169
+ environment.logger.debug(*args, &block)
170
+ end
171
+
169
172
  end
170
173
  end
@@ -1,17 +1,12 @@
1
- require 'librarian/helpers/debug'
2
-
3
1
  module Librarian
4
2
  class Specfile
5
3
 
6
- include Helpers::Debug
7
-
8
- attr_accessor :environment
9
- private :environment=
10
- attr_reader :path, :dependencies, :source
4
+ attr_accessor :environment, :path
5
+ private :environment=, :path=
11
6
 
12
7
  def initialize(environment, path)
13
8
  self.environment = environment
14
- @path = path
9
+ self.path = path
15
10
  end
16
11
 
17
12
  def read(precache_sources = [])
@@ -1,3 +1,3 @@
1
1
  module Librarian
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.25"
3
3
  end
data/librarian.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "librarian"
5
- s.version = "0.0.24"
5
+ s.version = "0.0.25"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jay Feldblum"]
9
- s.date = "2012-06-23"
9
+ s.date = "2012-10-12"
10
10
  s.description = "Librarian"
11
11
  s.email = ["y_feldblum@yahoo.com"]
12
12
  s.executables = ["librarian-chef", "librarian-mock"]
13
- s.files = [".gitignore", ".rspec", ".travis.yml", "CHANGELOG.md", "Gemfile", "MIT-LICENSE", "README.md", "Rakefile", "bin/librarian-chef", "bin/librarian-mock", "config/cucumber.yaml", "features/chef/cli/init.feature", "features/chef/cli/install.feature", "features/chef/cli/show.feature", "features/chef/cli/version.feature", "features/support/env.rb", "lib/librarian.rb", "lib/librarian/action.rb", "lib/librarian/action/base.rb", "lib/librarian/action/clean.rb", "lib/librarian/action/ensure.rb", "lib/librarian/action/install.rb", "lib/librarian/action/resolve.rb", "lib/librarian/action/update.rb", "lib/librarian/chef.rb", "lib/librarian/chef/cli.rb", "lib/librarian/chef/dsl.rb", "lib/librarian/chef/environment.rb", "lib/librarian/chef/extension.rb", "lib/librarian/chef/integration/knife.rb", "lib/librarian/chef/manifest_reader.rb", "lib/librarian/chef/source.rb", "lib/librarian/chef/source/git.rb", "lib/librarian/chef/source/local.rb", "lib/librarian/chef/source/path.rb", "lib/librarian/chef/source/site.rb", "lib/librarian/chef/templates/Cheffile", "lib/librarian/cli.rb", "lib/librarian/cli/manifest_presenter.rb", "lib/librarian/config.rb", "lib/librarian/config/database.rb", "lib/librarian/config/file_source.rb", "lib/librarian/config/hash_source.rb", "lib/librarian/config/source.rb", "lib/librarian/dependency.rb", "lib/librarian/dsl.rb", "lib/librarian/dsl/receiver.rb", "lib/librarian/dsl/target.rb", "lib/librarian/environment.rb", "lib/librarian/error.rb", "lib/librarian/helpers.rb", "lib/librarian/helpers/debug.rb", "lib/librarian/lockfile.rb", "lib/librarian/lockfile/compiler.rb", "lib/librarian/lockfile/parser.rb", "lib/librarian/manifest.rb", "lib/librarian/manifest_set.rb", "lib/librarian/mock.rb", "lib/librarian/mock/cli.rb", "lib/librarian/mock/dsl.rb", "lib/librarian/mock/environment.rb", "lib/librarian/mock/extension.rb", "lib/librarian/mock/source.rb", "lib/librarian/mock/source/mock.rb", "lib/librarian/mock/source/mock/registry.rb", "lib/librarian/resolution.rb", "lib/librarian/resolver.rb", "lib/librarian/resolver/implementation.rb", "lib/librarian/source.rb", "lib/librarian/source/git.rb", "lib/librarian/source/git/repository.rb", "lib/librarian/source/local.rb", "lib/librarian/source/path.rb", "lib/librarian/spec.rb", "lib/librarian/spec_change_set.rb", "lib/librarian/specfile.rb", "lib/librarian/support/abstract_method.rb", "lib/librarian/ui.rb", "lib/librarian/version.rb", "librarian.gemspec", "spec/functional/chef/source/git_spec.rb", "spec/functional/chef/source/site_spec.rb", "spec/functional/source/git/repository_spec.rb", "spec/unit/action/base_spec.rb", "spec/unit/action/clean_spec.rb", "spec/unit/action/ensure_spec.rb", "spec/unit/action/install_spec.rb", "spec/unit/config/database_spec.rb", "spec/unit/dependency_spec.rb", "spec/unit/dsl_spec.rb", "spec/unit/environment_spec.rb", "spec/unit/lockfile/parser_spec.rb", "spec/unit/lockfile_spec.rb", "spec/unit/manifest_set_spec.rb", "spec/unit/manifest_spec.rb", "spec/unit/mock/source/mock_spec.rb", "spec/unit/resolver_spec.rb", "spec/unit/source/git_spec.rb", "spec/unit/spec_change_set_spec.rb"]
13
+ s.files = [".gitignore", ".rspec", ".travis.yml", "CHANGELOG.md", "Gemfile", "MIT-LICENSE", "README.md", "Rakefile", "bin/librarian-chef", "bin/librarian-mock", "lib/librarian.rb", "lib/librarian/action.rb", "lib/librarian/action/base.rb", "lib/librarian/action/clean.rb", "lib/librarian/action/ensure.rb", "lib/librarian/action/install.rb", "lib/librarian/action/resolve.rb", "lib/librarian/action/update.rb", "lib/librarian/chef.rb", "lib/librarian/chef/cli.rb", "lib/librarian/chef/dsl.rb", "lib/librarian/chef/environment.rb", "lib/librarian/chef/extension.rb", "lib/librarian/chef/integration/knife.rb", "lib/librarian/chef/manifest_reader.rb", "lib/librarian/chef/source.rb", "lib/librarian/chef/source/git.rb", "lib/librarian/chef/source/local.rb", "lib/librarian/chef/source/path.rb", "lib/librarian/chef/source/site.rb", "lib/librarian/chef/templates/Cheffile", "lib/librarian/cli.rb", "lib/librarian/cli/manifest_presenter.rb", "lib/librarian/config.rb", "lib/librarian/config/database.rb", "lib/librarian/config/file_source.rb", "lib/librarian/config/hash_source.rb", "lib/librarian/config/source.rb", "lib/librarian/dependency.rb", "lib/librarian/dsl.rb", "lib/librarian/dsl/receiver.rb", "lib/librarian/dsl/target.rb", "lib/librarian/environment.rb", "lib/librarian/error.rb", "lib/librarian/helpers.rb", "lib/librarian/lockfile.rb", "lib/librarian/lockfile/compiler.rb", "lib/librarian/lockfile/parser.rb", "lib/librarian/logger.rb", "lib/librarian/manifest.rb", "lib/librarian/manifest_set.rb", "lib/librarian/mock.rb", "lib/librarian/mock/cli.rb", "lib/librarian/mock/dsl.rb", "lib/librarian/mock/environment.rb", "lib/librarian/mock/extension.rb", "lib/librarian/mock/source.rb", "lib/librarian/mock/source/mock.rb", "lib/librarian/mock/source/mock/registry.rb", "lib/librarian/resolution.rb", "lib/librarian/resolver.rb", "lib/librarian/resolver/implementation.rb", "lib/librarian/source.rb", "lib/librarian/source/git.rb", "lib/librarian/source/git/repository.rb", "lib/librarian/source/local.rb", "lib/librarian/source/path.rb", "lib/librarian/spec.rb", "lib/librarian/spec_change_set.rb", "lib/librarian/specfile.rb", "lib/librarian/support/abstract_method.rb", "lib/librarian/ui.rb", "lib/librarian/version.rb", "librarian.gemspec", "spec/functional/chef/cli_spec.rb", "spec/functional/chef/source/git_spec.rb", "spec/functional/chef/source/site_spec.rb", "spec/functional/source/git/repository_spec.rb", "spec/support/cli_macro.rb", "spec/support/with_env_macro.rb", "spec/unit/action/base_spec.rb", "spec/unit/action/clean_spec.rb", "spec/unit/action/ensure_spec.rb", "spec/unit/action/install_spec.rb", "spec/unit/config/database_spec.rb", "spec/unit/dependency_spec.rb", "spec/unit/dsl_spec.rb", "spec/unit/environment_spec.rb", "spec/unit/lockfile/parser_spec.rb", "spec/unit/lockfile_spec.rb", "spec/unit/manifest_set_spec.rb", "spec/unit/manifest_spec.rb", "spec/unit/mock/source/mock_spec.rb", "spec/unit/resolver_spec.rb", "spec/unit/source/git_spec.rb", "spec/unit/spec_change_set_spec.rb"]
14
14
  s.homepage = ""
15
15
  s.require_paths = ["lib"]
16
16
  s.rubyforge_project = "librarian"
@@ -24,8 +24,6 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency(%q<thor>, ["~> 0.15"])
25
25
  s.add_development_dependency(%q<rake>, [">= 0"])
26
26
  s.add_development_dependency(%q<rspec>, [">= 0"])
27
- s.add_development_dependency(%q<cucumber>, [">= 0"])
28
- s.add_development_dependency(%q<aruba>, [">= 0"])
29
27
  s.add_development_dependency(%q<webmock>, [">= 0"])
30
28
  s.add_development_dependency(%q<fakefs>, [">= 0"])
31
29
  s.add_runtime_dependency(%q<chef>, [">= 0.10"])
@@ -35,8 +33,6 @@ Gem::Specification.new do |s|
35
33
  s.add_dependency(%q<thor>, ["~> 0.15"])
36
34
  s.add_dependency(%q<rake>, [">= 0"])
37
35
  s.add_dependency(%q<rspec>, [">= 0"])
38
- s.add_dependency(%q<cucumber>, [">= 0"])
39
- s.add_dependency(%q<aruba>, [">= 0"])
40
36
  s.add_dependency(%q<webmock>, [">= 0"])
41
37
  s.add_dependency(%q<fakefs>, [">= 0"])
42
38
  s.add_dependency(%q<chef>, [">= 0.10"])
@@ -47,8 +43,6 @@ Gem::Specification.new do |s|
47
43
  s.add_dependency(%q<thor>, ["~> 0.15"])
48
44
  s.add_dependency(%q<rake>, [">= 0"])
49
45
  s.add_dependency(%q<rspec>, [">= 0"])
50
- s.add_dependency(%q<cucumber>, [">= 0"])
51
- s.add_dependency(%q<aruba>, [">= 0"])
52
46
  s.add_dependency(%q<webmock>, [">= 0"])
53
47
  s.add_dependency(%q<fakefs>, [">= 0"])
54
48
  s.add_dependency(%q<chef>, [">= 0.10"])
@@ -0,0 +1,194 @@
1
+ require "securerandom"
2
+
3
+ require "support/cli_macro"
4
+
5
+ require "librarian/chef/cli"
6
+
7
+ module Librarian
8
+ module Chef
9
+ describe Cli do
10
+ include CliMacro
11
+
12
+ describe "init" do
13
+ before do
14
+ cli! "init"
15
+ end
16
+
17
+ it "should create a file named Cheffile" do
18
+ pwd.should have_file "Cheffile"
19
+ end
20
+ end
21
+
22
+ describe "version" do
23
+ before do
24
+ cli! "version"
25
+ end
26
+
27
+ it "should print the version" do
28
+ stdout.should == strip_heredoc(<<-STDOUT)
29
+ librarian-#{VERSION}
30
+ STDOUT
31
+ end
32
+ end
33
+
34
+ describe "install" do
35
+
36
+ context "a simple Cheffile with one cookbook" do
37
+ let(:metadata) { {
38
+ "name" => "apt",
39
+ "version" => "1.0.0",
40
+ "dependencies" => { },
41
+ } }
42
+
43
+ before do
44
+ write_json_file! "cookbook-sources/apt/metadata.json", metadata
45
+ write_file! "Cheffile", strip_heredoc(<<-CHEFFILE)
46
+ cookbook 'apt',
47
+ :path => 'cookbook-sources'
48
+ CHEFFILE
49
+
50
+ cli! "install"
51
+ end
52
+
53
+ it "should write a lockfile" do
54
+ pwd.should have_file "Cheffile.lock"
55
+ end
56
+
57
+ it "should install the cookbook" do
58
+ pwd.should have_json_file "cookbooks/apt/metadata.json", metadata
59
+ end
60
+ end
61
+
62
+ context "a simple Cheffile with one cookbook with one dependency" do
63
+ let(:main_metadata) { {
64
+ "name" => "main",
65
+ "version" => "1.0.0",
66
+ "dependencies" => {
67
+ "sub" => "1.0.0",
68
+ }
69
+ } }
70
+ let(:sub_metadata) { {
71
+ "name" => "sub",
72
+ "version" => "1.0.0",
73
+ "dependencies" => { },
74
+ } }
75
+
76
+ before do
77
+ write_json_file! "cookbook-sources/main/metadata.json", main_metadata
78
+ write_json_file! "cookbook-sources/sub/metadata.json", sub_metadata
79
+ write_file! "Cheffile", strip_heredoc(<<-CHEFFILE)
80
+ path 'cookbook-sources'
81
+ cookbook 'main'
82
+ CHEFFILE
83
+
84
+ cli! "install"
85
+ end
86
+
87
+ it "should write a lockfile" do
88
+ pwd.should have_file "Cheffile.lock"
89
+ end
90
+
91
+ it "should install the dependant cookbook" do
92
+ pwd.should have_json_file "cookbooks/main/metadata.json", main_metadata
93
+ end
94
+
95
+ it "should install the independent cookbook" do
96
+ pwd.should have_json_file "cookbooks/sub/metadata.json", sub_metadata
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ describe "show" do
103
+ let(:main_metadata) { {
104
+ "name" => "main",
105
+ "version" => "1.0.0",
106
+ "dependencies" => {
107
+ "sub" => "1.0.0",
108
+ }
109
+ } }
110
+ let(:sub_metadata) { {
111
+ "name" => "sub",
112
+ "version" => "1.0.0",
113
+ "dependencies" => { },
114
+ } }
115
+
116
+ before do
117
+ write_json_file! "cookbook-sources/main/metadata.json", main_metadata
118
+ write_json_file! "cookbook-sources/sub/metadata.json", sub_metadata
119
+ write_file! "Cheffile", strip_heredoc(<<-CHEFFILE)
120
+ path 'cookbook-sources'
121
+ cookbook 'main'
122
+ CHEFFILE
123
+
124
+ cli! "install"
125
+ end
126
+
127
+ context "showing all without a lockfile" do
128
+ before do
129
+ pwd.join("Cheffile.lock").delete
130
+
131
+ cli! "show"
132
+ end
133
+
134
+ specify { exit_status.should == 1 }
135
+
136
+ it "should print a warning" do
137
+ stdout.should == strip_heredoc(<<-STDOUT)
138
+ Be sure to install first!
139
+ STDOUT
140
+ end
141
+ end
142
+
143
+ context "showing all" do
144
+ before do
145
+ cli! "show"
146
+ end
147
+
148
+ specify { exit_status.should == 0 }
149
+
150
+ it "should print a summary" do
151
+ stdout.should == strip_heredoc(<<-STDOUT)
152
+ main (1.0.0)
153
+ sub (1.0.0)
154
+ STDOUT
155
+ end
156
+ end
157
+
158
+ context "showing one without dependencies" do
159
+ before do
160
+ cli! "show", "sub"
161
+ end
162
+
163
+ specify { exit_status.should == 0 }
164
+
165
+ it "should print the details" do
166
+ stdout.should == strip_heredoc(<<-STDOUT)
167
+ sub (1.0.0)
168
+ source: cookbook-sources
169
+ STDOUT
170
+ end
171
+ end
172
+
173
+ context "showing one with dependencies" do
174
+ before do
175
+ cli! "show", "main"
176
+ end
177
+
178
+ specify { exit_status.should == 0 }
179
+
180
+ it "should print the details" do
181
+ stdout.should == strip_heredoc(<<-STDOUT)
182
+ main (1.0.0)
183
+ source: cookbook-sources
184
+ dependencies:
185
+ sub (= 1.0.0)
186
+ STDOUT
187
+ end
188
+ end
189
+
190
+ end
191
+
192
+ end
193
+ end
194
+ end
@@ -44,19 +44,20 @@ module Librarian
44
44
  "file" => "#{api_url}/cookbooks/sample/versions/0_6_5/file.tar.gz"
45
45
  }
46
46
  end
47
+ let(:sample_0_6_5_package) do
48
+ s = StringIO.new
49
+ z = Zlib::GzipWriter.new(s, Zlib::NO_COMPRESSION)
50
+ t = Archive::Tar::Minitar::Output.new(z)
51
+ t.tar.add_file_simple("sample/metadata.rb", :mode => 0700,
52
+ :size => sample_metadata.bytesize){|io| io.write(sample_metadata)}
53
+ t.close
54
+ z.close unless z.closed?
55
+ s.string
56
+ end
47
57
 
48
58
  # depends on repo_path being defined in each context
49
59
  let(:env) { Environment.new(:project_path => repo_path) }
50
60
 
51
- before :all do
52
- sample_path.rmtree if sample_path.exist?
53
- sample_path.mkpath
54
- sample_path.join("metadata.rb").open("wb") { |f| f.write(sample_metadata) }
55
- Dir.chdir(sample_path.dirname) do
56
- system "tar --create --gzip --file sample.tar.gz #{sample_path.basename}"
57
- end
58
- end
59
-
60
61
  before do
61
62
  stub_request(:get, "#{api_url}/cookbooks/sample").
62
63
  to_return(:body => JSON.dump(sample_index_data))
@@ -65,7 +66,7 @@ module Librarian
65
66
  to_return(:body => JSON.dump(sample_0_6_5_data))
66
67
 
67
68
  stub_request(:get, "#{api_url}/cookbooks/sample/versions/0_6_5/file.tar.gz").
68
- to_return(:body => sample_path.dirname.join("sample.tar.gz").read)
69
+ to_return(:body => sample_0_6_5_package)
69
70
  end
70
71
 
71
72
  after do
@@ -7,7 +7,7 @@ require "librarian/source/git/repository"
7
7
  describe Librarian::Source::Git::Repository do
8
8
 
9
9
  let(:env) do
10
- double(:ui => nil)
10
+ double(:ui => nil, :logger => double(:debug => nil, :info => nil))
11
11
  end
12
12
 
13
13
  let(:project_path) do
@@ -0,0 +1,122 @@
1
+ require "json"
2
+ require "pathname"
3
+ require "securerandom"
4
+ require "stringio"
5
+ require "thor"
6
+
7
+ require "librarian/helpers"
8
+
9
+ module CliMacro
10
+
11
+ class FakeShell < Thor::Shell::Basic
12
+ def stdout
13
+ @stdout ||= StringIO.new
14
+ end
15
+ def stderr
16
+ @stderr ||= StringIO.new
17
+ end
18
+ def stdin
19
+ raise "unsupported"
20
+ end
21
+ end
22
+
23
+ class FileMatcher
24
+ attr_accessor :rel_path, :content, :type, :base_path
25
+ def initialize(rel_path, content, options = { })
26
+ self.rel_path = rel_path
27
+ self.content = content
28
+ self.type = options[:type]
29
+ end
30
+ def full_path
31
+ @full_path ||= base_path + rel_path
32
+ end
33
+ def actual_content
34
+ @actual_content ||= begin
35
+ s = full_path.read
36
+ s = JSON.parse(s) if type == :json
37
+ s
38
+ end
39
+ end
40
+ def matches?(base_path)
41
+ base_path = Pathname(base_path) unless Pathname === base_path
42
+ self.base_path = base_path
43
+
44
+ full_path.file? && (!content || actual_content == content)
45
+ end
46
+ end
47
+
48
+ def self.included(base)
49
+ base.instance_exec do
50
+ let(:project_path) do
51
+ project_path = Pathname.new(__FILE__).expand_path
52
+ project_path = project_path.dirname until project_path.join("Rakefile").exist?
53
+ project_path
54
+ end
55
+ let(:tmp) { project_path.join("tmp/spec/cli") }
56
+ let(:pwd) { tmp + SecureRandom.hex(8) }
57
+
58
+ before { tmp.mkpath }
59
+ before { pwd.mkpath }
60
+
61
+ after { tmp.rmtree }
62
+ end
63
+ end
64
+
65
+ def cli!(*args)
66
+ Dir.chdir(pwd) do
67
+ described_class.with_environment do |environment|
68
+ begin
69
+ @shell = FakeShell.new
70
+ @exit_status = nil
71
+ described_class.start args, :shell => @shell
72
+ @exit_status = 0
73
+ rescue Librarian::Error => e
74
+ environment.ui.error e.message
75
+ environment.ui.debug e.backtrace.join("\n")
76
+ @exit_status = e.respond_to?(:status_code) ? e.status_code : 1
77
+ rescue Exception => e
78
+ @exit_status = 1
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def write_file!(path, content)
85
+ path = pwd.join(path)
86
+ path.dirname.mkpath
87
+ path.open("wb"){|f| f.write(content)}
88
+ end
89
+
90
+ def write_json_file!(path, content)
91
+ write_file! path, JSON.dump(content)
92
+ end
93
+
94
+ def strip_heredoc(text)
95
+ Librarian::Helpers.strip_heredoc(text)
96
+ end
97
+
98
+ def shell
99
+ @shell
100
+ end
101
+
102
+ def stdout
103
+ shell.stdout.string
104
+ end
105
+
106
+ def stderr
107
+ shell.stderr.string
108
+ end
109
+
110
+ def exit_status
111
+ @exit_status
112
+ end
113
+
114
+ def have_file(rel_path, content = nil)
115
+ FileMatcher.new(rel_path, content)
116
+ end
117
+
118
+ def have_json_file(rel_path, content)
119
+ FileMatcher.new(rel_path, content, :type => :json)
120
+ end
121
+
122
+ end