chef 12.0.0.alpha.1-x86-mingw32 → 12.0.0.alpha.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/application.rb +8 -1
  3. data/lib/chef/application/apply.rb +4 -0
  4. data/lib/chef/application/client.rb +7 -7
  5. data/lib/chef/application/solo.rb +21 -13
  6. data/lib/chef/chef_fs/chef_fs_data_store.rb +60 -6
  7. data/lib/chef/chef_fs/config.rb +78 -4
  8. data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +2 -2
  9. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  10. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  11. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  13. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +76 -2
  14. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  15. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  16. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  17. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +30 -0
  18. data/lib/chef/chef_fs/data_handler/organization_invites_data_handler.rb +17 -0
  19. data/lib/chef/chef_fs/data_handler/organization_members_data_handler.rb +17 -0
  20. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  21. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +2 -1
  22. data/lib/chef/chef_fs/file_system.rb +0 -1
  23. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +1 -1
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +5 -1
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +73 -13
  27. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +44 -5
  28. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -1
  29. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -3
  30. data/lib/chef/chef_fs/file_system/org_entry.rb +34 -0
  31. data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +58 -0
  32. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +57 -0
  33. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +13 -4
  34. data/lib/chef/chef_fs/knife.rb +1 -1
  35. data/lib/chef/client.rb +8 -2
  36. data/lib/chef/config.rb +75 -57
  37. data/lib/chef/config_fetcher.rb +6 -21
  38. data/lib/chef/dsl/data_query.rb +48 -3
  39. data/lib/chef/dsl/platform_introspection.rb +42 -0
  40. data/lib/chef/dsl/reboot_pending.rb +6 -3
  41. data/lib/chef/encrypted_data_bag_item.rb +1 -1
  42. data/lib/chef/encrypted_data_bag_item/encryptor.rb +12 -0
  43. data/lib/chef/exceptions.rb +2 -0
  44. data/lib/chef/http/basic_client.rb +14 -0
  45. data/lib/chef/http/json_output.rb +7 -2
  46. data/lib/chef/knife.rb +36 -121
  47. data/lib/chef/knife/bootstrap.rb +68 -54
  48. data/lib/chef/knife/bootstrap/archlinux-gems.erb +6 -1
  49. data/lib/chef/knife/bootstrap/chef-aix.erb +5 -0
  50. data/lib/chef/knife/bootstrap/chef-full.erb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +70 -29
  52. data/lib/chef/knife/search.rb +56 -12
  53. data/lib/chef/knife/serve.rb +1 -1
  54. data/lib/chef/local_mode.rb +10 -4
  55. data/lib/chef/mixin/deep_merge.rb +6 -3
  56. data/lib/chef/mixin/shell_out.rb +33 -17
  57. data/lib/chef/null_logger.rb +72 -0
  58. data/lib/chef/platform.rb +2 -1
  59. data/lib/chef/platform/provider_mapping.rb +1 -1
  60. data/lib/chef/platform/rebooter.rb +54 -0
  61. data/lib/chef/provider/ifconfig.rb +15 -16
  62. data/lib/chef/provider/link.rb +1 -1
  63. data/lib/chef/provider/mount/mount.rb +1 -1
  64. data/lib/chef/provider/mount/solaris.rb +102 -64
  65. data/lib/chef/provider/package/aix.rb +4 -12
  66. data/lib/chef/provider/package/ips.rb +8 -12
  67. data/lib/chef/provider/package/macports.rb +4 -12
  68. data/lib/chef/provider/package/pacman.rb +2 -6
  69. data/lib/chef/provider/package/portage.rb +2 -6
  70. data/lib/chef/provider/package/rpm.rb +4 -12
  71. data/lib/chef/provider/package/solaris.rb +4 -12
  72. data/lib/chef/provider/reboot.rb +69 -0
  73. data/lib/chef/provider/service/debian.rb +10 -10
  74. data/lib/chef/provider/service/freebsd.rb +89 -73
  75. data/lib/chef/provider/service/gentoo.rb +2 -2
  76. data/lib/chef/provider/service/init.rb +6 -4
  77. data/lib/chef/provider/service/insserv.rb +3 -3
  78. data/lib/chef/provider/service/macosx.rb +2 -2
  79. data/lib/chef/provider/service/simple.rb +6 -4
  80. data/lib/chef/provider/service/solaris.rb +1 -1
  81. data/lib/chef/provider/service/systemd.rb +9 -9
  82. data/lib/chef/provider/service/upstart.rb +6 -6
  83. data/lib/chef/provider/subversion.rb +6 -6
  84. data/lib/chef/provider/user/dscl.rb +32 -28
  85. data/lib/chef/provider/user/windows.rb +6 -6
  86. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  87. data/lib/chef/providers.rb +1 -0
  88. data/lib/chef/recipe.rb +0 -1
  89. data/lib/chef/resource.rb +3 -5
  90. data/lib/chef/resource/mount.rb +9 -0
  91. data/lib/chef/resource/reboot.rb +48 -0
  92. data/lib/chef/resources.rb +1 -0
  93. data/lib/chef/run_context.rb +25 -0
  94. data/lib/chef/search/query.rb +122 -14
  95. data/lib/chef/util/path_helper.rb +54 -6
  96. data/lib/chef/util/windows/net_user.rb +4 -1
  97. data/lib/chef/version.rb +1 -1
  98. data/lib/chef/win32/api/file.rb +1 -5
  99. data/lib/chef/win32/api/net.rb +1 -0
  100. data/lib/chef/workstation_config_loader.rb +177 -0
  101. data/spec/functional/http/simple_spec.rb +57 -1
  102. data/spec/functional/mixin/shell_out_spec.rb +2 -2
  103. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +51 -0
  104. data/spec/functional/rebooter_spec.rb +105 -0
  105. data/spec/functional/resource/deploy_revision_spec.rb +0 -4
  106. data/spec/functional/resource/file_spec.rb +26 -3
  107. data/spec/functional/resource/group_spec.rb +5 -3
  108. data/spec/functional/resource/link_spec.rb +16 -16
  109. data/spec/functional/resource/reboot_spec.rb +103 -0
  110. data/spec/integration/client/client_spec.rb +4 -8
  111. data/spec/integration/client/ipv6_spec.rb +1 -1
  112. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -2
  113. data/spec/integration/knife/delete_spec.rb +39 -0
  114. data/spec/integration/knife/deps_spec.rb +30 -20
  115. data/spec/integration/knife/download_spec.rb +77 -1
  116. data/spec/integration/knife/list_spec.rb +221 -0
  117. data/spec/integration/knife/raw_spec.rb +1 -1
  118. data/spec/integration/knife/show_spec.rb +2 -2
  119. data/spec/integration/knife/upload_spec.rb +154 -1
  120. data/spec/support/pedant/run_pedant.rb +0 -1
  121. data/spec/support/shared/functional/http.rb +8 -1
  122. data/spec/support/shared/integration/integration_helper.rb +11 -19
  123. data/spec/support/shared/unit/platform_introspector.rb +22 -0
  124. data/spec/unit/application/apply.rb +11 -1
  125. data/spec/unit/application/solo_spec.rb +19 -3
  126. data/spec/unit/chef_fs/config_spec.rb +58 -0
  127. data/spec/unit/config_fetcher_spec.rb +1 -3
  128. data/spec/unit/config_spec.rb +247 -220
  129. data/spec/unit/dsl/data_query_spec.rb +165 -23
  130. data/spec/unit/dsl/reboot_pending_spec.rb +1 -7
  131. data/spec/unit/encrypted_data_bag_item_spec.rb +1 -1
  132. data/spec/unit/knife/bootstrap_spec.rb +354 -182
  133. data/spec/unit/knife/core/bootstrap_context_spec.rb +67 -30
  134. data/spec/unit/knife_spec.rb +3 -30
  135. data/spec/unit/mixin/deep_merge_spec.rb +14 -0
  136. data/spec/unit/mixin/shell_out_spec.rb +134 -64
  137. data/spec/unit/provider/ifconfig/debian_spec.rb +19 -9
  138. data/spec/unit/provider/ifconfig/redhat_spec.rb +16 -14
  139. data/spec/unit/provider/ifconfig_spec.rb +3 -3
  140. data/spec/unit/provider/link_spec.rb +5 -5
  141. data/spec/unit/provider/mount/mount_spec.rb +10 -1
  142. data/spec/unit/provider/mount/solaris_spec.rb +185 -11
  143. data/spec/unit/provider/package/aix_spec.rb +5 -17
  144. data/spec/unit/provider/package/ips_spec.rb +8 -21
  145. data/spec/unit/provider/package/macports_spec.rb +12 -12
  146. data/spec/unit/provider/package/pacman_spec.rb +4 -12
  147. data/spec/unit/provider/package/portage_spec.rb +5 -15
  148. data/spec/unit/provider/package/rpm_spec.rb +7 -22
  149. data/spec/unit/provider/package/solaris_spec.rb +5 -16
  150. data/spec/unit/provider/service/arch_service_spec.rb +8 -14
  151. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  152. data/spec/unit/provider/service/freebsd_service_spec.rb +457 -225
  153. data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
  154. data/spec/unit/provider/service/init_service_spec.rb +10 -10
  155. data/spec/unit/provider/service/insserv_service_spec.rb +3 -4
  156. data/spec/unit/provider/service/invokercd_service_spec.rb +8 -9
  157. data/spec/unit/provider/service/macosx_spec.rb +5 -5
  158. data/spec/unit/provider/service/simple_service_spec.rb +4 -6
  159. data/spec/unit/provider/service/solaris_smf_service_spec.rb +1 -3
  160. data/spec/unit/provider/service/systemd_service_spec.rb +20 -20
  161. data/spec/unit/provider/service/upstart_service_spec.rb +15 -17
  162. data/spec/unit/provider/subversion_spec.rb +5 -6
  163. data/spec/unit/provider/user/dscl_spec.rb +2 -1
  164. data/spec/unit/provider/user/windows_spec.rb +7 -0
  165. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  166. data/spec/unit/resource/mount_spec.rb +9 -0
  167. data/spec/unit/resource_spec.rb +0 -4
  168. data/spec/unit/rest_spec.rb +1 -1
  169. data/spec/unit/run_context_spec.rb +15 -0
  170. data/spec/unit/search/query_spec.rb +196 -40
  171. data/spec/unit/util/path_helper_spec.rb +111 -28
  172. data/spec/unit/workstation_config_loader_spec.rb +283 -0
  173. metadata +36 -20
  174. data/lib/chef/knife/bootstrap/centos5-gems.erb +0 -62
  175. data/lib/chef/knife/bootstrap/fedora13-gems.erb +0 -44
  176. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +0 -53
  177. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +0 -48
  178. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +0 -46
  179. data/spec/support/shared/integration/chef_zero_support.rb +0 -130
  180. data/spec/unit/knife/config_file_selection_spec.rb +0 -135
