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

Using VCR to stub requests #171

Open
coreyward opened this issue Feb 27, 2016 · 0 comments
Open

Using VCR to stub requests #171

coreyward opened this issue Feb 27, 2016 · 0 comments

Comments

@coreyward
Copy link
Contributor

I was having issues w/ VCR not recording cassettes when using JsonApiClient, despite the Faraday underpinnings. The issue appears to be the following lines in connection.rb:

    # insert middleware before ParseJson - middleware executed in reverse order -
    #   inserted middleware will run after json parsed
    def use(middleware, *args, &block)
      return if faraday.builder.locked?
      faraday.builder.insert_before(Middleware::ParseJson, middleware, *args, &block)
    end

Because Connection wraps the Faraday connection, I believe the VCR-provided hook_into :faraday was ineffective. Adding the middleware manually using connection.use VCR::Middleware::Faraday results in an ArgumentError: VCR::Response initialized with an invalid body: <Hash …>.

The solution, for me, was to insert the VCR middleware after Middleware::ParseJson:

VCR.configure do
  faraday = API::Base.connection.faraday
  faraday.builder.insert_after(JsonApiClient::Middleware::ParseJson, VCR::Middleware::Faraday)
end

Note: API::Base in the example above inherits from JsonApiClient::Resource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant