puppet 4.0.0.rc1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +11 -6
  3. data/Gemfile +1 -1
  4. data/conf/environment.conf +4 -2
  5. data/ext/build_defaults.yaml +3 -3
  6. data/ext/debian/control +2 -2
  7. data/ext/project_data.yaml +1 -1
  8. data/ext/rack/config.ru +1 -0
  9. data/ext/redhat/client.sysconfig +1 -1
  10. data/ext/redhat/puppet.spec.erb +2 -2
  11. data/ext/systemd/puppet.service +1 -0
  12. data/install.rb +2 -2
  13. data/lib/puppet/application/device.rb +22 -5
  14. data/lib/puppet/data_providers.rb +7 -4
  15. data/lib/puppet/data_providers/data_adapter.rb +6 -1
  16. data/lib/puppet/data_providers/data_function_support.rb +17 -4
  17. data/lib/puppet/data_providers/function_env_data_provider.rb +1 -1
  18. data/lib/puppet/data_providers/function_module_data_provider.rb +14 -19
  19. data/lib/puppet/defaults.rb +43 -16
  20. data/lib/puppet/error.rb +4 -0
  21. data/lib/puppet/pops/evaluator/evaluator_impl.rb +33 -4
  22. data/lib/puppet/pops/evaluator/runtime3_support.rb +5 -1
  23. data/lib/puppet/pops/parser/egrammar.ra +2 -0
  24. data/lib/puppet/pops/parser/eparser.rb +732 -724
  25. data/lib/puppet/pops/parser/heredoc_support.rb +1 -1
  26. data/lib/puppet/pops/parser/lexer2.rb +19 -21
  27. data/lib/puppet/provider/macauthorization/macauthorization.rb +1 -1
  28. data/lib/puppet/provider/nameservice/directoryservice.rb +1 -1
  29. data/lib/puppet/provider/package/appdmg.rb +1 -1
  30. data/lib/puppet/provider/package/gem.rb +19 -6
  31. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  32. data/lib/puppet/provider/package/puppet_gem.rb +17 -0
  33. data/lib/puppet/provider/service/launchd.rb +1 -1
  34. data/lib/puppet/provider/user/directoryservice.rb +2 -2
  35. data/lib/puppet/settings.rb +1 -1
  36. data/lib/puppet/util/errors.rb +4 -2
  37. data/lib/puppet/util/network_device/config.rb +5 -0
  38. data/lib/puppet/util/run_mode.rb +28 -11
  39. data/lib/puppet/util/windows/registry.rb +3 -3
  40. data/lib/puppet/vendor/deep_merge/PUPPET_README.md +6 -0
  41. data/lib/puppet/vendor/load_plist.rb +1 -0
  42. data/lib/puppet/vendor/plist/CHANGELOG +82 -0
  43. data/lib/puppet/vendor/plist/MIT-LICENSE +21 -0
  44. data/lib/puppet/vendor/plist/PUPPET_README.md +6 -0
  45. data/lib/puppet/vendor/plist/README +36 -0
  46. data/lib/puppet/vendor/plist/Rakefile +144 -0
  47. data/lib/puppet/vendor/plist/docs/USAGE +104 -0
  48. data/lib/puppet/vendor/plist/docs/jamis-template.rb +591 -0
  49. data/lib/puppet/vendor/plist/lib/plist.rb +22 -0
  50. data/lib/puppet/vendor/plist/lib/plist/generator.rb +224 -0
  51. data/lib/puppet/vendor/plist/lib/plist/parser.rb +225 -0
  52. data/lib/puppet/vendor/plist/test/assets/AlbumData.xml +203 -0
  53. data/lib/puppet/vendor/plist/test/assets/Cookies.plist +104 -0
  54. data/lib/puppet/vendor/plist/test/assets/commented.plist +9 -0
  55. data/lib/puppet/vendor/plist/test/assets/example_data.bin +0 -0
  56. data/lib/puppet/vendor/plist/test/assets/example_data.jpg +0 -0
  57. data/lib/puppet/vendor/plist/test/assets/example_data.plist +259 -0
  58. data/lib/puppet/vendor/plist/test/assets/test_data_elements.plist +24 -0
  59. data/lib/puppet/vendor/plist/test/assets/test_empty_key.plist +13 -0
  60. data/lib/puppet/vendor/plist/test/test_data_elements.rb +115 -0
  61. data/lib/puppet/vendor/plist/test/test_generator.rb +59 -0
  62. data/lib/puppet/vendor/plist/test/test_generator_basic_types.rb +58 -0
  63. data/lib/puppet/vendor/plist/test/test_generator_collections.rb +82 -0
  64. data/lib/puppet/vendor/plist/test/test_parser.rb +90 -0
  65. data/lib/puppet/version.rb +1 -1
  66. data/man/man5/puppet.conf.5 +5 -13
  67. data/man/man8/extlookup2hiera.8 +1 -1
  68. data/man/man8/puppet-agent.8 +1 -1
  69. data/man/man8/puppet-apply.8 +1 -1
  70. data/man/man8/puppet-ca.8 +1 -1
  71. data/man/man8/puppet-catalog.8 +1 -1
  72. data/man/man8/puppet-cert.8 +1 -1
  73. data/man/man8/puppet-certificate.8 +1 -1
  74. data/man/man8/puppet-certificate_request.8 +1 -1
  75. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  76. data/man/man8/puppet-config.8 +1 -1
  77. data/man/man8/puppet-describe.8 +1 -1
  78. data/man/man8/puppet-device.8 +1 -1
  79. data/man/man8/puppet-doc.8 +1 -1
  80. data/man/man8/puppet-epp.8 +1 -1
  81. data/man/man8/puppet-facts.8 +1 -1
  82. data/man/man8/puppet-file.8 +1 -1
  83. data/man/man8/puppet-filebucket.8 +1 -1
  84. data/man/man8/puppet-help.8 +1 -1
  85. data/man/man8/puppet-inspect.8 +1 -1
  86. data/man/man8/puppet-key.8 +1 -1
  87. data/man/man8/puppet-man.8 +1 -1
  88. data/man/man8/puppet-master.8 +1 -1
  89. data/man/man8/puppet-module.8 +1 -1
  90. data/man/man8/puppet-node.8 +1 -1
  91. data/man/man8/puppet-parser.8 +1 -1
  92. data/man/man8/puppet-plugin.8 +1 -1
  93. data/man/man8/puppet-report.8 +1 -1
  94. data/man/man8/puppet-resource.8 +1 -1
  95. data/man/man8/puppet-resource_type.8 +1 -1
  96. data/man/man8/puppet-status.8 +1 -1
  97. data/man/man8/puppet.8 +1 -1
  98. data/spec/fixtures/unit/functions/lookup/environments/production/lib/puppet/functions/environment/data.rb +8 -6
  99. data/spec/fixtures/unit/functions/lookup/environments/production/modules/abc/lib/puppet/functions/abc/data.rb +4 -4
  100. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/lib/puppet/bindings/bad_data/default.rb +9 -0
  101. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/lib/puppet/functions/bad_data/data.rb +6 -0
  102. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bad_data/manifests/init.pp +3 -0
  103. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bca/lib/puppet/bindings/bca/default.rb +9 -0
  104. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bca/lib/puppet/functions/bca/data.rb +9 -0
  105. data/spec/fixtures/unit/functions/lookup/environments/production/modules/bca/manifests/init.pp +2 -0
  106. data/spec/fixtures/unit/functions/lookup/environments/production/modules/no_provider/manifests/init.pp +2 -0
  107. data/spec/integration/provider/yumrepo_spec.rb +127 -0
  108. data/spec/unit/application/device_spec.rb +52 -14
  109. data/spec/unit/functions/lookup_spec.rb +95 -55
  110. data/spec/unit/parser/functions/create_resources_spec.rb +1 -1
  111. data/spec/unit/pops/binder/injector_spec.rb +0 -18
  112. data/spec/unit/pops/parser/lexer2_spec.rb +26 -16
  113. data/spec/unit/pops/parser/parse_heredoc_spec.rb +21 -0
  114. data/spec/unit/pops/validator/validator_spec.rb +2 -3
  115. data/spec/unit/provider/macauthorization_spec.rb +1 -1
  116. data/spec/unit/provider/package/gem_spec.rb +201 -139
  117. data/spec/unit/provider/package/puppet_gem_spec.rb +67 -0
  118. data/spec/unit/provider/user/directoryservice_spec.rb +1 -1
  119. data/spec/unit/util/network_device/config_spec.rb +6 -0
  120. data/spec/unit/util/run_mode_spec.rb +26 -26
  121. data/spec/unit/util/windows/registry_spec.rb +4 -3
  122. metadata +3016 -2980