@@ -301,7 +301,7 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop
301
301
 
302
302
  def expect_commands(provider, commands)
303
303
  commands.each do |command|
304
- provider.should_receive(:run_command).with({:command => command})
304
+ provider.should_receive(:shell_out!).with(command)
305
305
  end
306
306
  end
307
307
 
@@ -18,313 +18,531 @@
18
18
 
19
19
  require 'spec_helper'
20
20
 
21
+ class Chef::Provider::Service::Freebsd
22
+ public :service_enable_variable_name
23
+ public :determine_enabled_status!
24
+ public :determine_current_status!
25
+ end
26
+
21
27
  describe Chef::Provider::Service::Freebsd do
28
+ let(:node) do
29
+ node = Chef::Node.new
30
+ node.automatic_attrs[:command] = {:ps => "ps -ax"}
31
+ node
32
+ end
33
+
34
+ let(:new_resource) do
35
+ new_resource = Chef::Resource::Service.new("apache22")
36
+ new_resource.pattern("httpd")
37
+ new_resource.supports({:status => false})
38
+ new_resource
39
+ end
40
+
41
+ let(:current_resource) do
42
+ current_resource = Chef::Resource::Service.new("apache22")
43
+ current_resource
44
+ end
45
+
46
+ let(:provider) do
47
+ events = Chef::EventDispatch::Dispatcher.new
48
+ run_context = Chef::RunContext.new(node, {}, events)
49
+ provider = Chef::Provider::Service::Freebsd.new(new_resource,run_context)
50
+ provider.action = :start
51
+ provider
52
+ end
53
+
22
54
  before do
23
- @node = Chef::Node.new
24
- @node.automatic_attrs[:command] = {:ps => "ps -ax"}
25
- @events = Chef::EventDispatch::Dispatcher.new
26
- @run_context = Chef::RunContext.new(@node, {}, @events)
55
+ allow(Chef::Resource::Service).to receive(:new).and_return(current_resource)
56
+ end
27
57
 
28
- @new_resource = Chef::Resource::Service.new("apache22")
29
- @new_resource.pattern("httpd")
30
- @new_resource.supports({:status => false})
58
+ def stub_etc_rcd_script
59
+ allow(::File).to receive(:exist?).and_return(false)
60
+ expect(::File).to receive(:exist?).with("/etc/rc.d/#{new_resource.service_name}").and_return(true)
61
+ end
31
62
 
32
- @current_resource = Chef::Resource::Service.new("apache22")
63
+ def stub_usr_local_rcd_script
64
+ allow(::File).to receive(:exist?).and_return(false)
65
+ expect(::File).to receive(:exist?).with("/usr/local/etc/rc.d/#{new_resource.service_name}").and_return(true)
66
+ end
33
67
 
34
- @provider = Chef::Provider::Service::Freebsd.new(@new_resource,@run_context)
35
- @provider.action = :start
36
- @init_command = "/usr/local/etc/rc.d/apache22"
37
- Chef::Resource::Service.stub(:new).and_return(@current_resource)
68
+ def run_load_current_resource
69
+ stub_usr_local_rcd_script
70
+ provider.load_current_resource
38
71
  end
39
72
 
40
- describe "load_current_resource" do
41
- before(:each) do
42
- @stdout = StringIO.new(<<-PS_SAMPLE)
43
- 413 ?? Ss 0:02.51 /usr/sbin/syslogd -s
44
- 539 ?? Is 0:00.14 /usr/sbin/sshd
45
- 545 ?? Ss 0:17.53 sendmail: accepting connections (sendmail)
46
- PS_SAMPLE
47
- @status = double(:stdout => @stdout, :exitstatus => 0)
48
- @provider.stub(:shell_out!).with(@node[:command][:ps]).and_return(@status)
49
-
50
- ::File.stub(:exists?).and_return(false)
51
- ::File.stub(:exists?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true)
52
- @lines = double("lines")
53
- @lines.stub(:each).and_yield("sshd_enable=\"YES\"").
54
- and_yield("#{@new_resource.name}_enable=\"YES\"")
55
- ::File.stub(:open).and_return(@lines)
56
-
57
- @rc_with_name = StringIO.new(<<-RC_SAMPLE)
58
- name="apache22"
59
- rcvar=`set_rcvar`
60
- RC_SAMPLE
61
- ::File.stub(:open).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(@rc_with_name)
62
- @provider.stub(:service_enable_variable_name).and_return nil
73
+ describe Chef::Provider::Service::Freebsd, "initialize" do
74
+ it "should default enabled_state_found to false" do
75
+ expect(provider.enabled_state_found).to be false
76
+ end
63
77
 
78
+ it "should find /usr/local/etc/rc.d init scripts" do
79
+ stub_usr_local_rcd_script
80
+ expect(provider.init_command).to eql "/usr/local/etc/rc.d/apache22"
64
81
  end
65
82
 
66
- it "should create a current resource with the name of the new resource" do
67
- Chef::Resource::Service.should_receive(:new).and_return(@current_resource)
68
- @provider.load_current_resource
83
+ it "should find /etc/rc.d init scripts" do
84
+ stub_etc_rcd_script
85
+ expect(provider.init_command).to eql "/etc/rc.d/apache22"
69
86
  end
70
87
 
71
- it "should set the current resources service name to the new resources service name" do
72
- @provider.load_current_resource
73
- @current_resource.service_name.should == @new_resource.service_name
88
+ it "should set init_command to nil if it can't find anything" do
89
+ allow(::File).to receive(:exist?).and_return(false)
90
+ expect(provider.init_command).to be nil
74
91
  end
92
+ end
75
93
 
76
- it "should not raise an exception if the rcscript have a name variable" do
77
- @provider.load_current_resource
78
- lambda { @provider.service_enable_variable_name }.should_not raise_error
94
+ describe Chef::Provider::Service::Freebsd, "determine_current_status!" do
95
+ before do
96
+ stub_usr_local_rcd_script
97
+ provider.current_resource = current_resource
98
+ current_resource.service_name(new_resource.service_name)
79
99
  end
80
100
 
81
- describe "when the service supports status" do
101
+ context "when a status command has been specified" do
102
+ let(:status) { double(:stdout => "", :exitstatus => 0) }
103
+
104
+ before do
105
+ new_resource.status_command("/bin/chefhasmonkeypants status")
106
+ end
107
+
108
+ it "should run the services status command if one has been specified" do
109
+ expect(provider).to receive(:shell_out).with("/bin/chefhasmonkeypants status").and_return(status)
110
+ provider.determine_current_status!
111
+ end
112
+ end
113
+
114
+ context "when the service supports status" do
115
+ let(:status) { double(:stdout => "", :exitstatus => 0) }
116
+
82
117
  before do
83
- @new_resource.supports({:status => true})
118
+ new_resource.supports({:status => true})
84
119
  end
85
120
 
86
121
  it "should run '/etc/init.d/service_name status'" do
87
- @provider.should_receive(:shell_out).with("/usr/local/etc/rc.d/#{@current_resource.service_name} status").and_return(@status)
88
- @provider.load_current_resource
122
+ expect(provider).to receive(:shell_out).with("/usr/local/etc/rc.d/#{new_resource.service_name} status").and_return(status)
123
+ provider.determine_current_status!
89
124
  end
