ruby - testing Rails json API -


i have rails app serves json, , want test code request , process json via http. what's best way test code without stubbing http request-response?

i'm thinking of firing webrick serve rails app, technically inept so. pointer code example appreciated.

# lib/bam.rb require 'open-uri'  class bam   def bam host='localhost'     hash = json.parse( open("http://#{host}/bam.json) )     # process hash   end end  # spec/bam_spec.rb rspec.describe 'bam'   before(:all)     # fire webrick   end   after(:all)     # shutdown webrick   end    'bam'     hash = bam.new.bam     hash.should eq('bam' => 'bam')   end end 

you can use airborne gem https://github.com/brooklyndev/airborne. can compare json structure.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -