Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 97 lines (74 sloc) 3.441 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 90 91 92 93 94 95 96
require 'helper'

describe Twitter::Client do
  Twitter::Configuration::VALID_FORMATS.each do |format|
    context ".new(:format => '#{format}')" do
      before do
        @client = Twitter::Client.new(:format => format, :consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
      end

      describe ".favorites" do

        context "with a screen name passed" do

          before do
            stub_get("favorites/sferik.#{format}").
              to_return(:body => fixture("favorites.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
          end

          it "should get the correct resource" do
            @client.favorites("sferik")
            a_get("favorites/sferik.#{format}").
              should have_been_made
          end

          it "should return the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter" do
            favorites = @client.favorites("sferik")
            favorites.should be_an Array
            favorites.first.user.name.should == "Zach Brock"
          end

        end

        context "without arguments passed" do

          before do
            stub_get("favorites.#{format}").
              to_return(:body => fixture("favorites.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
          end

          it "should get the correct resource" do
            @client.favorites
            a_get("favorites.#{format}").
              should have_been_made
          end

          it "should return the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter" do
            favorites = @client.favorites
            favorites.should be_an Array
            favorites.first.user.name.should == "Zach Brock"
          end

        end

      end

      describe ".favorite_create" do

        before do
          stub_post("favorites/create/25938088801.#{format}").
            to_return(:body => fixture("status.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
        end

        it "should get the correct resource" do
          @client.favorite_create(25938088801)
          a_post("favorites/create/25938088801.#{format}").
            should have_been_made
        end

        it "should return the favorite status when successful" do
          status = @client.favorite_create(25938088801)
          status.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
        end

      end

      describe ".favorite_destroy" do

        before do
          stub_delete("favorites/destroy/25938088801.#{format}").
            to_return(:body => fixture("status.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
        end

        it "should get the correct resource" do
          @client.favorite_destroy(25938088801)
          a_delete("favorites/destroy/25938088801.#{format}").
            should have_been_made
        end

        it "should return the un-favorite status when successful" do
          status = @client.favorite_destroy(25938088801)
          status.text.should == "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
        end
      end
    end
  end
end
Something went wrong with that request. Please try again.