File: rack_double.rb

package info (click to toggle)
ruby-bullet 7.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 836 kB
  • sloc: ruby: 6,133; javascript: 57; sh: 27; makefile: 4
file content (49 lines) | stat: -rw-r--r-- 716 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
# frozen_string_literal: true

module Support
  class AppDouble
    def call(_env)
      env = @env
      [status, headers, response]
    end

    attr_writer :status

    attr_writer :headers

    def headers
      @headers ||= { 'Content-Type' => 'text/html' }
      @headers
    end

    attr_writer :response

    private

    def status
      @status || 200
    end

    def response
      @response || ResponseDouble.new
    end
  end

  class ResponseDouble
    def initialize(actual_body = nil)
      @actual_body = actual_body
    end

    def body
      @body ||= '<html><head></head><body></body></html>'
    end

    attr_writer :body

    def each
      yield body
    end

    def close; end
  end
end