Skip to content

Pathname as json response body is not reading from file #1119

@jasonkarns

Description

@jasonkarns

Since #331, (v1.16), webmock has supported passing a Pathname as the stubbed response body.

This is fantastic for Rails, since file_fixture helper returns Pathnames.

However, passing Pathname as response body for to_return_json is currently not working.

As of v3.26.1:

    stub_request(:post, "https://api.taxjar.com/v2/taxes")
      .to_return_json(body: file_fixture("taxjar_tax.json"))

the stubbed response is coming back as the file path (presumably because of:

elsif !body.is_a?(String)
body.to_json

(It's calling .to_json on the Pathname and not going through the IO/.read flow.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions