0

I have a Rails app that serves up JSON, and want to test some code that request and process some json via http. What's the best way to test this code without stubbing http request-response?

I'm thinking of firing webrick to serve Rails app, but technically inept to do so. Any pointer to code example is 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' do
  before(:all) do
    # fire up webrick
  end
  after(:all) do
    # shutdown webrick
  end

  it 'bam' do
    hash = Bam.new.bam
    hash.should eq('bam' => 'bam')
  end
end
1

1 Answer 1

1

You can use airborne gem https://github.com/brooklynDev/airborne. Also you can compare JSON structure.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.