public
Rubygem
Description: command line tweets and an api wrapper for twitter
Homepage: http://twitter.rubyforge.org/
Clone URL: git://github.com/jnunemaker/twitter.git
Click here to lend your support to: twitter and make a donation at www.pledgie.com !
twitter / spec / search_spec.rb
100644 89 lines (70 sloc) 2.971 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require File.dirname(__FILE__) + '/spec_helper.rb'
 
describe Twitter::Search do
  before do
    @search = Twitter::Search.new
  end
  
  it "should be able to initialize with a search term" do
    Twitter::Search.new('httparty').query[:q].should include('httparty')
  end
  
  it "should be able to specify from" do
    @search.from('jnunemaker').query[:q].should include('from:jnunemaker')
  end
  
  it "should be able to specify to" do
    @search.to('jnunemaker').query[:q].should include('to:jnunemaker')
  end
  
  it "should be able to specify referencing" do
    @search.referencing('jnunemaker').query[:q].should include('@jnunemaker')
  end
  
  it "should alias references to referencing" do
    @search.references('jnunemaker').query[:q].should include('@jnunemaker')
  end
  
  it "should alias ref to referencing" do
    @search.ref('jnunemaker').query[:q].should include('@jnunemaker')
  end
  
  it "should be able to specify containing" do
    @search.containing('milk').query[:q].should include('milk')
  end
  
  it "should alias contains to containing" do
    @search.contains('milk').query[:q].should include('milk')
  end
  
  it "should be able to specify hashed" do
    @search.hashed('twitter').query[:q].should include('#twitter')
  end
  
  it "should be able to specify the language" do
    @search.lang('en').query[:lang].should == 'en'
  end
  
  it "should be able to specify the number of results per page" do
    @search.per_page(25).query[:rpp].should == 25
  end
  
  it "should be able to specify only returning results greater than an id" do
    @search.since(1234).query[:since_id].should == 1234
  end
  
  it "should be able to specify geo coordinates" do
    @search.geocode('40.757929', '-73.985506', '25mi').query[:geocode].should == '40.757929,-73.985506,25mi'
  end
  
  it "should be able to clear the filters set" do
    @search.from('jnunemaker').to('oaknd1')
    @search.clear.query.should == {:q => []}
  end
  
  it "should be able to chain methods together" do
    @search.from('jnunemaker').to('oaknd1').referencing('orderedlist').containing('milk').hashed('twitter').lang('en').per_page(20).since(1234).geocode('40.757929', '-73.985506', '25mi')
    @search.query[:q].should == ['from:jnunemaker', 'to:oaknd1', '@orderedlist', 'milk', '#twitter']
    @search.query[:lang].should == 'en'
    @search.query[:rpp].should == 20
    @search.query[:since_id].should == 1234
    @search.query[:geocode].should == '40.757929,-73.985506,25mi'
  end
  
  describe "fetching" do
    before do
      @response = open(File.dirname(__FILE__) + '/fixtures/friends_timeline.xml').read
      @search.class.stub!(:get).and_return(@response)
    end
    
    it "should return results" do
      @search.class.should_receive(:get).and_return(@response)
      @search.from('jnunemaker').fetch().should == @response
    end
  end
  
  it "should be able to iterate over results" do
    @search.respond_to?(:each).should == true
  end
end