spec/rubytter_spec.rb in rubytter-0.5.0 vs spec/rubytter_spec.rb in rubytter-0.6.0
- old
+ new
@@ -111,26 +111,27 @@
it 'should respond to search (1)' do
@rubytter.should_receive(:http_request) do |host, req, param_str|
req.path.should == '/search.json?q=test'
host.should == 'search.twitter.com'
+ {'results' => []}
end
@rubytter.search('test')
end
it 'should respond to search with params (1)' do
@rubytter.should_receive(:http_request) do |host, req, param_str|
req.path.should =~ /\/search.json\?/
req.path.should =~ /q=test/
req.path.should =~ /lang=ja/
+ {'results' => []}
end
@rubytter.search('test', :lang => 'ja')
end
it 'should respond to to_param_str' do
param_str = @rubytter.to_param_str(:page => 2, :foo => 'bar')
- p param_str
param_str.should =~ /^.+?=.+?&.+?=.+?$/
param_str.should =~ /page=2/
param_str.should =~ /foo=bar/
end
@@ -194,8 +195,49 @@
it 'should be set app_name' do
rubytter = Rubytter.new('test', 'teat', :app_name => "Foo")
rubytter.should_receive(:__update_status).with({:status => 'test', :source => "Foo"})
rubytter.update('test')
+ end
+
+ it 'should convert search results to struct' do
+ json_data = {
+ 'id' => '123',
+ 'text' => 'foo foo bar bar',
+ 'source' => '<a href="http:\/\/twitter.com\/">web<\/a>',
+ 'to_usre_id' => '20660692',
+ 'to_usre' => 'jugyo_test',
+ 'from_user_id' => '3748631',
+ 'from_user' => 'jugyo',
+ 'profile_image_url' => 'http://s3.amazonaws.com/twitter_production/profile_images/63467667/megane2_normal.png'
+ }
+ rubytter = Rubytter.new('test', 'teat')
+ result = rubytter.search_result_to_struct(json_data)
+ result['id'].should == '123'
+ result['text'].should == 'foo foo bar bar'
+ result['source'].should == "<a href=\"http:\\/\\/twitter.com\\/\">web<\\/a>"
+ result['in_reply_to_user_id'].should == '20660692'
+ result['in_reply_to_screen_name'].should == 'jugyo_test'
+ result['user']['id'].should == '3748631'
+ result['user']['screen_name'].should == 'jugyo'
+ result['user']['profile_image_url'].should == 'http://s3.amazonaws.com/twitter_production/profile_images/63467667/megane2_normal.png'
+ end
+
+ it 'should work search' do
+ json_data = JSON.parse open(File.dirname(__FILE__) + '/search.json').read
+
+ @rubytter.stub!(:http_request).and_return(json_data)
+ statuses = @rubytter.search('termtter')
+ status = statuses[0]
+
+ status.id.should == 1365281728
+ status.source.should == "<a href=\"http://twitter.com/\">web</a>"
+ status.text.should == "よし、add_hook 呼んでるところが無くなった #termtter"
+ status.in_reply_to_user_id.should == nil
+ status.in_reply_to_screen_name.should == nil
+ status.in_reply_to_status_id.should == nil
+ status.user.id.should == 74941
+ status.user.screen_name.should == "jugyo"
+ status.user.profile_image_url.should == "http://s3.amazonaws.com/twitter_production/profile_images/63467667/megane2_normal.png"
end
end
end