@@ -63,7 +63,7 @@ describe 'function for dynamically creating resources' do
63
63
  it 'should fail to add non-existing type' do
64
64
  expect do
65
65
  @scope.function_create_resources(['create-resource-foo', { 'foo' => {} }])
66
- end.to raise_error(ArgumentError, /Invalid resource type create-resource-foo/)
66
+ end.to raise_error(/Invalid resource type create-resource-foo/)
67
67
  end
68
68
 
69
69
  it 'should be able to add edges' do
@@ -607,24 +607,6 @@ describe 'Injector' do
607
607
  expect { injector.lookup(scope, 'broken_family2')}.to raise_error(/:uniq/)
608
608
  end
609
609
 
610
- it "a higher priority contribution is selected when resolution is :priority" do
611
- hash_of_duck = type_factory.hash_of(duck_type)
612
- multibind_id = "ducks"
613
-
614
- bindings.multibind(multibind_id).type(hash_of_duck).name('donalds_nephews')
615
-
616
- mb1 = bindings.bind.in_multibind(multibind_id)
617
- pending 'priority based on layers not added, and priority on category removed'
618
- mb1.type(duck_type).name('nephew').to(InjectorSpecModule::NamedDuck, 'Huey')
619
-
620
- mb2 = bindings.bind.in_multibind(multibind_id)
621
- mb2.type(duck_type).name('nephew').to(InjectorSpecModule::NamedDuck, 'Dewey')
622
-
623
- binder.define_layers(layered_bindings)
624
-
625
- expect(injector(binder).lookup(scope, hash_of_duck, "donalds_nephews")['nephew'].name).to eq('Huey')
626
- end
627
-
628
610
  it "a higher priority contribution wins when resolution is :merge" do
629
611
  # THIS TEST MAY DEPEND ON HASH ORDER SINCE PRIORITY BASED ON CATEGORY IS REMOVED
630
612
  hash_of_data = type_factory.hash_of_data()
@@ -118,10 +118,8 @@ describe 'Lexer2' do
118
118
  end
119
119
 
120
120
  [ '_x::y', 'x::_y'].each do |string|
121
- it "should consider the bare word '#{string}' to be a bad NAME" do
122
- expect {
123
- tokens_scanned_from(string)
124
- }.to raise_error(/Illegal fully qualified name/)
121
+ it "should consider the bare word '#{string}' to be a WORD" do
122
+ expect(tokens_scanned_from(string)).to match_tokens2(:WORD)
125
123
  end
126
124
  end
127
125
 
@@ -209,21 +207,33 @@ describe 'Lexer2' do
209
207
  end
210
208
  end
211
209
 
212
- { '"a$x b"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>2 }],
213
- [:VARIABLE, 'x', {:line => 1, :pos=>3, :length=>2 }],
214
- [:DQPOST, ' b', {:line => 1, :pos=>5, :length=>3 }]],
210
+ { '"a$x b"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>2 }],
211
+ [:VARIABLE, 'x', {:line => 1, :pos=>3, :length=>2 }],
212
+ [:DQPOST, ' b', {:line => 1, :pos=>5, :length=>3 }]],
215
213
 
216
- '"a$x.b"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>2 }],
217
- [:VARIABLE, 'x', {:line => 1, :pos=>3, :length=>2 }],
218
- [:DQPOST, '.b', {:line => 1, :pos=>5, :length=>3 }]],
214
+ '"a$x.b"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>2 }],
215
+ [:VARIABLE, 'x', {:line => 1, :pos=>3, :length=>2 }],
216
+ [:DQPOST, '.b', {:line => 1, :pos=>5, :length=>3 }]],
219
217
 
220
- '"$x.b"' => [[:DQPRE, '', {:line => 1, :pos=>1, :length=>1 }],
221
- [:VARIABLE, 'x', {:line => 1, :pos=>2, :length=>2 }],
222
- [:DQPOST, '.b', {:line => 1, :pos=>4, :length=>3 }]],
218
+ '"$x.b"' => [[:DQPRE, '', {:line => 1, :pos=>1, :length=>1 }],
219
+ [:VARIABLE, 'x', {:line => 1, :pos=>2, :length=>2 }],
220
+ [:DQPOST, '.b', {:line => 1, :pos=>4, :length=>3 }]],
223
221
 