90
125
 
91
126
  it "should set running to true if the status command returns 0" do
92
- @provider.should_receive(:shell_out).with("/usr/local/etc/rc.d/#{@current_resource.service_name} status").and_return(@status)
93
- @current_resource.should_receive(:running).with(true)
94
- @provider.load_current_resource
127
+ expect(provider).to receive(:shell_out).with("/usr/local/etc/rc.d/#{new_resource.service_name} status").and_return(status)
128
+ provider.determine_current_status!
129
+ expect(current_resource.running).to be true
95
130
  end
96
131
 
97
132
  it "should set running to false if the status command returns anything except 0" do
98
- @provider.should_receive(:shell_out).with("/usr/local/etc/rc.d/#{@current_resource.service_name} status").and_raise(Mixlib::ShellOut::ShellCommandFailed)
99
- @current_resource.should_receive(:running).with(false)
100
- @provider.load_current_resource
101
- # @provider.current_resource.running.should be_false
133
+ expect(provider).to receive(:shell_out).with("/usr/local/etc/rc.d/#{new_resource.service_name} status").and_raise(Mixlib::ShellOut::ShellCommandFailed)
134
+ provider.determine_current_status!
135
+ expect(current_resource.running).to be false
102
136
  end
103
137
  end
104
138
 
105
- describe "when a status command has been specified" do
139
+ context "when we have a 'ps' attribute" do
140
+ let(:stdout) do
141
+ StringIO.new(<<-PS_SAMPLE)
142
+ 413 ?? Ss 0:02.51 /usr/sbin/syslogd -s
143
+ 539 ?? Is 0:00.14 /usr/sbin/sshd
144
+ 545 ?? Ss 0:17.53 sendmail: accepting connections (sendmail)
145
+ PS_SAMPLE
146
+ end
147
+ let(:status) { double(:stdout => stdout, :exitstatus => 0) }
148
+
106
149
  before do
107
- @new_resource.status_command("/bin/chefhasmonkeypants status")
150
+ node.automatic_attrs[:command] = {:ps => "ps -ax"}
108
151
  end
109
152
 
110
- it "should run the services status command if one has been specified" do
111
- @provider.should_receive(:shell_out).with("/bin/chefhasmonkeypants status").and_return(@status)
112
- @provider.load_current_resource
153
+ it "should shell_out! the node's ps command" do
154
+ expect(provider).to receive(:shell_out!).with(node[:command][:ps]).and_return(status)
155
+ provider.determine_current_status!
156
+ end
157
+
158
+ it "should read stdout of the ps command" do
159
+ allow(provider).to receive(:shell_out!).and_return(status)
160
+ expect(stdout).to receive(:each_line).and_return(true)
161
+ provider.determine_current_status!
113
162
  end
114
163
 
164
+ context "when the regex matches the output" do
165
+ let(:stdout) do
166
+ StringIO.new(<<-PS_SAMPLE)
167
+ 555 ?? Ss 0:05.16 /usr/sbin/cron -s
168
+ 9881 ?? Ss 0:06.67 /usr/local/sbin/httpd -DNOHTTPACCEPT
169
+ PS_SAMPLE
170
+ end
171
+
172
+ it "should set running to true" do
173
+ allow(provider).to receive(:shell_out!).and_return(status)
174
+ provider.determine_current_status!
175
+ expect(current_resource.running).to be_true
176
+ end
177
+ end
178
+
179
+ it "should set running to false if the regex doesn't match" do
180
+ allow(provider).to receive(:shell_out!).and_return(status)
181
+ provider.determine_current_status!
182
+ expect(current_resource.running).to be_false
183
+ end
184
+
185
+ it "should set running to nil if ps fails" do
186
+ allow(provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed)
187
+ provider.determine_current_status!
188
+ expect(current_resource.running).to be_nil
189
+ expect(provider.status_load_success).to be_nil
190
+ end
191
+
192
+ context "when ps command is nil" do
193
+ before do
194
+ node.automatic_attrs[:command] = {:ps => nil}
195
+ end
196
+
197
+ it "should set running to nil" do
198
+ pending "superclass raises no conversion of nil to string which seems broken"
199
+ provider.determine_current_status!
200
+ expect(current_resource.running).to be_nil
201
+ end
202
+ end
203
+
204
+ context "when ps is empty string" do
205
+ before do
206
+ node.automatic_attrs[:command] = {:ps => ""}
207
+ end
208
+
209
+ it "should set running to nil" do
210
+ provider.determine_current_status!
211
+ expect(current_resource.running).to be_nil
212
+ end
213
+ end
115
214
  end
215
+ end
116
216
 
117
- it "should raise error if the node has a nil ps attribute and no other means to get status" do
118
- @node.automatic_attrs[:command] = {:ps => nil}
119
- @provider.define_resource_requirements
120
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
217
+ describe Chef::Provider::Service::Freebsd, "determine_enabled_status!" do
218
+ before do
219
+ stub_usr_local_rcd_script
220
+ provider.current_resource = current_resource
221
+ current_resource.service_name(new_resource.service_name)
222
+
223
+ allow(provider).to receive(:service_enable_variable_name).and_return("#{new_resource.service_name}_enable")
121
224
  end
122
225
 
123
- it "should raise error if the node has an empty ps attribute and no other means to get status" do
124
- @node.automatic_attrs[:command] = {:ps => ""}
125
- @provider.define_resource_requirements
126
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
226
+ context "when /etc/rc.conf does not exist" do
227
+ before do
228
+ expect(::File).to receive(:exist?).with("/etc/rc.conf").and_return(false)
229
+ end
230
+
231
+ it "sets enabled to false" do
232
+ provider.determine_enabled_status!
233
+ expect(current_resource.enabled).to be false
234
+ end
127
235
  end
128
236
 
