File: test_last_request.rb

package info (click to toggle)
ruby-fakeweb 1.3.0%2Bgit20170806%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 436 kB
  • sloc: ruby: 2,057; sh: 24; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 1,203 bytes parent folder | download | duplicates (6)
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
require 'test_helper'

class TestLastRequest < Test::Unit::TestCase

  def test_last_request_returns_correct_net_http_request_class
    FakeWeb.register_uri(:get, "http://example.com", :status => [200, "OK"])
    Net::HTTP.start("example.com") { |http| http.get("/") }
    assert_instance_of Net::HTTP::Get, FakeWeb.last_request
  end

  def test_last_request_has_correct_method_path_and_body_for_get
    FakeWeb.register_uri(:get, "http://example.com", :status => [200, "OK"])
    Net::HTTP.start("example.com") { |http| http.get("/") }
    assert_equal "GET", FakeWeb.last_request.method
    assert_equal "/", FakeWeb.last_request.path
    assert_nil FakeWeb.last_request.body
    assert_nil FakeWeb.last_request.content_length
  end

  def test_last_request_has_correct_method_path_and_body_for_post
    FakeWeb.register_uri(:post, "http://example.com/posts", :status => [201, "Created"])
    Net::HTTP.start("example.com") { |http| http.post("/posts", "title=Test") }
    assert_equal "POST", FakeWeb.last_request.method
    assert_equal "/posts", FakeWeb.last_request.path
    assert_equal "title=Test", FakeWeb.last_request.body
    assert_equal 10, FakeWeb.last_request.content_length
  end

end