facter 1.7.6 → 2.0.1.rc1

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

Potentially problematic release.


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

Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/COMMITTERS.md +194 -0
  3. data/CONTRIBUTING.md +63 -235
  4. data/Gemfile +12 -8
  5. data/README.md +1 -2
  6. data/Rakefile +1 -1
  7. data/bin/facter +0 -4
  8. data/ext/build_defaults.yaml +2 -2
  9. data/ext/project_data.yaml +18 -0
  10. data/install.rb +1 -16
  11. data/lib/facter.rb +171 -171
  12. data/lib/facter/application.rb +65 -54
  13. data/lib/facter/core/aggregate.rb +220 -0
  14. data/lib/facter/core/directed_graph.rb +46 -0
  15. data/lib/facter/core/execution.rb +100 -0
  16. data/lib/facter/core/execution/base.rb +73 -0
  17. data/lib/facter/core/execution/posix.rb +50 -0
  18. data/lib/facter/core/execution/windows.rb +57 -0
  19. data/lib/facter/core/logging.rb +169 -0
  20. data/lib/facter/core/resolvable.rb +94 -0
  21. data/lib/facter/core/suitable.rb +117 -0
  22. data/lib/facter/domain.rb +15 -9
  23. data/lib/facter/filesystems.rb +1 -1
  24. data/lib/facter/hardwaremodel.rb +1 -1
  25. data/lib/facter/hostname.rb +3 -3
  26. data/lib/facter/interfaces.rb +6 -1
  27. data/lib/facter/ipaddress.rb +2 -2
  28. data/lib/facter/kernel.rb +1 -1
  29. data/lib/facter/kernelrelease.rb +1 -1
  30. data/lib/facter/ldom.rb +1 -1
  31. data/lib/facter/lsbdistcodename.rb +1 -1
  32. data/lib/facter/lsbdistdescription.rb +1 -1
  33. data/lib/facter/lsbdistid.rb +1 -1
  34. data/lib/facter/lsbdistrelease.rb +1 -1
  35. data/lib/facter/lsbrelease.rb +1 -1
  36. data/lib/facter/macaddress.rb +1 -14
  37. data/lib/facter/macosx.rb +2 -2
  38. data/lib/facter/memory.rb +8 -19
  39. data/lib/facter/operatingsystem.rb +1 -1
  40. data/lib/facter/operatingsystemrelease.rb +34 -1
  41. data/lib/facter/physicalprocessorcount.rb +6 -6
  42. data/lib/facter/processor.rb +11 -10
  43. data/lib/facter/selinux.rb +4 -15
  44. data/lib/facter/ssh.rb +5 -2
  45. data/lib/facter/util/architecture.rb +2 -2
  46. data/lib/facter/util/collection.rb +42 -38
  47. data/lib/facter/util/config.rb +19 -9
  48. data/lib/facter/util/confine.rb +34 -4
  49. data/lib/facter/util/ec2.rb +1 -1
  50. data/lib/facter/util/fact.rb +108 -36
  51. data/lib/facter/util/file_read.rb +7 -6
  52. data/lib/facter/util/formatter.rb +38 -0
  53. data/lib/facter/util/ip.rb +3 -3
  54. data/lib/facter/util/loader.rb +62 -42
  55. data/lib/facter/util/macosx.rb +7 -8
  56. data/lib/facter/util/manufacturer.rb +3 -3
  57. data/lib/facter/util/memory.rb +13 -13
  58. data/lib/facter/util/monkey_patches.rb +0 -31
  59. data/lib/facter/util/netmask.rb +3 -3
  60. data/lib/facter/util/normalization.rb +94 -0
  61. data/lib/facter/util/nothing_loader.rb +3 -6
  62. data/lib/facter/util/parser.rb +3 -5
  63. data/lib/facter/util/plist/generator.rb +1 -1
  64. data/lib/facter/util/processor.rb +15 -15
  65. data/lib/facter/util/resolution.rb +112 -289
  66. data/lib/facter/util/solaris_zones.rb +4 -4
  67. data/lib/facter/util/uptime.rb +8 -3
  68. data/lib/facter/util/values.rb +67 -1
  69. data/lib/facter/util/virtual.rb +10 -10
  70. data/lib/facter/util/xendomains.rb +1 -1
  71. data/lib/facter/version.rb +42 -39
  72. data/lib/facter/virtual.rb +6 -7
  73. data/lib/facter/zfs_version.rb +3 -3
  74. data/lib/facter/zpool_version.rb +3 -3
  75. data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
  76. data/spec/unit/application_spec.rb +46 -1
  77. data/spec/unit/core/aggregate_spec.rb +125 -0
  78. data/spec/unit/core/directed_graph_spec.rb +79 -0
  79. data/spec/unit/core/execution/base_spec.rb +119 -0
  80. data/spec/unit/core/execution/posix_spec.rb +86 -0
  81. data/spec/unit/core/execution/windows_spec.rb +106 -0
  82. data/spec/unit/core/execution_spec.rb +37 -0
  83. data/spec/unit/core/logging_spec.rb +104 -0
  84. data/spec/unit/core/resolvable_spec.rb +81 -0
  85. data/spec/unit/core/suitable_spec.rb +96 -0
  86. data/spec/unit/domain_spec.rb +5 -5
  87. data/spec/unit/facter_spec.rb +61 -222
  88. data/spec/unit/filesystems_spec.rb +2 -2
  89. data/spec/unit/hardwareisa_spec.rb +5 -5
  90. data/spec/unit/hardwaremodel_spec.rb +1 -1
  91. data/spec/unit/hostname_spec.rb +4 -4
  92. data/spec/unit/id_spec.rb +3 -3
  93. data/spec/unit/interfaces_spec.rb +10 -0
  94. data/spec/unit/ipaddress6_spec.rb +4 -4
  95. data/spec/unit/ipaddress_spec.rb +1 -1
  96. data/spec/unit/kernel_spec.rb +2 -2
  97. data/spec/unit/kernelmajversion_spec.rb +1 -1
  98. data/spec/unit/kernelrelease_spec.rb +4 -4
  99. data/spec/unit/kernelversion_spec.rb +2 -2
  100. data/spec/unit/ldom_spec.rb +2 -2
  101. data/spec/unit/lsbdistcodename_spec.rb +2 -2
  102. data/spec/unit/lsbdistdescription_spec.rb +2 -2
  103. data/spec/unit/lsbdistid_spec.rb +2 -2
  104. data/spec/unit/lsbdistrelease_spec.rb +2 -2
  105. data/spec/unit/lsbrelease_spec.rb +2 -2
  106. data/spec/unit/manufacturer_spec.rb +1 -1
  107. data/spec/unit/memory_spec.rb +24 -31
  108. data/spec/unit/netmask_spec.rb +9 -0
  109. data/spec/unit/operatingsystem_spec.rb +1 -1
  110. data/spec/unit/operatingsystemrelease_spec.rb +62 -4
  111. data/spec/unit/physicalprocessorcount_spec.rb +10 -10
  112. data/spec/unit/processor_spec.rb +11 -11
  113. data/spec/unit/selinux_spec.rb +2 -8
  114. data/spec/unit/ssh_spec.rb +3 -2
  115. data/spec/unit/uniqueid_spec.rb +3 -3
  116. data/spec/unit/util/collection_spec.rb +37 -35
  117. data/spec/unit/util/config_spec.rb +20 -0
  118. data/spec/unit/util/confine_spec.rb +21 -0
  119. data/spec/unit/util/directory_loader_spec.rb +1 -0
  120. data/spec/unit/util/ec2_spec.rb +6 -6
  121. data/spec/unit/util/fact_spec.rb +92 -90
  122. data/spec/unit/util/ip_spec.rb +2 -2
  123. data/spec/unit/util/loader_spec.rb +127 -186
  124. data/spec/unit/util/macaddress_spec.rb +2 -2
  125. data/spec/unit/util/macosx_spec.rb +8 -8
  126. data/spec/unit/util/manufacturer_spec.rb +3 -3
  127. data/spec/unit/util/normalization_spec.rb +113 -0
  128. data/spec/unit/util/parser_spec.rb +25 -3
  129. data/spec/unit/util/processor_spec.rb +2 -2
  130. data/spec/unit/util/resolution_spec.rb +60 -631
  131. data/spec/unit/util/solaris_zones_spec.rb +5 -5
  132. data/spec/unit/util/uptime_spec.rb +1 -1
  133. data/spec/unit/util/values_spec.rb +131 -0
  134. data/spec/unit/util/virtual_spec.rb +16 -16
  135. data/spec/unit/util/xendomains_spec.rb +2 -2
  136. data/spec/unit/virtual_spec.rb +39 -39
  137. data/spec/unit/zfs_version_spec.rb +11 -11
  138. data/spec/unit/zonename_spec.rb +2 -2
  139. data/spec/unit/zones_spec.rb +1 -1
  140. data/spec/unit/zpool_version_spec.rb +11 -11
  141. metadata +466 -447
  142. data/lib/facter/util/cfpropertylist.rb +0 -6
  143. data/lib/facter/util/cfpropertylist/LICENSE +0 -19
  144. data/lib/facter/util/cfpropertylist/README +0 -44
  145. data/lib/facter/util/cfpropertylist/Rakefile +0 -44
  146. data/lib/facter/util/cfpropertylist/THANKS +0 -7
  147. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
  148. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
  149. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
  150. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
  151. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
  152. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
  153. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
  154. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
  155. data/spec/unit/util/monkey_patches_spec.rb +0 -42
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'facter/core/execution'
3
+
4
+ describe Facter::Core::Execution do
5
+ subject { described_class}
6
+ let(:impl) { described_class.impl }
7
+
8
+ it "delegates #search_paths to the implementation" do
9
+ impl.expects(:search_paths)
10
+ subject.search_paths
11
+ end
12
+
13
+ it "delegates #which to the implementation" do
14
+ impl.expects(:which).with('waffles')
15
+ subject.which('waffles')
16
+ end
17
+
18
+ it "delegates #absolute_path? to the implementation" do
19
+ impl.expects(:absolute_path?).with('waffles', nil)
20
+ subject.absolute_path?('waffles')
21
+ end
22
+
23
+ it "delegates #absolute_path? with an optional platform to the implementation" do
24
+ impl.expects(:absolute_path?).with('waffles', :windows)
25
+ subject.absolute_path?('waffles', :windows)
26
+ end
27
+
28
+ it "delegates #expand_command to the implementation" do
29
+ impl.expects(:expand_command).with('waffles')
30
+ subject.expand_command('waffles')
31
+ end
32
+
33
+ it "delegates #exec to the implementation" do
34
+ impl.expects(:exec).with('waffles')
35
+ subject.exec('waffles')
36
+ end
37
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+ require 'facter/core/logging'
3
+
4
+ describe Facter::Core::Logging do
5
+
6
+ subject { described_class }
7
+
8
+ after(:all) do
9
+ subject.debugging(false)
10
+ subject.timing(false)
11
+ end
12
+
13
+ describe "emitting debug messages" do
14
+ it "doesn't log a message when debugging is disabled" do
15
+ subject.debugging(false)
16
+ subject.expects(:puts).never
17
+ subject.debug("foo")
18
+ end
19
+
20
+ describe "and debugging is enabled" do
21
+ before { subject.debugging(true) }
22
+ it "emits a warning when called with nil" do
23
+ subject.expects(:warn).with { |msg| expect(msg).to match /invalid message nil:NilClass/ }
24
+ subject.debug(nil)
25
+ end
26
+
27
+ it "emits a warning when called with an empty string" do
28
+ subject.expects(:warn).with { |msg| expect(msg).to match /invalid message "":String/ }
29
+ subject.debug("")
30
+ end
31
+
32
+ it "prints the message when logging is enabled" do
33
+ subject.expects(:puts).with { |msg| expect(msg).to match /foo/ }
34
+ subject.debug("foo")
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "when warning" do
40
+ it "emits a warning when given a string" do
41
+ subject.debugging(true)
42
+ Kernel.expects(:warn).with('foo')
43
+ subject.warn('foo')
44
+ end
45
+
46
+ it "emits a warning regardless of log level" do
47
+ subject.debugging(false)
48
+ Kernel.expects(:warn).with "foo"
49
+ subject.warn "foo"
50
+ end
51
+
52
+ it "emits a warning if nil is passed" do
53
+ Kernel.expects(:warn).with { |msg| expect(msg).to match /invalid message nil:NilClass/ }
54
+ subject.warn(nil)
55
+ end
56
+
57
+ it "emits a warning if an empty string is passed" do
58
+ Kernel.expects(:warn).with { |msg| expect(msg).to match /invalid message "":String/ }
59
+ subject.warn('')
60
+ end
61
+ end
62
+
63
+ describe "when warning once" do
64
+ it "only logs a given warning string once" do
65
+ subject.expects(:warn).with('foo').once
66
+ subject.warnonce('foo')
67
+ subject.warnonce('foo')
68
+ end
69
+ end
70
+
71
+ describe "when setting the debugging mode" do
72
+ it "is enabled when the given value is true" do
73
+ subject.debugging(true)
74
+ expect(subject.debugging?).to be_true
75
+ end
76
+
77
+ it "is disabled when the given value is false" do
78
+ subject.debugging(false)
79
+ expect(subject.debugging?).to be_false
80
+ end
81
+
82
+ it "is disabled when the given value is nil" do
83
+ subject.debugging(nil)
84
+ expect(subject.debugging?).to be_false
85
+ end
86
+ end
87
+
88
+ describe "when setting the timing mode" do
89
+ it "is enabled when the given value is true" do
90
+ subject.timing(true)
91
+ expect(subject.timing?).to be_true
92
+ end
93
+
94
+ it "is disabled when the given value is false" do
95
+ subject.timing(false)
96
+ expect(subject.timing?).to be_false
97
+ end
98
+
99
+ it "is disabled when the given value is nil" do
100
+ subject.timing(nil)
101
+ expect(subject.timing?).to be_false
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+ require 'facter/core/resolvable'
3
+
4
+ describe Facter::Core::Resolvable do
5
+
6
+ class ResolvableClass
7
+ def initialize(name)
8
+ @name = name
9
+ @fact = Facter::Util::Fact.new("stub fact")
10
+ end
11
+ attr_accessor :name, :resolve_value
12
+ attr_reader :fact
13
+ include Facter::Core::Resolvable
14
+ end
15
+
16
+ subject { ResolvableClass.new('resolvable') }
17
+
18
+ it "has a default timeout of 0 seconds" do
19
+ expect(subject.limit).to eq 0
20
+ end
21
+
22
+ it "can specify a custom timeout" do
23
+ subject.timeout = 10
24
+ expect(subject.limit).to eq 10
25
+ end
26
+
27
+ describe "generating a value" do
28
+ it "returns the results of #resolve_value" do
29
+ subject.resolve_value = 'stuff'
30
+ expect(subject.value).to eq 'stuff'
31
+ end
32
+
33
+ it "normalizes the resolved value" do
34
+ Facter::Util::Normalization.expects(:normalize).returns 'stuff'
35
+ subject.resolve_value = 'stuff'
36
+ expect(subject.value).to eq('stuff')
37
+ end
38
+
39
+ it "logs a warning if an exception was raised" do
40
+ subject.expects(:resolve_value).raises RuntimeError, "kaboom!"
41
+ Facter.expects(:warn).with(regexp_matches(/Could not retrieve .*: kaboom!/))
42
+ expect(subject.value).to eq nil
43
+ end
44
+ end
45
+
46
+ describe "timing out" do
47
+ it "uses #limit instead of #timeout to determine the timeout period" do
48
+ subject.expects(:timeout).never
49
+ subject.expects(:limit).returns 25
50
+
51
+ Timeout.expects(:timeout).with(25)
52
+ subject.value
53
+ end
54
+
55
+ it "returns nil if the timeout was reached" do
56
+ Facter.expects(:warn).with(regexp_matches(/Timed out after 0\.1 seconds while resolving/))
57
+ Timeout.expects(:timeout).raises Timeout::Error
58
+
59
+ subject.timeout = 0.1
60
+
61
+ expect(subject.value).to be_nil
62
+ end
63
+ end
64
+
65
+ describe 'callbacks when flushing facts' do
66
+ class FlushFakeError < StandardError; end
67
+
68
+ context '#on_flush' do
69
+ it 'accepts a block with on_flush' do
70
+ subject.on_flush() { raise NotImplementedError }
71
+ end
72
+ end
73
+
74
+ context '#flush' do
75
+ it 'calls the block passed to on_flush' do
76
+ subject.on_flush() { raise FlushFakeError }
77
+ expect { subject.flush }.to raise_error FlushFakeError
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+ require 'facter/core/suitable'
3
+
4
+ describe Facter::Core::Suitable do
5
+
6
+ class SuitableClass
7
+ def initialize
8
+ @confines = []
9
+ end
10
+ attr_reader :confines
11
+ include Facter::Core::Suitable
12
+ end
13
+
14
+ subject { SuitableClass.new }
15
+
16
+ describe "confining on facts" do
17
+ it "can add confines with a fact and a single value" do
18
+ subject.confine :kernel => 'Linux'
19
+ end
20
+
21
+ it "creates a Facter::Util::Confine object for the confine call" do
22
+ subject.confine :kernel => 'Linux'
23
+ conf = subject.confines.first
24
+ expect(conf).to be_a_kind_of Facter::Util::Confine
25
+ expect(conf.fact).to eq :kernel
26
+ expect(conf.values).to eq ['Linux']
27
+ end
28
+ end
29
+
30
+ describe "confining on blocks" do
31
+ it "can add a single fact with a block parameter" do
32
+ subject.confine(:one) { true }
33
+ end
34
+
35
+ it "creates a Util::Confine instance for the provided fact with block parameter" do
36
+ block = lambda { true }
37
+ Facter::Util::Confine.expects(:new).with("one")
38
+
39
+ subject.confine("one", &block)
40
+ end
41
+
42
+ it "should accept a single block parameter" do
43
+ subject.confine() { true }
44
+ end
45
+
46
+ it "should create a Util::Confine instance for the provided block parameter" do
47
+ block = lambda { true }
48
+ Facter::Util::Confine.expects(:new)
49
+
50
+ subject.confine(&block)
51
+ end
52
+ end
53
+
54
+ describe "determining weight" do
55
+ it "is zero if no confines are set" do
56
+ expect(subject.weight).to eq 0
57
+ end
58
+
59
+ it "defaults to the number of confines" do
60
+ subject.confine :kernel => 'Linux'
61
+ expect(subject.weight).to eq 1
62
+ end
63
+
64
+ it "can be explicitly set" do
65
+ subject.has_weight 10
66
+ expect(subject.weight).to eq 10
67
+ end
68
+
69
+ it "prefers an explicit weight over the number of confines" do
70
+ subject.confine :kernel => 'Linux'
71
+ subject.has_weight 11
72
+ expect(subject.weight).to eq 11
73
+ end
74
+ end
75
+
76
+ describe "determining suitability" do
77
+ it "is true if all confines for the object evaluate to true" do
78
+ subject.confine :kernel => 'Linux'
79
+ subject.confine :operatingsystem => 'Redhat'
80
+
81
+ subject.confines.each { |confine| confine.stubs(:true?).returns true }
82
+
83
+ expect(subject).to be_suitable
84
+ end
85
+
86
+ it "is false if any confines for the object evaluate to false" do
87
+ subject.confine :kernel => 'Linux'
88
+ subject.confine :operatingsystem => 'Redhat'
89
+
90
+ subject.confines.first.stubs(:true?).returns true
91
+ subject.confines.first.stubs(:true?).returns false
92
+
93
+ expect(subject).to_not be_suitable
94
+ end
95
+ end
96
+ end
@@ -24,11 +24,11 @@ describe "Domain name facts" do
24
24
  let(:dnsdomain_command) { "dnsdomainname 2> /dev/null" }
