Sha256: 70a074345960fd8750b35e20df735b5476284fbe34a196f579042afd4c71a238

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'helper'

describe Recalls do
  before do
    Recalls.configure do |config|
      config.api_key = "badcheese"
    end
  end

  describe "search" do
    context "when a search returns a success" do
      before do
        stub_request(:get, "http://search.usa.gov/search/recalls/?format=json").
         with(:headers => {'Accept'=>'application/json'}).
         to_return(:status => 200, :body => fixture('recalls_search_response.json'), :headers => {})
      end
      
      it "should return a hash with the results" do
        response = Recalls.search
        response.is_a?(Hash).should be_true
        response["success"]["total"].should == 21840
      end
    end
    
    context "when a search returns an error" do
      before do
        stub_request(:get, "http://search.usa.gov/search/recalls/?format=json").
         with(:headers => {'Accept'=>'application/json'}).
         to_return(:status => 401, :body => "Invalid API Key", :headers => {})
      end
      
      it "should return an error" do
        response = Recalls.search
        response.is_a?(String).should be_true
        response.should == "Invalid API Key"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
recalls-0.1 spec/recalls_spec.rb
Recalls-0.1 spec/recalls_spec.rb