ruby on rails - Outputting HTTP request/response data with RSpec -


i have rails project serves json api tests written in rspec. when running specs (request specs, specifically), i’m interested in seeing details http request/response...i.e. request url, request body, , response body, ideally json pretty-formatted readability. isn't purposes of documentation rather part of development / debugging process.

i have helper method wrote this...you drop method call spec , prints stuff out.

but, seems better if there switch that’s part of running specs. rspec has custom formatters thought might right direction, in trying build one, can't figure out how access request/response objects can inside of spec.

how can access request/response objects in custom rspec formatter? or, perhaps way approach problem?

here's approach:

assuming rails project, in spec_helper.rb, define global "after" hook so:

config.after(:each) #runs after each example   if env['printhttp']     #use request/response objects here, e.g. puts response.status   end    end 

then, can conditionally enable adding environmental variable on command-line:

$ printhttp=1 rspec  

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -