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
Post a Comment