summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-30 10:59:57 -0600
committerJohn Keiser <john@johnkeiser.com>2015-06-30 11:18:42 -0600
commite1e1e1331a4e87c662dae72acdeff00230e74a3c (patch)
tree4aa5d541a6a2f06c84ac6be9f742e8d1e8477687
parent5bb507836095585274d5a9bb2802bf662fab4195 (diff)
downloadchef-e1e1e1331a4e87c662dae72acdeff00230e74a3c.tar.gz
Make provider resolution tests less invasive (don't actually instantiate the provider)jk/call_provides_when_resolving
-rw-r--r--lib/chef/provider/group/windows.rb8
-rw-r--r--lib/chef/provider/user/windows.rb8
-rw-r--r--spec/unit/platform_spec.rb2
-rw-r--r--spec/unit/provider_resolver_spec.rb20
4 files changed, 22 insertions, 16 deletions
diff --git a/lib/chef/provider/group/windows.rb b/lib/chef/provider/group/windows.rb
index 59d1c308ff..46d8afc7f6 100644
--- a/lib/chef/provider/group/windows.rb
+++ b/lib/chef/provider/group/windows.rb
@@ -28,11 +28,9 @@ class Chef
provides :group, os: 'windows'
- if RUBY_PLATFORM =~ /mswin|mingw32|windows/
- def initialize(new_resource,run_context)
- super
- @net_group = Chef::Util::Windows::NetGroup.new(@new_resource.group_name)
- end
+ def initialize(new_resource,run_context)
+ super
+ @net_group = Chef::Util::Windows::NetGroup.new(@new_resource.group_name)
end
def load_current_resource
diff --git a/lib/chef/provider/user/windows.rb b/lib/chef/provider/user/windows.rb
index d8653c6af3..e282a11d45 100644
--- a/lib/chef/provider/user/windows.rb
+++ b/lib/chef/provider/user/windows.rb
@@ -29,11 +29,9 @@ class Chef
provides :user, os: "windows"
- if RUBY_PLATFORM =~ /mswin|mingw32|windows/
- def initialize(new_resource,run_context)
- super
- @net_user = Chef::Util::Windows::NetUser.new(@new_resource.username)
- end
+ def initialize(new_resource,run_context)
+ super
+ @net_user = Chef::Util::Windows::NetUser.new(@new_resource.username)
end
def load_current_resource
diff --git a/spec/unit/platform_spec.rb b/spec/unit/platform_spec.rb
index 36325d5411..34b46f657f 100644
--- a/spec/unit/platform_spec.rb
+++ b/spec/unit/platform_spec.rb
@@ -103,7 +103,7 @@ describe Chef::Platform do
end
it "should raise an exception if a provider cannot be found for a resource type" do
- expect { Chef::Platform.find_provider("Darwin", "9.2.2", :coffee) }.to raise_error(ArgumentError)
+ expect { Chef::Platform.find_provider("Darwin", "9.2.2", :coffee) }.to raise_error(Chef::Exceptions::ProviderNotFound)
end
it "should look up a provider for a resource with a Chef::Resource object" do
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb
index 6cddaaced9..e09b12a20a 100644
--- a/spec/unit/provider_resolver_spec.rb
+++ b/spec/unit/provider_resolver_spec.rb
@@ -106,13 +106,23 @@ describe Chef::ProviderResolver do
end
end
- if expected_resource || expected_provider
- it "resolves to #{[ expected_resource, expected_provider ].compact.join(" and ")}", *tags do
- expect(resource.class).to eql(expected_resource) if expected_resource
- expect(resolved_provider).to eql(expected_provider) if expected_provider
+ if expected_resource && expected_provider
+ it "'#{name}' resolves to resource #{expected_resource} and provider #{expected_provider}", *tags do
+ expect(resource.class).to eql(expected_resource)
+ provider = double(expected_provider, class: expected_provider)
+ expect(provider).to receive(:action=).with(action)
+ expect(expected_provider).to receive(:new).with(resource, run_context).and_return(provider)
+ expect(resolved_provider).to eql(expected_provider)
+ end
+ elsif expected_provider
+ it "'#{name}' resolves to provider #{expected_provider}", *tags do
+ provider = double(expected_provider)
+ expect(provider).to receive(:action=).with(action)
+ expect(expected_provider).to receive(:new).with(resource, run_context).and_return(provider)
+ expect(resolved_provider).to eql(expected_provider)
end
else
- it "Fails to resolve (since #{name.inspect} is unsupported on #{platform} #{platform_version})", *tags do
+ it "'#{name}' fails to resolve (since #{name.inspect} is unsupported on #{platform} #{platform_version})", *tags do
expect(resolved_provider).to be_nil
end
end