224
- '"a$x"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>2 }],
225
- [:VARIABLE, 'x', {:line => 1, :pos=>3, :length=>2 }],
226
- [:DQPOST, '', {:line => 1, :pos=>5, :length=>1 }]],
222
+ '"a$x"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>2 }],
223
+ [:VARIABLE, 'x', {:line => 1, :pos=>3, :length=>2 }],
224
+ [:DQPOST, '', {:line => 1, :pos=>5, :length=>1 }]],
225
+
226
+ '"a${x}"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>4 }],
227
+ [:VARIABLE, 'x', {:line => 1, :pos=>5, :length=>1 }],
228
+ [:DQPOST, '', {:line => 1, :pos=>7, :length=>1 }]],
229
+
230
+ '"a${_x}"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>4 }],
231
+ [:VARIABLE, '_x', {:line => 1, :pos=>5, :length=>2 }],
232
+ [:DQPOST, '', {:line => 1, :pos=>8, :length=>1 }]],
233
+
234
+ '"a${y::_x}"' => [[:DQPRE, 'a', {:line => 1, :pos=>1, :length=>4 }],
235
+ [:VARIABLE, 'y::_x', {:line => 1, :pos=>5, :length=>5 }],
236
+ [:DQPOST, '', {:line => 1, :pos=>11, :length=>1 }]],
227
237
  }.each do |source, expected|
228
238
  it "should lex an interpolated variable 'x' from #{source}" do
229
239
  expect(tokens_scanned_from(source)).to match_tokens2(*expected)
@@ -114,4 +114,25 @@ describe "egrammar parsing heredoc" do
114
114
  ].join("\n"))
115
115
  end
116
116
 
117
+ it 'parses multiple heredocs on the same line' do
118
+ src = <<-CODE
119
+ notice({ @(foo) => @(bar) })
120
+ hello
121
+ -foo
122
+ world
123
+ -bar
124
+ notice '!'
125
+ CODE
126
+ expect(dump(parse(src))).to eq([
127
+ '(block',
128
+ ' (invoke notice ({} ((@()',
129
+ ' (sublocated \' hello\')',
130
+ ' ) (@()',
131
+ ' (sublocated \' world\')',
132
+ ' ))))',
133
+ ' (invoke notice \'!\')',
134
+ ')'
135
+ ].join("\n"))
136
+ end
137
+
117
138
  end
@@ -19,9 +19,8 @@ describe "validating 4x" do
19
19
  end
20
20
 
21
21
  it 'should raise error for illegal names' do
22
- pending "validation was too strict, now too relaxed - validation missing"
23
- expect(validate(fqn('Aaa'))).to have_issue(Puppet::Pops::Issues::ILLEGAL_NAME)
24
- expect(validate(fqn('AAA'))).to have_issue(Puppet::Pops::Issues::ILLEGAL_NAME)
22
+ expect(validate(parse('class aaa::_bbb {}'))).to have_issue(Puppet::Pops::Issues::ILLEGAL_DEFINITION_NAME)
23
+ expect(validate(parse('class Aaa {}'))).to have_issue(Puppet::Pops::Issues::ILLEGAL_DEFINITION_NAME)
25
24
  end
26
25
 
27
26
  it 'should raise error for illegal variable names' do
@@ -6,7 +6,7 @@
6
6
  require 'spec_helper'
7
7
 
8
8
  require 'puppet'
9
- require 'facter/util/plist'
9
+ require 'plist'
10
10
 
11
11
  provider_class = Puppet::Type.type(:macauthorization).provider(:macauthorization)
12
12
 
@@ -3,184 +3,246 @@ require 'spec_helper'
3
3
 
4
4
  provider_class = Puppet::Type.type(:package).provider(:gem)
5
5
 
