File: response_spec.rb

package info (click to toggle)
ruby-typhoeus 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 656 kB
  • sloc: ruby: 4,489; makefile: 6
file content (100 lines) | stat: -rw-r--r-- 2,327 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require 'spec_helper'

describe Typhoeus::Response do
  let(:response) { Typhoeus::Response.new(options) }
  let(:options) { {} }

  describe ".new" do
    context "when options" do
      context "when return_code" do
        let(:options) { {:return_code => 2} }

        it "stores" do
          expect(response.options[:return_code]).to be(2)
        end
      end

      context "when headers" do
        let(:options) { {:headers => {'A' => 'B'}} }

        it "stores unmodified" do
          expect(response.options[:headers]).to be(options[:headers])
        end

        it "sets @headers to a Typhoeus::Response::Header" do
          expect(response.instance_variable_get(:@headers)).to be_a(Typhoeus::Response::Header)
        end

        it "has key" do
          expect(response.headers['A']).to eq('B')
        end
      end
    end
  end

  describe "#mock" do
    context "when @mock" do
      before { response.mock = true }

      it "returns @mock" do
        expect(response.mock).to be_truthy
      end
    end

    context "when options[:mock]" do
      let(:options) { {:mock => true} }

      it "returns options[:mock]" do
        expect(response.mock).to be_truthy
      end
    end

    context "when @mock and options[:mock]" do
      let(:options) { {:mock => 1} }
      before { response.mock = 2 }

      it "returns @mock" do
        expect(response.mock).to be(2)
      end
    end
  end

  describe "#handled_response" do
    let(:handled_response) { Typhoeus::Response.new }

    context "when @handled_response" do
      before { response.handled_response = handled_response }

      it "returns @handled_response" do
        expect(response.handled_response).to be(handled_response)
      end
    end

    context "when @handled_response is nil" do
      before { response.handled_response = nil }

      it "returns response" do
        expect(response.handled_response).to be(response)
      end
    end
  end

  describe "#cached" do
    context "when @cached" do
      before { response.cached = true }

      it "returns cached status" do
        expect(response.cached?).to be_truthy
      end
    end

    context "when @cached is nil" do
      before { response.cached = nil }

      it "returns false" do
        expect(response.cached?).to be_falsey
      end
    end

  end
end