Sha256: 618cb4c953fd15a1a37079aec3dcf5161a23b15c902ee3fe828bb8d91907d32b

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

require 'helper'

describe Twitter::REST::API::Search do

  before do
    @client = Twitter::REST::Client.new(:consumer_key => "CK", :consumer_secret => "CS", :access_token => "AT", :access_token_secret => "AS")
  end

  describe "#search" do
    before do
      stub_get("/1.1/search/tweets.json").with(:query => {:q => "twitter"}).to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"})
    end
    it "requests the correct resource" do
      @client.search("twitter")
      expect(a_get("/1.1/search/tweets.json").with(:query => {:q => "twitter"})).to have_been_made
    end
    it "returns recent Tweets related to a query with images and videos embedded" do
      search = @client.search("twitter")
      expect(search).to be_a Twitter::SearchResults
      expect(search.first).to be_a Twitter::Tweet
      expect(search.first.text).to eq("Bubble Mailer #freebandnames")
    end
    it "returns the max_id value for a search result" do
      search = @client.search("twitter")
      expect(search.max_id).to eq(250126199840518145)
    end

    context "when search API responds a malformed result" do
      before do
        stub_get("/1.1/search/tweets.json").with(:query => {:q => "twitter"}).to_return(:body => fixture("search_malformed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
      end

      it "returns an empty array" do
        search = @client.search("twitter")
        expect(search.to_a).to be_an Array
        expect(search.to_a).to be_empty
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
twitter-5.1.1 spec/twitter/rest/api/search_spec.rb
twitter-5.1.0 spec/twitter/rest/api/search_spec.rb
twitter-5.0.1 spec/twitter/rest/api/search_spec.rb
twitter-5.0.0 spec/twitter/rest/api/search_spec.rb
twitter-5.0.0.rc.1 spec/twitter/rest/api/search_spec.rb