Sha256: e90a00db8283fc1fbb4e11330b36ae59fc3a2a4b57c457a2eeb204e58f3bfd3a

Contents?: true

Size: 1.91 KB

Versions: 14

Compression:

Stored size: 1.91 KB

Contents

require 'helper'

describe Twitter::RateLimit do

  describe '#limit' do
    it 'returns an Integer when x-rate-limit-limit header is set' do
      rate_limit = Twitter::RateLimit.new('x-rate-limit-limit' => '150')
      expect(rate_limit.limit).to be_an Integer
      expect(rate_limit.limit).to eq(150)
    end
    it 'returns nil when x-rate-limit-limit header is not set' do
      rate_limit = Twitter::RateLimit.new
      expect(rate_limit.limit).to be_nil
    end
  end

  describe '#remaining' do
    it 'returns an Integer when x-rate-limit-remaining header is set' do
      rate_limit = Twitter::RateLimit.new('x-rate-limit-remaining' => '149')
      expect(rate_limit.remaining).to be_an Integer
      expect(rate_limit.remaining).to eq(149)
    end
    it 'returns nil when x-rate-limit-remaining header is not set' do
      rate_limit = Twitter::RateLimit.new
      expect(rate_limit.remaining).to be_nil
    end
  end

  describe '#reset_at' do
    it 'returns a Time when x-rate-limit-reset header is set' do
      rate_limit = Twitter::RateLimit.new('x-rate-limit-reset' => '1339019097')
      expect(rate_limit.reset_at).to be_a Time
      expect(rate_limit.reset_at).to eq(Time.at(1_339_019_097))
    end
    it 'returns nil when x-rate-limit-reset header is not set' do
      rate_limit = Twitter::RateLimit.new
      expect(rate_limit.reset_at).to be_nil
    end
  end

  describe '#reset_in' do
    before do
      Timecop.freeze(Time.utc(2012, 6, 6, 17, 22, 0))
    end
    after do
      Timecop.return
    end
    it 'returns an Integer when x-rate-limit-reset header is set' do
      rate_limit = Twitter::RateLimit.new('x-rate-limit-reset' => '1339019097')
      expect(rate_limit.reset_in).to be_an Integer
      expect(rate_limit.reset_in).to eq(15_777)
    end
    it 'returns nil when x-rate-limit-reset header is not set' do
      rate_limit = Twitter::RateLimit.new
      expect(rate_limit.reset_in).to be_nil
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
twitter-5.11.0 spec/twitter/rate_limit_spec.rb
twitter-5.10.0 spec/twitter/rate_limit_spec.rb
twitter-5.9.0 spec/twitter/rate_limit_spec.rb
twitter-5.8.0 spec/twitter/rate_limit_spec.rb
twitter-5.7.1 spec/twitter/rate_limit_spec.rb
twitter-5.7.0 spec/twitter/rate_limit_spec.rb
twitter-5.6.0 spec/twitter/rate_limit_spec.rb
twitter-5.5.1 spec/twitter/rate_limit_spec.rb
twitter-5.5.0 spec/twitter/rate_limit_spec.rb
twitter-5.4.1 spec/twitter/rate_limit_spec.rb
twitter-5.4.0 spec/twitter/rate_limit_spec.rb
twitter-5.3.1 spec/twitter/rate_limit_spec.rb
twitter-5.3.0 spec/twitter/rate_limit_spec.rb
twitter-5.2.0 spec/twitter/rate_limit_spec.rb