diff options
author | Claire McQuin <claire@getchef.com> | 2015-05-12 11:56:36 -0700 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2015-05-27 14:16:25 -0400 |
commit | e2a974f008d8635a37acaff2964404f3653b3a33 (patch) | |
tree | c4dbe98aa29dfd39f4907595cd9115ae7f13457b | |
parent | 5745ba2f93c9157d8cbbe6a63a96d4989fcea2a3 (diff) | |
download | chef-e2a974f008d8635a37acaff2964404f3653b3a33.tar.gz |
refactor ohai stubs, remove hardcoding
-rw-r--r-- | spec/support/shared/context/client.rb | 30 | ||||
-rw-r--r-- | spec/support/shared/examples/client.rb | 5 |
2 files changed, 18 insertions, 17 deletions
diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb index aa1f473aae..e625185f7c 100644 --- a/spec/support/shared/context/client.rb +++ b/spec/support/shared/context/client.rb @@ -3,28 +3,28 @@ require 'spec_helper' # Stubs a basic client object shared_context "client" do - let(:hostname) { "hostname" } - let(:machinename) { "machinename.example.org" } - let(:fqdn) { "hostname.example.org" } + let(:fqdn) { "hostname.example.org" } + let(:hostname) { "hostname" } + let(:machinename) { "machinename.example.org" } + let(:platform) { "example-platform" } + let(:platform_version) { "example-platform-1.0" } let(:ohai_data) do - { :fqdn => fqdn, - :hostname => hostname, - :machinename => machinename, - :platform => 'example-platform', - :platform_version => 'example-platform-1.0', - :data => {} + { + :fqdn => fqdn, + :hostname => hostname, + :machinename => machinename, + :platform => platform, + :platform_version => platform_version } end let(:ohai_system) do - ohai_system = double( "Ohai::System", - :all_plugins => true, - :data => ohai_data) - allow(ohai_system).to receive(:[]) do |key| - ohai_data[key] + ohai = instance_double("Ohai::System", :all_plugins => true, :data => ohai_data) + allow(ohai).to receive(:[]) do |k| + ohai_data[k] end - ohai_system + ohai end let(:node) do diff --git a/spec/support/shared/examples/client.rb b/spec/support/shared/examples/client.rb index 17eda195b8..0a57abc044 100644 --- a/spec/support/shared/examples/client.rb +++ b/spec/support/shared/examples/client.rb @@ -2,6 +2,7 @@ require 'spec_helper' require 'spec/support/shared/context/client' +# requires platform and platform_version be defined shared_examples "a completed run" do include_context "run completed" @@ -10,8 +11,8 @@ shared_examples "a completed run" do expect(client.run).to be true # fork is stubbed, so we can see the outcome of the run - expect(node.automatic_attrs[:platform]).to eq("example-platform") - expect(node.automatic_attrs[:platform_version]).to eq("example-platform-1.0") + expect(node.automatic_attrs[:platform]).to eq(platform) + expect(node.automatic_attrs[:platform_version]).to eq(platform_version) end end |