NoMethodError: undefined method inject for String (when upgrading to 6.1.0)
Opened this issue · 3 comments
I've been working on upgrading my rails app from 4.2 to Rails 5.0. I also upgraded rspec_api_documentation
from 4.9.0 to 6.1.0 but I got this stack bomb when running my test suite. (I've included only the gem specific lines of the backtrace):
NoMethodError:
undefined method `inject' for #<String:0x00007fcdf10a91e8>
Did you mean? inspect
# /Users/tobit/.gem/ruby/2.4.4/gems/rspec_api_documentation-6.1.0/lib/rspec_api_documentation/dsl/endpoint.rb:170:in `extra_params'
# /Users/tobit/.gem/ruby/2.4.4/gems/rspec_api_documentation-6.1.0/lib/rspec_api_documentation/dsl/endpoint.rb:107:in `extended_parameters'
# /Users/tobit/.gem/ruby/2.4.4/gems/rspec_api_documentation-6.1.0/lib/rspec_api_documentation/dsl/endpoint.rb:41:in `do_request'
I rolled back to 4.9.0 and haven't had this issue.
+1 I'm seeing this too. For now I'm resolving it as commenting out the "Accept"
and "Content-Type"
. Just to make my tests pass. But my documentation is invalid.
I get the same error with rails (6.0.0)
and rspec_api_documentation (6.1.0)
.
I hit this today on a new project running rails 6.0.2
and rspec_api_documentation 6.1.0
We found one work around to define the raw_post
variable and call to_json
on it. (documentation)
let(:raw_post) {
{
user: { first_name: 'test' }
}.to_json
}
Further research found that the default request_body_formatter
is a Proc (source).
Adding the following to our config resolved the issue without the need to define raw_post
.
RspecApiDocumentation.configure do |config|
config.request_body_formatter = :json
end
That configuration setting can take :xml
or a Proc also:
# Change how the post body is formatted by default, you can still override by `raw_post`
# Can be :json, :xml, or a proc that will be passed the params
config.request_body_formatter = Proc.new { |params| params }