File: test_commands_serve_servlet.rb

package info (click to toggle)
jekyll 3.9.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,604 kB
  • sloc: ruby: 15,325; javascript: 1,455; sh: 214; xml: 29; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 965 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
# frozen_string_literal: true

require "webrick"
require "helper"
require "net/http"

class TestCommandsServeServlet < JekyllUnitTest
  def get(path)
    TestWEBrick.mount_server do |_server, addr, port|
      http = Net::HTTP.new(addr, port)
      req = Net::HTTP::Get.new(path)

      http.request(req) { |response| yield(response) }
    end
  end

  context "with a directory and file with the same name" do
    should "find that file" do
      get("/bar/") do |response|
        assert_equal("200", response.code)
        assert_equal("Content of bar.html", response.body.strip)
      end
    end

    should "find file in directory" do
      get("/bar/baz") do |response|
        assert_equal("200", response.code)
        assert_equal("Content of baz.html", response.body.strip)
      end
    end

    should "return 404 for non-existing files" do
      get("/bar/missing") do |response|
        assert_equal("404", response.code)
      end
    end
  end
end