6
- describe provider_class do
7
- let(:resource) do
8
- Puppet::Type.type(:package).new(
9
- :name => 'myresource',
10
- :ensure => :installed
11
- )
12
- end
13
-
14
- let(:provider) do
15
- provider = provider_class.new
16
- provider.resource = resource
17
- provider
18
- end
19
-
20
- before :each do
21
- resource.provider = provider
22
- end
23
-
24
- describe "when installing" do
25
- it "should use the path to the gem" do
26
- provider_class.stubs(:command).with(:gemcmd).returns "/my/gem"
27
- provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns ""
28
- provider.install
6
+ context 'installing myresource' do
7
+ describe provider_class do
8
+ let(:resource) do
9
+ Puppet::Type.type(:package).new(
10
+ :name => 'myresource',
11
+ :ensure => :installed
12
+ )
29
13
  end
30
14
 
31
- it "should specify that the gem is being installed" do
32
- provider.expects(:execute).with { |args| args[1] == "install" }.returns ""
33
- provider.install
15
+ let(:provider) do
16
+ provider = provider_class.new
17
+ provider.resource = resource
18
+ provider
34
19
  end
35
20
 
36
- it "should specify that documentation should not be included" do
37
- provider.expects(:execute).with { |args| args[2] == "--no-rdoc" }.returns ""
38
- provider.install
21
+ before :each do
22
+ resource.provider = provider
39
23
  end
40
24
 
41
- it "should specify that RI should not be included" do
42
- provider.expects(:execute).with { |args| args[3] == "--no-ri" }.returns ""
43
- provider.install
44
- end
25
+ describe "when installing" do
26
+ it "should use the path to the gem" do
27
+ provider_class.stubs(:command).with(:gemcmd).returns "/my/gem"
28
+ provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns ""
29
+ provider.install
30
+ end
45
31
 
46
- it "should specify the package name" do
47
- provider.expects(:execute).with { |args| args[4] == "myresource" }.returns ""
48
- provider.install
49
- end
32
+ it "should specify that the gem is being installed" do
33
+ provider.expects(:execute).with { |args| args[1] == "install" }.returns ""
34
+ provider.install
35
+ end
50
36
 
51
- it "should not append install_options by default" do
52
- provider.expects(:execute).with { |args| args.length == 5 }.returns ""
53
- provider.install
54
- end
37
+ it "should specify that documentation should not be included" do
38
+ provider.expects(:execute).with { |args| args[2] == "--no-rdoc" }.returns ""
39
+ provider.install
40
+ end
55
41
 
56
- it "should allow setting an install_options parameter" do
57
- resource[:install_options] = [ '--force', {'--bindir' => '/usr/bin' } ]
58
- provider.expects(:execute).with { |args| args[5] == '--force' && args[6] == '--bindir=/usr/bin' }.returns ''
59
- provider.install
60
- end
42
+ it "should specify that RI should not be included" do
43
+ provider.expects(:execute).with { |args| args[3] == "--no-ri" }.returns ""
44
+ provider.install
45
+ end
61
46
 
62
- describe "when a source is specified" do
63
- describe "as a normal file" do
64
- it "should use the file name instead of the gem name" do
65
- resource[:source] = "/my/file"
66
- provider.expects(:execute).with { |args| args[2] == "/my/file" }.returns ""
67
- provider.install
68
- end
47
+ it "should specify the package name" do
48
+ provider.expects(:execute).with { |args| args[4] == "myresource" }.returns ""
49
+ provider.install
69
50
  end
70
- describe "as a file url" do
71
- it "should use the file name instead of the gem name" do
72
- resource[:source] = "file:///my/file"
73
- provider.expects(:execute).with { |args| args[2] == "/my/file" }.returns ""
74
- provider.install
75
- end
51
+
52
+ it "should not append install_options by default" do
53
+ provider.expects(:execute).with { |args| args.length == 5 }.returns ""
54
+ provider.install
76
55
  end
77
- describe "as a puppet url" do
78
- it "should fail" do
79
- resource[:source] = "puppet://my/file"
80
- expect { provider.install }.to raise_error(Puppet::Error)
81
- end
56
+
57
+ it "should allow setting an install_options parameter" do
58
+ resource[:install_options] = [ '--force', {'--bindir' => '/usr/bin' } ]
59
+ provider.expects(:execute).with { |args| args[5] == '--force' && args[6] == '--bindir=/usr/bin' }.returns ''
60
+ provider.install
82
61
  end
