0

I'm trying to customize stubs via Faraday and have a little problem with setting request_body and request_headers. All test works and are green, but I'm still getting message by Rubymine: „Found extra argument“ and that part of the code is underlined in red. I would like to get rid of it. Just how to customize body and headers in right way, please?

Actual problem

1

I have tried to customize it like this:

conn = Faraday.new(url: "url") do |faraday|
        faraday.response :raise_error
      end

conn.get("url") do |req|
  req.body: {body: "body"}
  req.headers: {headers: "headers"}
end

But it did not work.

vimuth
  • 5,064
  • 33
  • 79
  • 116
Pavel
  • 15
  • 3
  • Not sure what ruby mine is trying to tell you because your code is correct, could just be an issue with method reflection as it is very hard for the IDE to determine how to reflect in an interpreted dynamic language like ruby. Also those methods are defined dynamically which might be causing issues. [Source](https://github.com/lostisland/faraday/blob/v2.7.2/lib/faraday/connection.rb#L197) That being said your "customization" looks wrong. I think it should be `req.body = "body"` and `req.headers = {your: "headers"}`. – engineersmnky Jan 12 '23 at 14:05
  • Hi, thanks. :) But I'm still getting "TypeError: no implicit conversion of Array into String" if I'm trying it the second way. The problem line is `conn.get("url") do |req|`. – Pavel Jan 12 '23 at 14:20
  • If "body" is actually an `Array` you will need to call `to_json` e.g. `req.body = body.to_json`. There is nothing wrong with either way you are calling `conn.get` [`Faraday::Connection#get`](https://www.rubydoc.info/github/lostisland/faraday/Faraday/Connection#get-class_method) – engineersmnky Jan 12 '23 at 14:25

1 Answers1

1

Thank you for the feedback. This is a known problem, please follow the RUBY-30140/False-positive-found-extra-argument-warning-with-Faraday.get(see help if you are not familiar with YouTrack).

I've requested this issue to include in one of our nearest maintenance sprint. Sorry for inconveniences:(

Best regards Anna Kutarba.

JetBrains https://jetbrains.com The Drive to Develop

Rabodaber
  • 163
  • 2
  • 9