|
9 | 9 | before do |
10 | 10 | allow(Async::HTTP::Internet).to receive(:new).and_return(internet) |
11 | 11 | allow(internet).to receive(:get).and_return(http_response) |
| 12 | + allow(http_response).to receive(:read).and_return(job_data) |
12 | 13 | end |
13 | 14 |
|
14 | 15 | it "can instantiate" do |
|
29 | 30 | hash_including("User-Agent" => user_agent) |
30 | 31 | ) |
31 | 32 | end |
| 33 | + |
| 34 | + context "when providing a custom user agent" do |
| 35 | + before { described_class.new(user_agent: "lovely-user-agent").with_fetch } |
| 36 | + |
| 37 | + it "sends the custom user agent instead of the default" do |
| 38 | + expect(internet).to have_received(:get).with( |
| 39 | + instance_of(URI::HTTPS), |
| 40 | + hash_including("User-Agent" => "lovely-user-agent") |
| 41 | + ) |
| 42 | + end |
| 43 | + end |
32 | 44 | end |
33 | 45 |
|
34 | 46 | # rubocop:disable RSpec/MultipleExpectations |
|
48 | 60 | expect(uri.query).to include("tags=ruby%2Cdigital+nomad") |
49 | 61 | end |
50 | 62 | end |
| 63 | + |
| 64 | + it "returns an array of Job objects" do |
| 65 | + expect(client.jobs.first).to be_a(RemoteOK::Job) |
| 66 | + end |
| 67 | + |
| 68 | + it "returns the correct number of items" do |
| 69 | + expect(client.jobs.size).to eq(3) |
| 70 | + end |
51 | 71 | end |
52 | 72 | # rubocop:enable RSpec/MultipleExpectations |
53 | 73 |
|
|
57 | 77 |
|
58 | 78 | expect(legal_info).to eq(JSON.parse(job_data).first["legal"]) |
59 | 79 | end |
| 80 | + |
| 81 | + it "can be chained with fetch to force refresh" do |
| 82 | + legal_info = client.with_fetch.legal |
| 83 | + |
| 84 | + expect(legal_info).to eq(JSON.parse(job_data).first["legal"]) |
| 85 | + end |
60 | 86 | end |
61 | | - # let(:job_data) { File.open "spec/fixtures/jobs_data.json" } |
62 | | - |
63 | | - # before do |
64 | | - # instance_double("HTTParty", body: job_data.read) |
65 | | - # allow(described_class).to receive(:get).and_return(httpclient) |
66 | | - # end |
67 | | - |
68 | | - # it "can instantiate" do |
69 | | - # expect(described_class.new).not_to be_nil |
70 | | - # end |
71 | | - |
72 | | - # describe "User Agent" do |
73 | | - # it "sends a default user agent with each request" do |
74 | | - # httpclient = double("HTTParty", body: "{}") |
75 | | - # exp_params = { |
76 | | - # headers: { |
77 | | - # "User-Agent" => |
78 | | - # "remote-ok-ruby/0.1.0 +http://github.com/RemoteCTO/remote-ok-ruby" |
79 | | - # } |
80 | | - # } |
81 | | - |
82 | | - # expect(described_class).to( |
83 | | - # receive(:get) |
84 | | - # .with(anything, exp_params) |
85 | | - # .and_return(httpclient) |
86 | | - # ) |
87 | | - |
88 | | - # described_class.new.jobs |
89 | | - # end |
90 | | - |
91 | | - # context "when providing a custom user agent" do |
92 | | - # it "sends the custom user agent instead of the default" do |
93 | | - # httpclient = double("HTTParty", body: "{}") |
94 | | - # exp_params = {headers: {"User-Agent" => "lovely-user-agent"}} |
95 | | - |
96 | | - # expect(described_class).to( |
97 | | - # receive(:get) |
98 | | - # .with(anything, exp_params) |
99 | | - # .and_return(httpclient) |
100 | | - # ) |
101 | | - |
102 | | - # described_class.new(user_agent: "lovely-user-agent").jobs |
103 | | - # end |
104 | | - # end |
105 | | - # end |
106 | | - |
107 | | - # context "Debug flag on" do |
108 | | - # it "Requests HTTP debug output into the console" do |
109 | | - # httpclient = double("HTTParty", body: "{}") |
110 | | - # exp_params = { |
111 | | - # headers: {"User-Agent" => ""}, |
112 | | - # debug_output: $stdout |
113 | | - # } |
114 | | - |
115 | | - # expect(described_class).to( |
116 | | - # receive(:get) |
117 | | - # .with(anything, exp_params) |
118 | | - # .and_return(httpclient) |
119 | | - # ) |
120 | | - |
121 | | - # described_class.new(user_agent: "", debug: true).jobs |
122 | | - # end |
123 | | - # end |
124 | | - |
125 | | - # describe "legal" do |
126 | | - # it "outputs the RemoteOK legal text" do |
127 | | - # expect(described_class.new.legal).to start_with "API Terms of Service" |
128 | | - # end |
129 | | - |
130 | | - # it "can be chained with fetch to force refresh" do |
131 | | - # expect(described_class.new.with_fetch.legal).to start_with "API Terms of Service" |
132 | | - # end |
133 | | - # end |
134 | | - |
135 | | - # describe "jobs" do |
136 | | - # it "returns the correct number of items" do |
137 | | - # expect(described_class.new.jobs.size).to eq 3 |
138 | | - # end |
139 | | - |
140 | | - # it "returns an array of Job objects" do |
141 | | - # expect(described_class.new.jobs.first).to be_a RemoteOK::Job |
142 | | - # end |
143 | | - |
144 | | - # context "when there are no jobs" do |
145 | | - # before do |
146 | | - # nj_data = File.open "spec/fixtures/no_jobs.json" |
147 | | - # httpclient = double("HTTParty", body: nj_data.read) |
148 | | - # allow(described_class).to receive(:get).and_return(httpclient) |
149 | | - # end |
150 | | - |
151 | | - # it "returns zero jobs" do |
152 | | - # expect(described_class.new.jobs.size).to eq 0 |
153 | | - # end |
154 | | - # end |
155 | | - |
156 | | - # context "when providing tags" do |
157 | | - # let(:data) { File.open "spec/fixtures/jobs_data.json" } |
158 | | - # let(:http_client) { double("HTTParty", body: data.read) } |
159 | | - |
160 | | - # it "provides the tags as parameters to the api" do |
161 | | - # httpclient = double("HTTParty", body: data.read) |
162 | | - # exp_params = { |
163 | | - # headers: {"User-Agent" => ""}, |
164 | | - # query: {tags: "ruby,digital nomad"} |
165 | | - # } |
166 | | - |
167 | | - # expect(described_class).to( |
168 | | - # receive(:get) |
169 | | - # .with(anything, exp_params) |
170 | | - # .and_return(httpclient) |
171 | | - # ) |
172 | | - |
173 | | - # described_class.new(user_agent: "").jobs :ruby, :digital_nomad |
174 | | - # end |
175 | | - # end |
176 | | - # end |
177 | 87 | end |
0 commit comments