[Pkg-puppet-devel] [facter] 06/61: (maint) Fix mocha expectations crashing facter_spec
Stig Sandbeck Mathisen
ssm at debian.org
Mon Nov 4 15:01:38 UTC 2013
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository facter.
commit 603127523d1ff740f59ca966796813697dc19917
Author: Josh Partlow <joshua.partlow at puppetlabs.com>
Date: Mon Jul 8 16:13:37 2013 -0700
(maint) Fix mocha expectations crashing facter_spec
Running `bundle exec rspec spec/unit/util/virtual_spec.rb
spec/unit/facter_spec.rb` prior to this patch would crash rspec outright
while the test harness was still loading. This was because
virtual_spec.rb had expectations set in a shared_examples block but
outside of a before or it block. These then caused an expectation
failure when explicit calls to Facter[:foo] were used as the description
in two describe calls in facter_spec.
This patch clears up both those misuses of rspec, and also adds the
log_spec_order method from Puppet for future bisecting of spec order
issues in Facter...which hopefully we won't have to do. :)
---
spec/spec_helper.rb | 21 +++++++++++++++++++++
spec/unit/facter_spec.rb | 4 ++--
spec/unit/util/virtual_spec.rb | 13 +++++++++----
3 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 97fa072..b0d8566 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -17,6 +17,27 @@ Pathname.glob("#{dir}/shared_contexts/*.rb") do |file|
require file.relative_path_from(Pathname.new(dir))
end
+module LogSpecOrder
+ # Log the spec order to a file, but only if the LOG_SPEC_ORDER environment
+ # variable is set. This could be enabled on Jenkins runs, as it can
+ # be used with Nick L.'s bisect script to help identify and debug
+ # order-dependent spec failures.
+ #
+ # jpartlow 2013-07-05: this was in puppet and I pulled it into facter because
+ # I was seeing similar ordering issues in the specs...and needed to bisect them :/
+ def self.log_spec_order
+ if ENV['LOG_SPEC_ORDER']
+ File.open("./spec_order.txt", "w") do |logfile|
+ RSpec.configuration.files_to_run.each { |f| logfile.puts f }
+ end
+ end
+ end
+end
+
+# Executing here rather than after :suite, so that we can get the order output
+# even when the issue breaks rspec when specs are first loaded.
+LogSpecOrder.log_spec_order
+
RSpec.configure do |config|
config.mock_with :mocha
diff --git a/spec/unit/facter_spec.rb b/spec/unit/facter_spec.rb
index e86bfa4..3f9d086 100755
--- a/spec/unit/facter_spec.rb
+++ b/spec/unit/facter_spec.rb
@@ -102,13 +102,13 @@ describe Facter do
end
end
- describe Facter[:hostname] do
+ describe "Facter[:hostname]" do
it "should have its ldapname set to 'cn'" do
Facter[:hostname].ldapname.should == "cn"
end
end
- describe Facter[:ipaddress] do
+ describe "Facter[:ipaddress]" do
it "should have its ldapname set to 'iphostnumber'" do
Facter[:ipaddress].ldapname.should == "iphostnumber"
end
diff --git a/spec/unit/util/virtual_spec.rb b/spec/unit/util/virtual_spec.rb
index 2331142..f4dca6f 100755
--- a/spec/unit/util/virtual_spec.rb
+++ b/spec/unit/util/virtual_spec.rb
@@ -261,10 +261,15 @@ describe Facter::Util::Virtual do
end
shared_examples_for "virt-what" do |kernel, path, null_device|
- Facter.fact(:kernel).stubs(:value).returns(kernel)
- Facter::Util::Resolution.expects(:which).with("virt-what").returns(path)
- Facter::Util::Resolution.expects(:exec).with("#{path} 2>#{null_device}")
- Facter::Util::Virtual.virt_what
+ before(:each) do
+ Facter.fact(:kernel).stubs(:value).returns(kernel)
+ Facter::Util::Resolution.expects(:which).with("virt-what").returns(path)
+ Facter::Util::Resolution.expects(:exec).with("#{path} 2>#{null_device}")
+ end
+
+ it "on #{kernel} virt-what is at #{path} and stderr is sent to #{null_device}" do
+ Facter::Util::Virtual.virt_what
+ end
end
context "on linux" do
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git
More information about the Pkg-puppet-devel
mailing list