Sha256: 7b18c865aba04a8fbdea03cd67141eb85f9c016329f90dd41d6d5d9da9a175b2

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'uri'

describe Cafepress::Search::Client do
  before(:all) do
    @result_xml = File.read(File.join(File.dirname(__FILE__), '..', 'data', 'dog_search.xml'))
    Cafepress::Search::Client.base_url = "http://example.com"
  end

  before(:each) do
    @client = Cafepress::Search::Client.new('application key')
  end

  describe "#serch" do
    context "when the http interaction succeeds" do
      it "should request the appropriate search url" do
        query_url = 'http://example.com/product.search.cp?appKey=application%20key&query=dog'
        Net::HTTP.should_receive(:get).once.with(URI.parse(query_url)).and_return(@result_xml)
        @client.search('dog')
      end

      it "should return a search result set object" do
        Net::HTTP.stub!(:get).and_return(@result_xml)
        @client.search('dog').is_a?(Cafepress::Search::SearchResultSet).should be_true
      end
    end

    context "when the http interaction fails" do
      it "should raise an error" do
        Net::HTTP.stub!(:get).and_raise(Net::HTTPError)
        Proc.new { @client.search('beans') }.should raise_error
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cafepress-search-1.1.0 spec/cafepress-search/client_spec.rb
cafepress-search-1.0.2 spec/cafepress-search/client_spec.rb
cafepress-search-1.0.1 spec/cafepress-search/client_spec.rb
cafepress-search-1.0.0 spec/cafepress-search/client_spec.rb