summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Nordsieck <theo@opscode.com>2013-08-21 10:25:37 -0700
committerTheodore Nordsieck <theo@opscode.com>2013-08-22 11:06:29 -0700
commit8171a336f256438e96af974d2bf124d0d93ea1f4 (patch)
tree376be7014a8e7f642afd012352e4bd1d6ccdfe76
parent0d9fc0e2e11270d29c43446dd8c6d6b2e371e16f (diff)
downloadohai-8171a336f256438e96af974d2bf124d0d93ea1f4.tar.gz
Modified subsumes? so that it can test all leaves and is still also testable itself
-rw-r--r--spec/unit/path/ohai_plugin_common.rb18
-rw-r--r--spec/unit/path/ohai_plugin_common_spec.rb57
2 files changed, 42 insertions, 33 deletions
diff --git a/spec/unit/path/ohai_plugin_common.rb b/spec/unit/path/ohai_plugin_common.rb
index 1289479e..ff6de7fa 100644
--- a/spec/unit/path/ohai_plugin_common.rb
+++ b/spec/unit/path/ohai_plugin_common.rb
@@ -152,13 +152,12 @@ end
#checks to see if the elements in test are also in source. Recursively decends into Hashes.
#nil values in test match against both nil and non-existance in source.
-def subsumes?(source, test, path = [])
+def subsumes?(source, test, path = [], &block)
if source.is_a?( Hash ) && test.is_a?( Hash )
- test.all? { |k,v| subsumes?( source[k], v, path.clone << k )}
+ test.all? { |k,v| subsumes?( source[k], v, path.clone << k, &block )}
else
- it "should set " + path.map { |s| "[#{s}]" }.join + " to #{source || 'nil'}" do
- source.should eq( test )
- end
+ block.call( path, source, test ) if block
+ source == test
end
end
@@ -204,7 +203,14 @@ shared_context "cross platform data" do
cmd_list.each { |c| [ "", ".bat" ].each { |ext| Mixlib::ShellOut.new("rm #{path}/#{c}#{ext}").run_command if !cmd_not_found.include?( c )}}
end
- subsumes?( @ohai.data, e[:ohai] )
+ enc = Yajl::Encoder
+ subsumes?( @ohai.data, e[:ohai] ) do | path, source, test |
+ path_txt = path.map { |e| "[#{enc.encode( e )}]" }.join
+ source_txt = if source.nil? then "nil" else enc.encode( source ) end
+ it "should set #{path_txt} to #{source_txt}" do
+ source.should eq( test )
+ end
+ end
end
end
end
diff --git a/spec/unit/path/ohai_plugin_common_spec.rb b/spec/unit/path/ohai_plugin_common_spec.rb
index f3c0ca0c..5ea81ee5 100644
--- a/spec/unit/path/ohai_plugin_common_spec.rb
+++ b/spec/unit/path/ohai_plugin_common_spec.rb
@@ -19,31 +19,34 @@
require File.expand_path(File.dirname(__FILE__) + "/ohai_plugin_common.rb")
describe OhaiPluginCommon, "subsumes?" do
- # before(:each) do
- # @hash = { "languages" => { "python" => { "version" => "1.6.2", "type" => "interpreted" }}}
- # end
-
- @hash = { "languages" => { "python" => { "version" => "1.6.2", "type" => "interpreted" }}}
-
- # returns true if given an exact duplicate
- subsumes?( @hash, @hash )
-
- # returns false if given an exact duplicate with extra info
- # subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => "darwin", "type" => "interpreted" }}} )
- # subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => {}, "type" => "interpreted" }}} ).should be_false
- # subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => { "name" => "darwin" }, "type" => "interpreted" }}} ).should be_false
-
- # returns true if all elements in the second hash are in the first hash
- subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2" }}} )
- subsumes?( @hash, { "languages" => { "python" => {}}} )
- subsumes?( @hash, { "languages" => {}} )
-
- # returns true if the second hash contains a key pointing to a nil where the first hash has nothing
- subsumes?( @hash, { "languages" => { "lua" => nil }} )
- subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2" }, "lua" => nil }} )
-
- # returns false if the second hash has nil in the place of a real value
- # subsumes?( @hash, { "languages" => { "python" => { "version" => nil }}} ).should be_false
- # subsumes?( @hash, { "languages" => { "python" => nil }} ).should be_false
- # subsumes?( { "languages" => {}}, { "languages" => nil } ).should be_false
+ before(:each) do
+ @hash = { "languages" => { "python" => { "version" => "1.6.2", "type" => "interpreted" }}}
+ end
+
+ it "returns true if given an exact duplicate" do
+ subsumes?( @hash, @hash ).should be_true
+ end
+
+ it "returns false if given an exact duplicate with extra info" do
+ subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => "darwin", "type" => "interpreted" }}} ).should be_false
+ subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => {}, "type" => "interpreted" }}} ).should be_false
+ subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2", "os" => { "name" => "darwin" }, "type" => "interpreted" }}} ).should be_false
+ end
+
+ it "returns true if all elements in the second hash are in the first hash" do
+ subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2" }}} ).should be_true
+ subsumes?( @hash, { "languages" => { "python" => {}}} ).should be_true
+ subsumes?( @hash, { "languages" => {}} ).should be_true
+ end
+
+ it "returns true if the second hash contains a key pointing to a nil where the first hash has nothing" do
+ subsumes?( @hash, { "languages" => { "lua" => nil }} ).should be_true
+ subsumes?( @hash, { "languages" => { "python" => { "version" => "1.6.2" }, "lua" => nil }} ).should be_true
+ end
+
+ it "returns false if the second hash has nil in the place of a real value" do
+ subsumes?( @hash, { "languages" => { "python" => { "version" => nil }}} ).should be_false
+ subsumes?( @hash, { "languages" => { "python" => nil }} ).should be_false
+ subsumes?( { "languages" => {}}, { "languages" => nil } ).should be_false
+ end
end