83
- describe "as a non-file and non-puppet url" do
84
- it "should treat the source as a gem repository" do
85
- resource[:source] = "http://host/my/file"
86
- provider.expects(:execute).with { |args| args[2..4] == ["--source", "http://host/my/file", "myresource"] }.returns ""
87
- provider.install
62
+
63
+ describe "when a source is specified" do
64
+ describe "as a normal file" do
65
+ it "should use the file name instead of the gem name" do
66
+ resource[:source] = "/my/file"
67
+ provider.expects(:execute).with { |args| args[2] == "/my/file" }.returns ""
68
+ provider.install
69
+ end
88
70
  end
89
- end
90
- describe "with an invalid uri" do
91
- it "should fail" do
92
- URI.expects(:parse).raises(ArgumentError)
93
- resource[:source] = "http:::::uppet:/:/my/file"
94
- expect { provider.install }.to raise_error(Puppet::Error)
71
+ describe "as a file url" do
72
+ it "should use the file name instead of the gem name" do
73
+ resource[:source] = "file:///my/file"
74
+ provider.expects(:execute).with { |args| args[2] == "/my/file" }.returns ""
75
+ provider.install
76
+ end
77
+ end
78
+ describe "as a puppet url" do
79
+ it "should fail" do
80
+ resource[:source] = "puppet://my/file"
81
+ expect { provider.install }.to raise_error(Puppet::Error)
82
+ end
83
+ end
84
+ describe "as a non-file and non-puppet url" do
85
+ it "should treat the source as a gem repository" do
86
+ resource[:source] = "http://host/my/file"
87
+ provider.expects(:execute).with { |args| args[2..4] == ["--source", "http://host/my/file", "myresource"] }.returns ""
88
+ provider.install
89
+ end
90
+ end
91
+ describe "with an invalid uri" do
92
+ it "should fail" do
93
+ URI.expects(:parse).raises(ArgumentError)
94
+ resource[:source] = "http:::::uppet:/:/my/file"
95
+ expect { provider.install }.to raise_error(Puppet::Error)
96
+ end
95
97
  end
96
98
  end
97
99
  end
98
- end
99
100
 
100
- describe "#latest" do
101
- it "should return a single value for 'latest'" do
102
- #gemlist is used for retrieving both local and remote version numbers, and there are cases
103
- # (particularly local) where it makes sense for it to return an array. That doesn't make
104
- # sense for '#latest', though.
105
- provider.class.expects(:gemlist).with({ :justme => 'myresource'}).returns({
101
+ describe "#latest" do
102
+ it "should return a single value for 'latest'" do
103
+ #gemlist is used for retrieving both local and remote version numbers, and there are cases
104
+ # (particularly local) where it makes sense for it to return an array. That doesn't make
105
+ # sense for '#latest', though.
106
+ provider.class.expects(:gemlist).with({ :justme => 'myresource'}).returns({
106
107
  :name => 'myresource',
107
108
  :ensure => ["3.0"],
108
109
  :provider => :gem,
109
- })
110
- expect(provider.latest).to eq("3.0")
111
- end
110
+ })
111
+ expect(provider.latest).to eq("3.0")
112
+ end
112
113
 
