Skip to content

Vacuum:Response body parsing in RSpec #92

@TheCorp

Description

@TheCorp

I am not sure what I am doing wrong here but I have a weird issue in my rspec tests, this is psuedocode but should give you an idea of what I am trying to do:

Code being tested

api_response = Vacuum::Request.new(all_the_usual_options).get_items(item_ids: [some_keys], resources: some_resources)
p api_response.parse

Test

VCR.use_cassette('some_VCR') do
    [Test that runs the Code block above]
end

When I run the test above the output of the print api_response.parse returns this error JSON::ParserError: Empty input () at line 1, column 0 [sparse.c:838] because the body value is blank on the first run of the test but returns results on all subsequent runs. There is no change in the actual contents of the VCR file between runs.

If I change my code to this, it works the first time:

api_response = Vacuum::Request.new(all_the_usual_options).get_items(item_ids: [some_keys], resources: some_resources)
p JSON.parse(api_response.body.to_s)

The closest I have come to understanding what's going on is that during one of my tests when I tried to just unload the entire Vacuum::Response object .to_json and it returned this error on the first run:

     HTTP::StateError:
       body has already been consumed

Any idea what I might be doing wrong here? I don't know if it matters but I did this using the Vacuum::Matcher as well as without it and it didn't seem to make a difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions