File: rack_spec.rb

package info (click to toggle)
puppet 3.7.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 18,896 kB
  • sloc: ruby: 210,387; sh: 2,050; xml: 1,554; lisp: 300; makefile: 142; python: 108; sql: 103; yacc: 72
file content (43 lines) | stat: -rwxr-xr-x 1,381 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/network/http/rack' if Puppet.features.rack?

describe "Puppet::Network::HTTP::Rack", :if => Puppet.features.rack? do
  describe "when called" do
    before :all do
      @app = Puppet::Network::HTTP::Rack.new()
      # let's use Rack::Lint to verify that we're OK with the rack specification
      @linted = Rack::Lint.new(@app)
    end

    before :each do
      @env = Rack::MockRequest.env_for('/')
    end

    it "should create a Request object" do
      request = Rack::Request.new(@env)
      Rack::Request.expects(:new).returns request
      @linted.call(@env)
    end

    it "should create a Response object" do
      Rack::Response.expects(:new).returns stub_everything
      @app.call(@env) # can't lint when Rack::Response is a stub
    end

    it "should let RackREST process the request" do
      Puppet::Network::HTTP::RackREST.any_instance.expects(:process).once
      @linted.call(@env)
    end

    it "should catch unhandled exceptions from RackREST" do
      Puppet::Network::HTTP::RackREST.any_instance.expects(:process).raises(ArgumentError, 'test error')
      Proc.new { @linted.call(@env) }.should_not raise_error
    end

    it "should finish() the Response" do
      Rack::Response.any_instance.expects(:finish).once
      @app.call(@env) # can't lint when finish is a stub
    end
  end
end