Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Allow asserting on requests in tests #1069

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add headers into the request
  • Loading branch information
johngallagher committed Sep 12, 2024
commit 88e96648d0f0a3ca7fbbef22a7085886b7c51d87
7 changes: 4 additions & 3 deletions lib/webmock/request_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ class RequestRegistry
attr_accessor :requested_signatures

class Request
attr_accessor :method, :uri
attr_accessor :method, :uri, :headers

def self.from_webmock_request_signature(request_signature)
new(method: request_signature.method, uri: request_signature.uri)
new(method: request_signature.method, uri: request_signature.uri, headers: request_signature.headers)
end

def initialize(method:, uri:)
def initialize(method:, uri:, headers:)
@method = method
@uri = uri
@headers = headers
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/unit/request_registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
expect(request_registry.requests_made[1].uri).to eq(Addressable::URI.parse("http://www.example.org/"))
end

it "parses the URL of the requests made" do
it "returns the headers of the request" do
request_registry = WebMock::RequestRegistry.instance
request_registry.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.com"))
expect(request_registry.requests_made.first.uri).to eq(Addressable::URI.parse("http://www.example.com/"))
request_registry.requested_signatures.put(WebMock::RequestSignature.new(:get, "www.example.com", headers: { 'Content-Type' => 'application/json' }))
expect(request_registry.requests_made.first.headers).to eq({ 'Content-Type' => 'application/json' })
end
end
end