diff options
author | Rein Henrichs <rein@puppetlabs.com> | 2010-06-25 14:36:40 -0700 |
---|---|---|
committer | Jesse Wolfe <jes5199@gmail.com> | 2010-06-25 18:14:58 -0700 |
commit | 4ef40b88f246a6c158cc3ea91ea44dc941d4ac41 (patch) | |
tree | 263d9aad2bfff94cd3e9039a9ee9d5c83e3a879a | |
parent | edfcbf94cf44170f9aa8bcc8a330d323f0701abb (diff) | |
download | puppet-4ef40b88f246a6c158cc3ea91ea44dc941d4ac41.tar.gz puppet-4ef40b88f246a6c158cc3ea91ea44dc941d4ac41.tar.xz puppet-4ef40b88f246a6c158cc3ea91ea44dc941d4ac41.zip |
maint: Rework testing of Reports http processor to be self contained
* do not monkey patch Net::HTTP in a way that breaks other specs
* Use fakes to sense behavior of Net::HTTP
-rw-r--r-- | spec/unit/reports/http_spec.rb | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/spec/unit/reports/http_spec.rb b/spec/unit/reports/http_spec.rb index 2c7c32c18..cc7346467 100644 --- a/spec/unit/reports/http_spec.rb +++ b/spec/unit/reports/http_spec.rb @@ -4,25 +4,39 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f require 'puppet/reports' -class Net::HTTP +# FakeHTTP fakes the behavior of Net::HTTP#request and acts as a sensor for an +# otherwise difficult to trace method call. +# +class FakeHTTP REQUESTS = {} - alias_method :old_request, :request - def request(req, body=nil, &block) + def self.request(req) REQUESTS[req.path] = req - old_request(req, body, &block) end end processor = Puppet::Reports.report(:http) describe processor do + before { Net::HTTP.any_instance.stubs(:start).yields(FakeHTTP) } subject { Puppet::Transaction::Report.new.extend(processor) } it { should respond_to(:process) } + it "should use the reporturl setting's host and port" do + uri = URI.parse(Puppet[:reporturl]) + Net::HTTP.expects(:new).with(uri.host, uri.port).returns(stub_everything('http')) + subject.process + end + describe "request" do before { subject.process } + describe "path" do + it "should use the path specified by the 'reporturl' setting" do + reports_request.path.should == URI.parse(Puppet[:reporturl]).path + end + end + describe "body" do it "should be the report as YAML" do reports_request.body.should == subject.to_yaml @@ -38,5 +52,5 @@ describe processor do private - def reports_request; Net::HTTP::REQUESTS[URI.parse(Puppet[:reporturl]).path] end + def reports_request; FakeHTTP::REQUESTS[URI.parse(Puppet[:reporturl]).path] end end |