129
- describe "when executing assertions" do
130
- it "should verify that /etc/rc.conf exists" do
131
- ::File.should_receive(:exists?).with("/etc/rc.conf")
132
- @provider.stub(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable")
133
- @provider.load_current_resource
237
+ context "when /etc/rc.conf does exist" do
238
+ before do
239
+ expect(::File).to receive(:exist?).with("/etc/rc.conf").and_return(true)
240
+ expect(provider).to receive(:read_rc_conf).and_return(lines)
134
241
  end
135
242
 
136
- context "and the init script is not found" do
137
- [ "start", "reload", "restart", "enable" ].each do |action|
138
- it "should raise an exception when the action is #{action}" do
139
- ::File.stub(:exists?).and_return(false)
140
- @provider.load_current_resource
141
- @provider.define_resource_requirements
142
- @provider.instance_variable_get("@rcd_script_found").should be_false
143
- @provider.action = action
144
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
243
+ %w{YES Yes yes yEs YeS}.each do |setting|
244
+ context "when the enable variable is set to #{setting}" do
245
+ let(:lines) { [ %Q{#{new_resource.service_name}_enable="#{setting}"} ] }
246
+ it "sets enabled to true" do
247
+ provider.determine_enabled_status!
248
+ expect(current_resource.enabled).to be true
145
249
  end
146
250
  end
251
+ end
147
252
 
148
- [ "stop", "disable" ].each do |action|
149
- it "should not raise an error when the action is #{action}" do
150
- @provider.action = action
151
- lambda { @provider.process_resource_requirements }.should_not raise_error
253
+ %w{No NO no nO None NONE none nOnE}.each do |setting|
254
+ context "when the enable variable is set to #{setting}" do
255
+ let(:lines) { [ %Q{#{new_resource.service_name}_enable="#{setting}"} ] }
256
+ it "sets enabled to false" do
257
+ provider.determine_enabled_status!
258
+ expect(current_resource.enabled).to be false
152
259
  end
153
260
  end
154
261
  end
155
262
 
156
- it "update state when current resource enabled state could not be determined" do
157
- ::File.should_receive(:exists?).with("/etc/rc.conf").and_return false
158
- @provider.load_current_resource
159
- @provider.instance_variable_get("@enabled_state_found").should be_false
263
+ context "when the enable variable is garbage" do
264
+ let(:lines) { [ %Q{#{new_resource.service_name}_enable="alskdjflasdkjflakdfj"} ] }
265
+ it "sets enabled to false" do
266
+ provider.determine_enabled_status!
267
+ expect(current_resource.enabled).to be false
268
+ end
160
269
  end
161
270
 
162
- it "update state when current resource enabled state could be determined" do
163
- ::File.stub(:exist?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true)
164
- ::File.should_receive(:exists?).with("/etc/rc.conf").and_return true
165
- @provider.load_current_resource
166
- @provider.instance_variable_get("@enabled_state_found").should be_false
167
- @provider.instance_variable_get("@rcd_script_found").should be_true
168
- @provider.define_resource_requirements
169
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service,
170
- "Could not find the service name in /usr/local/etc/rc.d/#{@current_resource.service_name} and rcvar")
271
+ context "when the enable variable partial matches (left) some other service and we are disabled" do
272
+ let(:lines) { [
273
+ %Q{thing_#{new_resource.service_name}_enable="YES"},
274
+ %Q{#{new_resource.service_name}_enable="NO"},
275
+ ] }
276
+ it "sets enabled based on the exact match (false)" do
277
+ provider.determine_enabled_status!
278
+ expect(current_resource.enabled).to be false
279
+ end
171
280
  end
172
281
 
173
- it "should throw an exception if service line is missing from rc.d script" do
174
- pending "not implemented" do
175
- false.should be_true
176
- end
282
+ context "when the enable variable partial matches (right) some other service and we are disabled" do
283
+ let(:lines) { [
284
+ %Q{#{new_resource.service_name}_thing_enable="YES"},
285
+ %Q{#{new_resource.service_name}_enable="NO"},
286
+ ] }
287
+ it "sets enabled based on the exact match (false)" do
288
+ provider.determine_enabled_status!
289
+ expect(current_resource.enabled).to be false
290
+ end
291
+ end
292
+
293
+ context "when the enable variable partial matches (left) some other disabled service and we are enabled" do
294
+ let(:lines) { [
295
+ %Q{thing_#{new_resource.service_name}_enable="NO"},
296
+ %Q{#{new_resource.service_name}_enable="YES"},
297
+ ] }
298
+ it "sets enabled based on the exact match (true)" do
299
+ provider.determine_enabled_status!
300
+ expect(current_resource.enabled).to be true
301
+ end
177
302
  end
178
303
 
304
+ context "when the enable variable partial matches (right) some other disabled service and we are enabled" do
305
+ let(:lines) { [
306
+ %Q{#{new_resource.service_name}_thing_enable="NO"},
307
+ %Q{#{new_resource.service_name}_enable="YES"},
308
+ ] }
309
+ it "sets enabled based on the exact match (true)" do
310
+ provider.determine_enabled_status!
311
+ expect(current_resource.enabled).to be true
312
+ end
313
+ end
314
+
315
+ context "when the enable variable only partial matches (left) some other enabled service" do
316
+ let(:lines) { [ %Q{thing_#{new_resource.service_name}_enable="YES"} ] }
317
+ it "sets enabled to false" do
318
+ provider.determine_enabled_status!
319
+ expect(current_resource.enabled).to be false
320
+ end
321
+ end
322
+
323
+ context "when the enable variable only partial matches (right) some other enabled service" do
324
+ let(:lines) { [ %Q{#{new_resource.service_name}_thing_enable="YES"} ] }
325
+ it "sets enabled to false" do
326
+ provider.determine_enabled_status!
327
+ expect(current_resource.enabled).to be false
328
+ end
329
+ end
330
+
331
+ context "when nothing matches" do
332
+ let(:lines) { [] }
333
+ it "sets enabled to true" do
334
+ provider.determine_enabled_status!
335
+ expect(current_resource.enabled).to be false
336
+ end
337
+ end
179
338
  end
339
+ end
180
340
 
181
- describe "when we have a 'ps' attribute" do
182
- before do
183
- @node.automatic_attrs[:command] = {:ps => "ps -ax"}
341
+ describe Chef::Provider::Service::Freebsd, "service_enable_variable_name" do
342
+ before do
343
+ stub_usr_local_rcd_script
344
+ provider.current_resource = current_resource
345
+ current_resource.service_name(new_resource.service_name)
346
+
347
+ expect(::File).to receive(:open).with("/usr/local/etc/rc.d/#{new_resource.service_name}").and_yield(rcscript)
348
+ end
349
+
350
+ context "when the rc script has a 'name' variable" do
351
+ let(:rcscript) do
352
+ StringIO.new(<<-EOF)
353
+ name="#{new_resource.service_name}"
354
+ rcvar=`set_rcvar`
355
+ EOF
184
356
  end
185
357
 
186
- it "should shell_out! the node's ps command" do
187
- @provider.should_receive(:shell_out!).with(@node[:command][:ps]).and_return(@status)
188
- @provider.load_current_resource
358
+ it "should not raise an exception if the rcscript have a name variable" do
359
+ expect { provider.service_enable_variable_name }.not_to raise_error
189
360
  end
190
361
 
191
- it "should read stdout of the ps command" do
192
- @provider.stub(:shell_out!).and_return(@status)
193
- @stdout.should_receive(:each_line).and_return(true)
194
- @provider.load_current_resource
362
+ it "should not run rcvar" do
363
+ expect(provider).not_to receive(:shell_out!)
364
+ provider.service_enable_variable_name
195
365
  end
196
366
 
197
- it "should set running to true if the regex matches the output" do
198
- @stdout.stub(:each_line).and_yield("555 ?? Ss 0:05.16 /usr/sbin/cron -s").
199
- and_yield(" 9881 ?? Ss 0:06.67 /usr/local/sbin/httpd -DNOHTTPACCEPT")
200
- @provider.load_current_resource
201
- @current_resource.running.should be_true
367
+ it "should return the enable variable determined from the rcscript name" do
368
+ expect(provider.service_enable_variable_name).to eql "#{new_resource.service_name}_enable"
202
369
  end
370
+ end
203
371
 
204
- it "should set running to false if the regex doesn't match" do
205
- @provider.stub(:shell_out!).and_return(@status)
206
- @provider.load_current_resource
207
- @current_resource.running.should be_false
372
+ describe "when the rcscript does not have a name variable" do
373
+ let(:rcscript) do
374
+ StringIO.new <<-EOF
375
+ rcvar=`set_rcvar`
376
+ EOF
377
+ end
378
+
379
+ before do
380
+ status = double(:stdout => rcvar_stdout, :exitstatus => 0)
381
+ allow(provider).to receive(:shell_out!).with("/usr/local/etc/rc.d/#{new_resource.service_name} rcvar").and_return(status)
382
+ end
383
+
384
+ describe "when rcvar returns foobar_enable" do
385
+ let(:rcvar_stdout) do
386
+ rcvar_stdout = <<-EOF
387
+ # apache22
388
+ #
389
+ # #{new_resource.service_name}_enable="YES"
390
+ # (default: "")
391
+ EOF
392
+ end
393
+
394
+ it "should get the service name from rcvar if the rcscript does not have a name variable" do
395
+ expect(provider.service_enable_variable_name).to eq("#{new_resource.service_name}_enable")
396
+ end
397
+
398
+ it "should not raise an exception if the rcscript does not have a name variable" do
399
+ expect { provider.service_enable_variable_name }.not_to raise_error
400
+ end
208
401
  end
209
402
 
210
- it "should raise an exception if ps fails" do
211
- @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed)
212
- @provider.load_current_resource
213
- @provider.define_resource_requirements
214
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
403
+ describe "when rcvar does not return foobar_enable" do
404
+ let(:rcvar_stdout) do
405
+ rcvar_stdout = <<-EOF
406
+ # service_with_noname
407
+ #
408
+ EOF
409
+ end
410
+
411
+ it "should return nil" do
412
+ expect(provider.service_enable_variable_name).to be nil
413
+ end
215
414
  end
216
415
  end
416
+ end
417
+
418
+ describe Chef::Provider::Service::Freebsd, "load_current_resource" do
419
+ before(:each) do
420
+ stub_usr_local_rcd_script
421
+ expect(provider).to receive(:determine_current_status!)
422
+ current_resource.running(false)
423
+ allow(provider).to receive(:service_enable_variable_name).and_return "#{new_resource.service_name}_enable"
424
+ end
425
+
426
+ it "should create a current resource with the name of the new resource" do
427
+ expect(Chef::Resource::Service).to receive(:new).and_return(current_resource)
428
+ provider.load_current_resource
429
+ end
430
+
431
+ it "should set the current resources service name to the new resources service name" do
432
+ provider.load_current_resource
433
+ expect(current_resource.service_name).to eq(new_resource.service_name)
434
+ end
217
435
 
218
436
  it "should return the current resource" do
219
- @provider.load_current_resource.should eql(@current_resource)
437
+ expect(provider.load_current_resource).to eql(current_resource)
220
438
  end
221
439
 
222
- describe "when starting the service" do
440
+ end
441
+
442
+ context "when testing actions" do
443
+ before(:each) do
444
+ stub_usr_local_rcd_script
445
+ expect(provider).to receive(:determine_current_status!)
446
+ current_resource.running(false)
447
+ expect(provider).to receive(:determine_enabled_status!)
448
+ current_resource.enabled(false)
449
+ provider.load_current_resource
450
+ end
451
+
452
+ describe Chef::Provider::Service::Freebsd, "start_service" do
223
453
  it "should call the start command if one is specified" do
224
- @new_resource.start_command("/etc/rc.d/chef startyousillysally")
225
- @provider.should_receive(:shell_out!).with("/etc/rc.d/chef startyousillysally")
226
- @provider.load_current_resource
227
- @provider.start_service()
454
+ new_resource.start_command("/etc/rc.d/chef startyousillysally")
455
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/chef startyousillysally")
456
+ provider.start_service()
228
457
  end
229
458
 
230
459
  it "should call '/usr/local/etc/rc.d/service_name faststart' if no start command is specified" do
231
- @provider.should_receive(:shell_out!).with("/usr/local/etc/rc.d/#{@new_resource.service_name} faststart")
232
- @provider.load_current_resource
233
- @provider.start_service()
460
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/usr/local/etc/rc.d/#{new_resource.service_name} faststart")
461
+ provider.start_service()
234
462
  end
235
463
  end
236
464
 
237
- describe Chef::Provider::Service::Init, "stop_service" do
465
+ describe Chef::Provider::Service::Freebsd, "stop_service" do
238
466
  it "should call the stop command if one is specified" do
239
- @new_resource.stop_command("/etc/init.d/chef itoldyoutostop")
240
- @provider.should_receive(:shell_out!).with("/etc/init.d/chef itoldyoutostop")
241
- @provider.load_current_resource
242
- @provider.stop_service()
467
+ new_resource.stop_command("/etc/init.d/chef itoldyoutostop")
468
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef itoldyoutostop")
469
+ provider.stop_service()
243
470
  end
244
471
 
245
472
  it "should call '/usr/local/etc/rc.d/service_name faststop' if no stop command is specified" do
246
- @provider.should_receive(:shell_out!).with("/usr/local/etc/rc.d/#{@new_resource.service_name} faststop")
247
- @provider.load_current_resource
248
- @provider.stop_service()
473
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/usr/local/etc/rc.d/#{new_resource.service_name} faststop")
474
+ provider.stop_service()
249
475
  end
250
476
  end
251
477
 
252
- describe "when restarting a service" do
478
+ describe Chef::Provider::Service::Freebsd, "restart_service" do
253
479
  it "should call 'restart' on the service_name if the resource supports it" do
254
- @new_resource.supports({:restart => true})
255
- @provider.should_receive(:shell_out!).with("/usr/local/etc/rc.d/#{@new_resource.service_name} fastrestart")
256
- @provider.load_current_resource
257
- @provider.restart_service()
480
+ new_resource.supports({:restart => true})
481
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/usr/local/etc/rc.d/#{new_resource.service_name} fastrestart")
482
+ provider.restart_service()
258
483
  end
259
484
 
260
485
  it "should call the restart_command if one has been specified" do
261
- @new_resource.restart_command("/etc/init.d/chef restartinafire")
262
- @provider.should_receive(:shell_out!).with("/etc/init.d/chef restartinafire")
263
- @provider.load_current_resource
264
- @provider.restart_service()
486
+ new_resource.restart_command("/etc/init.d/chef restartinafire")
487
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef restartinafire")
488
+ provider.restart_service()
489
+ end
490
+
491
+ it "otherwise it should call stop and start" do
492
+ expect(provider).to receive(:stop_service)
493
+ expect(provider).to receive(:start_service)
494
+ provider.restart_service()
265
495
  end
266
496
  end
497
+ end
267
498
 
268
- describe "when the rcscript does not have a name variable" do
499
+ describe Chef::Provider::Service::Freebsd, "define_resource_requirements" do
500
+ before do
501
+ provider.current_resource = current_resource
502
+ end
503
+
504
+ context "when the init script is not found" do
269
505
  before do
270
- @rc_without_name = StringIO.new(<<-RC_SAMPLE)
271
- rcvar=`set_rcvar`
272
- RC_SAMPLE
273
- ::File.stub(:open).with("/usr/local/etc/rc.d/#{@current_resource.service_name}").and_return(@rc_with_noname)
274
- @provider.current_resource = @current_resource
506
+ provider.init_command = nil
507
+ allow(provider).to receive(:service_enable_variable_name).and_return("#{new_resource.service_name}_enable")
275
508
  end
276
509
 
277
- describe "when rcvar returns foobar_enable" do
278
- before do
279
- @rcvar_stdout = <<RCVAR_SAMPLE
280
- # apache22
281
- #
282
- # #{@current_resource.service_name}_enable="YES"
283
- # (default: "")
284
- RCVAR_SAMPLE
285
- @status = double(:stdout => @rcvar_stdout, :exitstatus => 0)
286
- @provider.stub(:shell_out!).with("/usr/local/etc/rc.d/#{@current_resource.service_name} rcvar").and_return(@status)
287
- end
288
-
289
- it "should get the service name from rcvar if the rcscript does not have a name variable" do
290
- @provider.load_current_resource
291
- @provider.unstub(:service_enable_variable_name)
292
- @provider.service_enable_variable_name.should == "#{@current_resource.service_name}_enable"
510
+ [ "start", "reload", "restart", "enable" ].each do |action|
511
+ it "should raise an exception when the action is #{action}" do
512
+ provider.define_resource_requirements
513
+ provider.action = action
514
+ expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
293
515
  end
516
+ end
294
517
 
295
- it "should not raise an exception if the rcscript does not have a name variable" do
296
- @provider.load_current_resource
297
- lambda { @provider.service_enable_variable_name }.should_not raise_error
518
+ [ "stop", "disable" ].each do |action|
519
+ it "should not raise an error when the action is #{action}" do
520
+ provider.define_resource_requirements
521
+ provider.action = action
522
+ expect { provider.process_resource_requirements }.not_to raise_error
298
523
  end
299
524
  end
525
+ end
300
526
 
301
- describe "when rcvar does not return foobar_enable" do
302
- before do
303
- @rcvar_stdout = <<RCVAR_SAMPLE
304
- # service_with_noname
305
- #
306
- RCVAR_SAMPLE
307
- @status = double(:stdout => @rcvar_stdout, :exitstatus => 0)
308
- @provider.stub(:shell_out!).with("/usr/local/etc/rc.d/#{@current_resource.service_name} rcvar").and_return(@status)
309
- end
527
+ context "when the init script is found, but the service_enable_variable_name is nil" do
528
+ before do
529
+ provider.init_command = nil
530
+ allow(provider).to receive(:service_enable_variable_name).and_return(nil)
531
+ end
310
532
 
311
- [ "start", "reload", "restart", "enable" ].each do |action|
312
- it "should raise an exception when the action is #{action}" do
313
- @provider.action = action
314
- @provider.load_current_resource
315
- @provider.define_resource_requirements
316
- lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service)
317
- end
533
+ [ "start", "reload", "restart", "enable" ].each do |action|
534
+ it "should raise an exception when the action is #{action}" do
535
+ provider.action = action
536
+ provider.define_resource_requirements
537
+ expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service)
318
538
  end
539
+ end
319
540
 
320
- [ "stop", "disable" ].each do |action|
321
- it "should not raise an error when the action is #{action}" do
322
- ::File.stub(:exist?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true)
323
- @provider.action = action
324
- @provider.load_current_resource
325
- @provider.define_resource_requirements
326
- lambda { @provider.process_resource_requirements }.should_not raise_error
327
- end
541
+ [ "stop", "disable" ].each do |action|
542
+ it "should not raise an error when the action is #{action}" do
543
+ provider.action = action
544
+ provider.define_resource_requirements
545
+ expect { provider.process_resource_requirements }.not_to raise_error
328
546
  end
329
547
  end
330
548
  end
@@ -332,48 +550,62 @@ RCVAR_SAMPLE
332
550
 
333
551
  describe Chef::Provider::Service::Freebsd, "enable_service" do
334
552
  before do
335
- @provider.current_resource = @current_resource
336
- @provider.stub(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable")
553
+ provider.current_resource = current_resource
554
+ allow(provider).to receive(:service_enable_variable_name).and_return("#{new_resource.service_name}_enable")
337
555
  end
338
556
 
339
557
  it "should enable the service if it is not enabled" do
340
- @current_resource.stub(:enabled).and_return(false)
341
- @provider.should_receive(:read_rc_conf).and_return([ "foo", "#{@current_resource.service_name}_enable=\"NO\"", "bar" ])
342
- @provider.should_receive(:write_rc_conf).with(["foo", "bar", "#{@current_resource.service_name}_enable=\"YES\""])
343
- @provider.enable_service()
558
+ allow(current_resource).to receive(:enabled).and_return(false)
559
+ expect(provider).to receive(:read_rc_conf).and_return([ "foo", "#{new_resource.service_name}_enable=\"NO\"", "bar" ])
560
+ expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"YES\""])
561
+ provider.enable_service()
562
+ end
563
+
564
+ it "should not partial match an already enabled service" do
565
+ allow(current_resource).to receive(:enabled).and_return(false)
566
+ expect(provider).to receive(:read_rc_conf).and_return([ "foo", "thing_#{new_resource.service_name}_enable=\"NO\"", "bar" ])
567
+ expect(provider).to receive(:write_rc_conf).with(["foo", "thing_#{new_resource.service_name}_enable=\"NO\"", "bar", "#{new_resource.service_name}_enable=\"YES\""])
568
+ provider.enable_service()
344
569
  end
345
570
 
346
571
  it "should enable the service if it is not enabled and not already specified in the rc.conf file" do
347
- @current_resource.stub(:enabled).and_return(false)
348
- @provider.should_receive(:read_rc_conf).and_return([ "foo", "bar" ])
349
- @provider.should_receive(:write_rc_conf).with(["foo", "bar", "#{@current_resource.service_name}_enable=\"YES\""])
350
- @provider.enable_service()
572
+ allow(current_resource).to receive(:enabled).and_return(false)
573
+ expect(provider).to receive(:read_rc_conf).and_return([ "foo", "bar" ])
574
+ expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"YES\""])
575
+ provider.enable_service()
351
576
  end
352
577
 
353
578
  it "should not enable the service if it is already enabled" do
354
- @current_resource.stub(:enabled).and_return(true)
355
- @provider.should_not_receive(:write_rc_conf)
356
- @provider.enable_service
579
+ allow(current_resource).to receive(:enabled).and_return(true)
580
+ expect(provider).not_to receive(:write_rc_conf)
581
+ provider.enable_service
357
582
  end
358
583
  end
359
584
 
360
585
  describe Chef::Provider::Service::Freebsd, "disable_service" do
361
586
  before do
362
- @provider.current_resource = @current_resource
363
- @provider.stub(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable")
587
+ provider.current_resource = current_resource
588
+ allow(provider).to receive(:service_enable_variable_name).and_return("#{new_resource.service_name}_enable")
589
+ end
590
+
591
+ it "should disable the service if it is not disabled" do
592
+ allow(current_resource).to receive(:enabled).and_return(true)
593
+ expect(provider).to receive(:read_rc_conf).and_return([ "foo", "#{new_resource.service_name}_enable=\"YES\"", "bar" ])
594
+ expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"NO\""])
595
+ provider.disable_service()
364
596
  end
365
597
 
366
- it "should should disable the service if it is not disabled" do
367
- @current_resource.stub(:enabled).and_return(true)
368
- @provider.should_receive(:read_rc_conf).and_return([ "foo", "#{@current_resource.service_name}_enable=\"YES\"", "bar" ])
369
- @provider.should_receive(:write_rc_conf).with(["foo", "bar", "#{@current_resource.service_name}_enable=\"NO\""])
370
- @provider.disable_service()
598
+ it "should not disable an enabled service that partially matches" do
599
+ allow(current_resource).to receive(:enabled).and_return(true)
600
+ expect(provider).to receive(:read_rc_conf).and_return([ "foo", "thing_#{new_resource.service_name}_enable=\"YES\"", "bar" ])
601
+ expect(provider).to receive(:write_rc_conf).with(["foo", "thing_#{new_resource.service_name}_enable=\"YES\"", "bar", "#{new_resource.service_name}_enable=\"NO\""])
602
+ provider.disable_service()
371
603
  end
372
604
 
373
605
  it "should not disable the service if it is already disabled" do
374
- @current_resource.stub(:enabled).and_return(false)
375
- @provider.should_not_receive(:write_rc_conf)
376
- @provider.disable_service()
606
+ allow(current_resource).to receive(:enabled).and_return(false)
607
+ expect(provider).not_to receive(:write_rc_conf)
608
+ provider.disable_service()
377
609
  end
378
610
  end
379
611
  end