Skip to content

Commit c05fe47

Browse files
committed
Split SAMPLE_REQUEST_HEADERS and SAMPLE_RESPONSE_HEADERS to be more realistic
1 parent 5f46eca commit c05fe47

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

spec/acceptance/shared/request_expectations.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,9 @@
536536
describe "when request with headers is expected" do
537537
it "should satisfy expectation if request was executed with the same headers" do
538538
expect {
539-
http_request(:get, "http://www.example.com/", headers: SAMPLE_HEADERS)
539+
http_request(:get, "http://www.example.com/", headers: SAMPLE_REQUEST_HEADERS)
540540
expect(a_request(:get, "www.example.com").
541-
with(headers: SAMPLE_HEADERS)).to have_been_made
541+
with(headers: SAMPLE_REQUEST_HEADERS)).to have_been_made
542542
}.not_to raise_error
543543
end
544544

@@ -578,7 +578,7 @@
578578

579579
it "should fail if request was executed with different headers" do
580580
expect {
581-
http_request(:get, "http://www.example.com/", headers: SAMPLE_HEADERS)
581+
http_request(:get, "http://www.example.com/", headers: SAMPLE_REQUEST_HEADERS)
582582
expect(a_request(:get, "www.example.com").
583583
with(headers: { 'Content-Length' => '9999'})).to have_been_made
584584
}.to fail_with(%r(The request GET http://www.example.com/ with headers \{'Content-Length'=>'9999'\} was expected to execute 1 time but it executed 0 times))
@@ -606,7 +606,7 @@
606606
expect {
607607
http_request(:post, "http://www.example.com/",
608608
body: "abc",
609-
headers: SAMPLE_HEADERS
609+
headers: SAMPLE_REQUEST_HEADERS
610610
)
611611
expect(a_request(:post, "www.example.com")).to have_been_made
612612
}.not_to raise_error

spec/acceptance/shared/returning_declared_responses.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def call(request)
6262
end
6363

6464
it "should return response with declared headers" do
65-
stub_request(:get, "www.example.com").to_return(headers: SAMPLE_HEADERS)
65+
stub_request(:get, "www.example.com").to_return(headers: SAMPLE_RESPONSE_HEADERS)
6666
response = http_request(:get, "http://www.example.com/")
67-
expect(response.headers["Accept"]).to eq("application/json")
67+
expect(response.headers["Content-Type"]).to eq("application/json")
6868
unless adapter_info.include?(:no_content_length_header)
6969
expect(response.headers["Content-Length"]).to eq("8888")
7070
end

spec/acceptance/shared/stubbing_requests.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@
366366

367367
describe "based on headers" do
368368
it "should match requests if headers are the same" do
369-
stub_request(:get, "www.example.com").with(headers: { "Accept" => "application/json" } )
369+
stub_request(:get, "www.example.com").with(headers: SAMPLE_REQUEST_HEADERS )
370370
expect(http_request(
371371
:get, "http://www.example.com/",
372-
headers: { "Accept" => "application/json" }).status).to eq("200")
372+
headers: SAMPLE_REQUEST_HEADERS).status).to eq("200")
373373
end
374374

375375
it "should match requests if headers are the same and declared as array" do
@@ -409,7 +409,7 @@
409409
stub_request(:get, "www.example.com")
410410
expect(http_request(
411411
:get, "http://www.example.com/",
412-
headers: SAMPLE_HEADERS).status).to eq("200")
412+
headers: SAMPLE_REQUEST_HEADERS).status).to eq("200")
413413
end
414414

415415
it "should not match requests if headers are different" do

spec/acceptance/webmock_shared.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
require 'acceptance/shared/precedence_of_stubs'
99
require 'acceptance/shared/complex_cross_concern_behaviors'
1010

11-
unless defined? SAMPLE_HEADERS
12-
SAMPLE_HEADERS = { "Accept" => "application/json" }
11+
unless defined? SAMPLE_REQUEST_HEADERS
12+
SAMPLE_REQUEST_HEADERS = { "Accept" => "application/json" }
13+
SAMPLE_RESPONSE_HEADERS = { "Content-Type" => "application/json", "Content-Length" => "8888" }
1314
ESCAPED_PARAMS = "x=ab%20c&z=%27Stop%21%27%20said%20Fred%20m"
1415
NOT_ESCAPED_PARAMS = "z='Stop!' said Fred m&x=ab c"
1516
end

0 commit comments

Comments
 (0)