113
- it "should list from the specified source repository" do
114
- resource[:source] = "http://foo.bar.baz/gems"
115
- provider.class.expects(:gemlist).
116
- with({:justme => 'myresource', :source => "http://foo.bar.baz/gems"}).
117
- returns({
118
- :name => 'myresource',
119
- :ensure => ["3.0"],
120
- :provider => :gem,
114
+ it "should list from the specified source repository" do
115
+ resource[:source] = "http://foo.bar.baz/gems"
116
+ provider.class.expects(:gemlist).
117
+ with({:justme => 'myresource', :source => "http://foo.bar.baz/gems"}).
118
+ returns({
119
+ :name => 'myresource',
120
+ :ensure => ["3.0"],
121
+ :provider => :gem,
121
122
  })
122
- expect(provider.latest).to eq("3.0")
123
+ expect(provider.latest).to eq("3.0")
124
+ end
123
125
  end
124
- end
125
126
 
126
- describe "#instances" do
127
- before do
128
- provider_class.stubs(:command).with(:gemcmd).returns "/my/gem"
129
- end
127
+ describe "#instances" do
128
+ before do
129
+ provider_class.stubs(:command).with(:gemcmd).returns "/my/gem"
130
+ end
130
131
 
131
- it "should return an empty array when no gems installed" do
132
- provider_class.expects(:execute).with(%w{/my/gem list --local}).returns("\n")
133
- expect(provider_class.instances).to eq([])
134
- end
132
+ it "should return an empty array when no gems installed" do
133
+ provider_class.expects(:execute).with(%w{/my/gem list --local}).returns("\n")
134
+ expect(provider_class.instances).to eq([])
135
+ end
135
136
 
136
- it "should return ensure values as an array of installed versions" do
137
- provider_class.expects(:execute).with(%w{/my/gem list --local}).returns <<-HEREDOC.gsub(/ /, '')
137
+ it "should return ensure values as an array of installed versions" do
138
+ provider_class.expects(:execute).with(%w{/my/gem list --local}).returns <<-HEREDOC.gsub(/ /, '')
138
139
  systemu (1.2.0)
139
140
  vagrant (0.8.7, 0.6.9)
140
- HEREDOC
141
+ HEREDOC
141
142
 
142
- expect(provider_class.instances.map {|p| p.properties}).to eq([
143
- {:ensure => ["1.2.0"], :provider => :gem, :name => 'systemu'},
144
- {:ensure => ["0.8.7", "0.6.9"], :provider => :gem, :name => 'vagrant'}
145
- ])
146
- end
143
+ expect(provider_class.instances.map {|p| p.properties}).to eq([
144
+ {:ensure => ["1.2.0"], :provider => :gem, :name => 'systemu'},
145
+ {:ensure => ["0.8.7", "0.6.9"], :provider => :gem, :name => 'vagrant'}
146
+ ])
147
+ end
147
148
 
148
- it "should ignore platform specifications" do
149
- provider_class.expects(:execute).with(%w{/my/gem list --local}).returns <<-HEREDOC.gsub(/ /, '')
149
+ it "should ignore platform specifications" do
150
+ provider_class.expects(:execute).with(%w{/my/gem list --local}).returns <<-HEREDOC.gsub(/ /, '')
150
151
  systemu (1.2.0)
151
152
  nokogiri (1.6.1 ruby java x86-mingw32 x86-mswin32-60, 1.4.4.1 x86-mswin32)
152
- HEREDOC
153
+ HEREDOC
154
+
155
+ expect(provider_class.instances.map {|p| p.properties}).to eq([
156
+ {:ensure => ["1.2.0"], :provider => :gem, :name => 'systemu'},
157
+ {:ensure => ["1.6.1", "1.4.4.1"], :provider => :gem, :name => 'nokogiri'}
158
+ ])
159
+ end
153
160
 
154
- expect(provider_class.instances.map {|p| p.properties}).to eq([
155
- {:ensure => ["1.2.0"], :provider => :gem, :name => 'systemu'},
156
- {:ensure => ["1.6.1", "1.4.4.1"], :provider => :gem, :name => 'nokogiri'}
157
- ])
161
+ it "should not fail when an unmatched line is returned" do
162
+ provider_class.expects(:execute).with(%w{/my/gem list --local}).
163
+ returns(File.read(my_fixture('line-with-1.8.5-warning')))
164
+
165
+ expect(provider_class.instances.map {|p| p.properties}).
166
+ to eq([{:provider=>:gem, :ensure=>["0.3.2"], :name=>"columnize"},
167
+ {:provider=>:gem, :ensure=>["1.1.3"], :name=>"diff-lcs"},
168
+ {:provider=>:gem, :ensure=>["0.0.1"], :name=>"metaclass"},
169
+ {:provider=>:gem, :ensure=>["0.10.5"], :name=>"mocha"},
170
+ {:provider=>:gem, :ensure=>["0.8.7"], :name=>"rake"},
171
+ {:provider=>:gem, :ensure=>["2.9.0"], :name=>"rspec-core"},
172
+ {:provider=>:gem, :ensure=>["2.9.1"], :name=>"rspec-expectations"},
173
+ {:provider=>:gem, :ensure=>["2.9.0"], :name=>"rspec-mocks"},
174
+ {:provider=>:gem, :ensure=>["0.9.0"], :name=>"rubygems-bundler"},
175
+ {:provider=>:gem, :ensure=>["1.11.3.3"], :name=>"rvm"}])
176
+ end
158
177
  end
159
178
 
160
- it "should not fail when an unmatched line is returned" do
161
- provider_class.expects(:execute).with(%w{/my/gem list --local}).
162
- returns(File.read(my_fixture('line-with-1.8.5-warning')))
163
-
164
- expect(provider_class.instances.map {|p| p.properties}).
165
- to eq([{:provider=>:gem, :ensure=>["0.3.2"], :name=>"columnize"},
166
- {:provider=>:gem, :ensure=>["1.1.3"], :name=>"diff-lcs"},
167
- {:provider=>:gem, :ensure=>["0.0.1"], :name=>"metaclass"},
168
- {:provider=>:gem, :ensure=>["0.10.5"], :name=>"mocha"},
169
- {:provider=>:gem, :ensure=>["0.8.7"], :name=>"rake"},
170
- {:provider=>:gem, :ensure=>["2.9.0"], :name=>"rspec-core"},
171
- {:provider=>:gem, :ensure=>["2.9.1"], :name=>"rspec-expectations"},
172
- {:provider=>:gem, :ensure=>["2.9.0"], :name=>"rspec-mocks"},
173
- {:provider=>:gem, :ensure=>["0.9.0"], :name=>"rubygems-bundler"},
174
- {:provider=>:gem, :ensure=>["1.11.3.3"], :name=>"rvm"}])
179
+ describe "listing gems" do
180
+ describe "searching for a single package" do
181
+ it "searches for an exact match" do
182
+ provider_class.expects(:execute).with(includes('^bundler$')).returns(File.read(my_fixture('gem-list-single-package')))
183
+ expected = {:name => 'bundler', :ensure => %w[1.6.2], :provider => :gem}
184
+ expect(provider_class.gemlist({:justme => 'bundler'})).to eq(expected)
185
+ end
186
+ end
175
187
  end
176
188
  end
189
+ end
190
+
191
+ context 'uninstalling myresource' do
192
+ describe provider_class do
193
+ let(:resource) do
194
+ Puppet::Type.type(:package).new(
195
+ :name => 'myresource',
196
+ :ensure => :absent
197
+ )
198
+ end
199
+
200
+ let(:provider) do
201
+ provider = provider_class.new
202
+ provider.resource = resource
203
+ provider
204
+ end
205
+
206
+ before :each do
207
+ resource.provider = provider
208
+ end
209
+
210
+ describe "when uninstalling" do
211
+ it "should use the path to the gem" do
212
+ provider_class.stubs(:command).with(:gemcmd).returns "/my/gem"
213
+ provider.expects(:execute).with { |args| args[0] == "/my/gem" }.returns ""
214
+ provider.uninstall
215
+ end
216
+
217
+ it "should specify that the gem is being uninstalled" do
218
+ provider.expects(:execute).with { |args| args[1] == "uninstall" }.returns ""
219
+ provider.uninstall
220
+ end
221
+
222
+ it "should specify that the relevant executables should be removed without confirmation" do
223
+ provider.expects(:execute).with { |args| args[2] == "--executables" }.returns ""
224
+ provider.uninstall
225
+ end
226
+
227
+ it "should specify that all the matching versions should be removed" do
228
+ provider.expects(:execute).with { |args| args[3] == "--all" }.returns ""
229
+ provider.uninstall
230
+ end
231
+
232
+ it "should specify the package name" do
233
+ provider.expects(:execute).with { |args| args[4] == "myresource" }.returns ""
234
+ provider.uninstall
235
+ end
236
+
237
+ it "should not append uninstall_options by default" do
238
+ provider.expects(:execute).with { |args| args.length == 5 }.returns ""
239
+ provider.uninstall
240
+ end
177
241
 
178
- describe "listing gems" do
179
- describe "searching for a single package" do
180
- it "searches for an exact match" do
181
- provider_class.expects(:execute).with(includes('^bundler$')).returns(File.read(my_fixture('gem-list-single-package')))
182
- expected = {:name => 'bundler', :ensure => %w[1.6.2], :provider => :gem}
183
- expect(provider_class.gemlist({:justme => 'bundler'})).to eq(expected)
242
+ it "should allow setting an uninstall_options parameter" do
243
+ resource[:uninstall_options] = [ '--ignore-dependencies', {'--version' => '0.1.1' } ]
244
+ provider.expects(:execute).with { |args| args[5] == '--ignore-dependencies' && args[6] == '--version=0.1.1' }.returns ''
245
+ provider.uninstall
184
246
  end
185
247
  end
186
248
  end