1

I'm writing specs for a Rails controller that receives HTTP JSON requests, and returns a response to those requests. In my test suite, I'd like to have some fixtured HTTP requests that I can play back against my application.

Sample code:

context "when '/product/add' is requested" do
  subject do
    get '/product/add', fixtured_request # <-- This is some kind of recorded request
  end
  it do
    expect(subject).to have_http_status(200)
  end
end

Basically, I want VCR but in reverse, so I can play back a set of known requests in my specs to make sure my application is behaving as I expect.

  1. Can VCR record & playback inbound requests against my application?
  2. If it can, how can I record "inbound requests"?
  3. If it can't, is there a gem that can do something like this?

(Also, this guy is doing something similar, but it doesn't really mesh well with my test suite.)

David Elner
  • 5,091
  • 6
  • 33
  • 49
  • I'm not sure why you need to do this.. but did you try mounting your app in tests and treat it as an external service? In this case you can test it with VCR. – Hesham Aug 10 '15 at 00:07
  • If you build a JSON API, and you want to test specific request body content (e.g. a large, complex JSON object) how else would you do it? – David Elner Aug 10 '15 at 06:04
  • Maybe use FactoryGirl to build a JSON fixture for your request params like this example: http://stackoverflow.com/questions/25205545/building-a-json-stub-using-factorygirl? – Hesham Aug 10 '15 at 15:54

0 Answers0