Skip to content

Commit

Permalink
Support :as option
Browse files Browse the repository at this point in the history
  • Loading branch information
rsamoilov committed Feb 19, 2024
1 parent 092147e commit ecf7677
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/rage/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ def #{method_name}(path, params: {}, headers: {})

%w(post put patch delete).each do |method_name|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
def #{method_name}(path, params: {}, headers: {})
def #{method_name}(path, params: {}, headers: {}, as: nil)
if as == :json
params = params.to_json
headers["content-type"] = "application/json"
end
request("#{method_name.upcase}", path, params: params, headers: headers.merge("IODINE_HAS_BODY" => !params.empty?))
end
RUBY
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def subdomain
post "/params", params: { i: "444" }
expect(response.body).to eq("444")

post "/params", params: { i: "555" }.to_json, headers: { "content-type" => "application/json" }
post "/params", params: { i: "555" }, as: :json
expect(response.body).to eq("555")
end

Expand Down

0 comments on commit ecf7677

Please sign in to comment.