25
25
 
26
26
  def the_hostname_is(value)
27
- Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns(value)
27
+ Facter::Core::Execution.stubs(:exec).with(hostname_command).returns(value)
28
28
  end
29
29
 
30
30
  def the_dnsdomainname_is(value)
31
- Facter::Util::Resolution.stubs(:exec).with(dnsdomain_command).returns(value)
31
+ Facter::Core::Execution.stubs(:exec).with(dnsdomain_command).returns(value)
32
32
  end
33
33
 
34
34
  before do
@@ -197,7 +197,7 @@ describe "Domain name facts" do
197
197
  it "should return nil" do
198
198
  expects_dnsdomains([nil])
199
199
 
200
- Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns('sometest')
200
+ Facter::Core::Execution.stubs(:exec).with(hostname_command).returns('sometest')
201
201
  FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(false)
202
202
 
203
203
  Facter.fact(:domain).value.should be_nil
@@ -288,8 +288,8 @@ describe "Domain name facts" do
288
288
 
289
289
  describe scenario[:scenario] do
290
290
  before(:each) do
291
- Facter::Util::Resolution.stubs(:exec).with("hostname -f 2> /dev/null").returns(scenario[:hostname])
292
- Facter::Util::Resolution.stubs(:exec).with("dnsdomainname 2> /dev/null").returns(scenario[:dnsdomainname])
291
+ Facter::Core::Execution.stubs(:exec).with("hostname -f 2> /dev/null").returns(scenario[:hostname])
292
+ Facter::Core::Execution.stubs(:exec).with("dnsdomainname 2> /dev/null").returns(scenario[:dnsdomainname])
293
293
  resolv_conf_contains(
294
294
  "search #{scenario[:resolve_search]}",
295
295
  "domain #{scenario[:resolve_domain]}"
@@ -3,267 +3,106 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Facter do
6
- it "should have a method for returning its collection" do
7
- Facter.should respond_to(:collection)
8
- end
9
-
10
- it "should cache the collection" do
6
+ it "caches the collection" do
11
7
  Facter.collection.should equal(Facter.collection)
12
8
  end
13
9
 
14
- it "should delegate the :flush method to the collection" do
15
- Facter.collection.expects(:flush)
16
- Facter.flush
17
- end
18
-
19
- it "should delegate the :fact method to the collection" do
20
- Facter.collection.expects(:fact)
21
- Facter.fact
22
- end
23
-
24
- it "should delegate the :list method to the collection" do
25
- Facter.collection.expects(:list)
26
- Facter.list
27
- end
28
-
29
- it "should load all facts when listing" do
30
- Facter.collection.expects(:load_all)
31
- Facter.collection.stubs(:list)
32
- Facter.list
33
- end
34
-
35
- it "should delegate the :to_hash method to the collection" do
36
- Facter.collection.expects(:to_hash)
37
- Facter.to_hash
38
- end
39
-
40
- it "should load all facts when calling :to_hash" do
41
- Facter.collection.expects(:load_all)
42
- Facter.collection.stubs(:to_hash)
43
- Facter.to_hash
44
- end
45
-
46
- it "should delegate the :value method to the collection" do
47
- Facter.collection.expects(:value)
48
- Facter.value
49
- end
50
-
51
- it "should delegate the :each method to the collection" do
52
- Facter.collection.expects(:each)
53
- Facter.each
54
- end
55
-
56
- it "should load all facts when calling :each" do
57
- Facter.collection.expects(:load_all)
58
- Facter.collection.stubs(:each)
59
- Facter.each
60
- end
61
-
62
- it "should yield to the block when using :each" do
63
- Facter.collection.stubs(:load_all)
64
- Facter.collection.stubs(:each).yields "foo"
65
- result = []
66
- Facter.each { |f| result << f }
67
- result.should == %w{foo}
68
- end
69
-
70
- describe "when provided code as a string" do
71
- it "should execute the code in the shell" do
72
- test_command = Facter::Util::Config.is_windows? ? 'cmd.exe /c echo yup' : 'echo yup'
73
- Facter.add("shell_testing") do
74
- setcode test_command
75
- end
76
-
77
- Facter["shell_testing"].value.should == "yup"
10
+ describe "methods on the collection" do
11
+ it "delegates the :flush method to the collection" do
12
+ Facter.collection.expects(:flush)
13
+ Facter.flush
78
14
  end
79
- end
80
15
 
81
- describe "when asked for a fact as an undefined Facter class method" do
82
- describe "and the collection is already initialized" do
83
- it "should return the fact's value" do
84
- Facter.collection
85
- Facter.ipaddress.should == Facter['ipaddress'].value
86
- end
16
+ it "delegates the :fact method to the collection" do
17
+ Facter.collection.expects(:fact).with("afact")
18
+ Facter.fact("afact")
87
19
  end
88
20
 
89
- describe "and the collection has been just reset" do
90
- it "should return the fact's value" do
91
- Facter.reset
92
- Facter.ipaddress.should == Facter['ipaddress'].value
93
- end
21
+ it "delegates the :list method to the collection" do
22
+ Facter.collection.expects(:list)
23
+ Facter.list
94
24
  end
95
- end
96
25
 
97
- describe "when passed code as a block" do
98
- it "should execute the provided block" do
99
- Facter.add("block_testing") { setcode { "foo" } }
100
-
101
- Facter["block_testing"].value.should == "foo"
26
+ it "loads all facts when listing" do
27
+ Facter.collection.expects(:load_all)
28
+ Facter.list
102
29
  end
103
- end
104
30
 
105
- describe "Facter[:hostname]" do
106
- it "should have its ldapname set to 'cn'" do
107
- Facter[:hostname].ldapname.should == "cn"
31
+ it "delegates the :to_hash method to the collection" do
32
+ Facter.collection.expects(:to_hash)
33
+ Facter.to_hash
108
34
  end
109
- end
110
35
 
111
- describe "Facter[:ipaddress]" do
112
- it "should have its ldapname set to 'iphostnumber'" do
113
- Facter[:ipaddress].ldapname.should == "iphostnumber"
36
+ it "loads all facts when calling :to_hash" do
37
+ Facter.collection.expects(:load_all)
38
+ Facter.collection.stubs(:to_hash)
39
+ Facter.to_hash
114
40
  end
115
- end
116
-
117
- # #33 Make sure we only get one mac address
118
- it "should only return one mac address" do
119
- if macaddress = Facter.value(:macaddress)
120
- macaddress.should_not be_include(" ")
121
- end
122
- end
123
-
124
- it "should have a method for registering directories to search" do
125
- Facter.should respond_to(:search)
126
- end
127
41
 
128
- it "should have a method for returning the registered search directories" do
129
- Facter.should respond_to(:search_path)
130
- end
131
-
132
- it "should have a method to query debugging mode" do
133
- Facter.should respond_to(:debugging?)
134
- end
135
-
136
- it "should have a method to query timing mode" do
137
- Facter.should respond_to(:timing?)
138
- end
139
-
140
- it "should have a method to show timing information" do
141
- Facter.should respond_to(:show_time)
142
- end
143
-
144
- it "should have a method to warn" do
145
- Facter.should respond_to(:warn)
146
- end
147
-
148
- describe "when warning" do
149
- it "should warn if debugging is enabled" do
150
- Facter.debugging(true)
151
- Kernel.stubs(:warn)
152
- Kernel.expects(:warn).with('foo')
153
- Facter.warn('foo')
42
+ it "delegates the :value method to the collection" do
43
+ Facter.collection.expects(:value).with("myvaluefact")
44
+ Facter.value("myvaluefact")
154
45
  end
155
46
 
156
- it "should not warn if debugging is enabled but nil is passed" do
157
- Facter.debugging(true)
158
- Kernel.stubs(:warn)
159
- Kernel.expects(:warn).never
160
- Facter.warn(nil)
47
+ it "delegates the :each method to the collection" do
48
+ Facter.collection.expects(:each)
49
+ Facter.each
161
50
  end
162
51
 
163
- it "should not warn if debugging is enabled but an empyt string is passed" do
164
- Facter.debugging(true)
165
- Kernel.stubs(:warn)
166
- Kernel.expects(:warn).never
167
- Facter.warn('')
52
+ it "delegates the :add method to the collection" do
53
+ Facter.collection.expects(:add).with("factname", {})
54
+ Facter.add("factname")
168
55
  end
169
56
 
170
- it "should not warn if debugging is disabled" do
171
- Facter.debugging(false)
172
- Kernel.stubs(:warn)
173
- Kernel.expects(:warn).never
174
- Facter.warn('foo')
57
+ it "delegates the :define_fact method to the collection" do
58
+ Facter.collection.expects(:define_fact).with("factname", {})
59
+ Facter.define_fact("factname")
175
60
  end
176
61
 
177
- it "should warn for any given element for an array if debugging is enabled" do
178
- Facter.debugging(true)
179
- Kernel.stubs(:warn)
180
- Kernel.expects(:warn).with('foo')
181
- Kernel.expects(:warn).with('bar')
182
- Facter.warn( ['foo','bar'])
62
+ it "loads all facts when calling :each" do
63
+ Facter.collection.expects(:load_all)
64
+ Facter.collection.stubs(:each)
65
+ Facter.each
183
66
  end
184
67
  end
185
68
 
186
- describe "when warning once" do
187
- it "should only warn once" do
188
- Kernel.stubs(:warnonce)
189
- Kernel.expects(:warn).with('foo').once
190
- Facter.warnonce('foo')
191
- Facter.warnonce('foo')
192
- end
69
+ it "yields to the block when using :each" do
70
+ Facter.collection.stubs(:load_all)
71
+ Facter.collection.stubs(:each).yields "foo"
72
+ result = []
73
+ Facter.each { |f| result << f }
74
+ result.should == %w{foo}
75
+ end
193
76
 
194
- it "should not warnonce if nil is passed" do
195
- Kernel.stubs(:warn)
196
- Kernel.expects(:warnonce).never
197
- Facter.warnonce(nil)
198
- end
77
+ describe "when registering directories to search" do
78
+ after { Facter.reset_search_path! }
199
79
 
200
- it "should not warnonce if an empty string is passed" do
201
- Kernel.stubs(:warn)
202
- Kernel.expects(:warnonce).never
203
- Facter.warnonce('')
80
+ it "allows registration of a directory" do
81
+ Facter.search "/my/dir"
204
82
  end
205
- end
206
83
 
207
- describe "when setting debugging mode" do
208
- it "should have debugging enabled using 1" do
209
- Facter.debugging(1)
210
- Facter.should be_debugging
211
- end
212
- it "should have debugging enabled using true" do
213
- Facter.debugging(true)
214
- Facter.should be_debugging
215
- end
216
- it "should have debugging enabled using any string except off" do
217
- Facter.debugging('aaaaa')
218
- Facter.should be_debugging
219
- end
220
- it "should have debugging disabled using 0" do
221
- Facter.debugging(0)
222
- Facter.should_not be_debugging
223
- end
224
- it "should have debugging disabled using false" do
225
- Facter.debugging(false)
226
- Facter.should_not be_debugging
227
- end
228
- it "should have debugging disabled using the string 'off'" do
229
- Facter.debugging('off')
230
- Facter.should_not be_debugging
84
+ it "allows registration of multiple directories" do
85
+ Facter.search "/my/dir", "/other/dir"
231
86
  end
232
- end
233
87
 
234
- describe "when setting timing mode" do
235
- it "should have timing enabled using 1" do
236
- Facter.timing(1)
237
- Facter.should be_timing
238
- end
239
- it "should have timing enabled using true" do
240
- Facter.timing(true)
241
- Facter.should be_timing
242
- end
243
- it "should have timing disabled using 0" do
244
- Facter.timing(0)
245
- Facter.should_not be_timing
246
- end
247
- it "should have timing disabled using false" do
248
- Facter.timing(false)
249
- Facter.should_not be_timing
88
+ it "returns all registered directories when asked" do
89
+ Facter.search "/my/dir", "/other/dir"
90
+ Facter.search_path.should == %w{/my/dir /other/dir}
250
91
  end
251
92
  end
252
93
 
253
- describe "when registering directories to search" do
254
- after { Facter.instance_variable_set("@search_path", []) }
255
-
256
- it "should allow registration of a directory" do
257
- Facter.search "/my/dir"
94
+ describe "when registering directories to search for external facts" do
95
+ it "allows registration of a directory" do
96
+ Facter.search_external ["/my/dir"]
258
97
  end
259
98
 
260
- it "should allow registration of multiple directories" do
261
- Facter.search "/my/dir", "/other/dir"
99
+ it "allows registration of multiple directories" do
100
+ Facter.search_external ["/my/dir", "/other/dir"]
262
101
  end
263
102
 
264
- it "should return all registered directories when asked" do
265
- Facter.search "/my/dir", "/other/dir"
266
- Facter.search_path.should == %w{/my/dir /other/dir}
103
+ it "returns all registered directories when asked" do
104
+ Facter.search_external ["/my/dir", "/other/dir"]
105
+ Facter.search_external_path.should include("/my/dir", "/other/dir")
267
106
  end
268
107
  end
269
108
  end