spec/lib/agig/session_spec.rb in agig-0.1.5 vs spec/lib/agig/session_spec.rb in agig-0.2.0
- old
+ new
@@ -1,21 +1,77 @@
# coding: utf-8
require File.expand_path('../../../spec_helper', __FILE__)
+require 'logger'
describe Agig::Session do
+
+ let :log do
+ StringIO.new
+ end
+
+ let :oauth_token do
+ 'OAUTH_TOKEN_DUMMY'
+ end
+
before do
- @session = described_class.new('localhost', nil, nil)
+ octokit_client = Octokit::Client.new(oauth_token: oauth_token)
+ @session = described_class.new('localhost', nil, Logger.new(log))
+ @session.instance_variable_set(:@client, octokit_client)
end
+ describe '#retrieve' do
+ let :long_time_ago do
+ Time.parse('Jan 1 2010')
+ end
+
+ before do
+ allow(@session).to receive(:reachable_url_for).and_return('')
+
+ %w(/notifications?all=true /user/received_events).each do |path|
+ stub_request(:get, "https://api.github.com#{path}")
+ .to_return(
+ status: 200,
+ headers: { 'Content-Type' => 'application/json; charset=utf-8' },
+ body: open("#{fixture_path}#{path}.json").read)
+ end
+ end
+
+ context 'When notifications have not been retrieved for a long time' do
+ before do
+ @session.instance_variable_set(:@notification_last_retrieved, long_time_ago)
+ end
+
+ it do
+ expect(@session).to \
+ receive(:post).with(anything(), anything(), '#notification', anything())
+ .exactly(5).times
+ @session.send(:retrieve, 0)
+ end
+ end
+
+ context 'When watches have not been retrieved for a long time' do
+ before do
+ @session.instance_variable_set(:@watch_last_retrieved, long_time_ago)
+ end
+
+ it do
+ expect(@session).to \
+ receive(:post).with(anything(), anything(), '#watch', anything())
+ .exactly(2).times
+ @session.send(:retrieve, 0)
+ end
+ end
+ end
+
describe '#reachable_url_for' do
- subject { @session.reachable_url_for(latest_comment_url) }
+ subject { @session.send(:reachable_url_for, latest_comment_url) }
context 'When "https://api.github.com/repos/fastladder/fastladder/pulls/170" given' do
before do
- @session.stub_chain(:client, :issue_comments).and_return([])
+ allow(@session).to receive_message_chain(:client, :issue_comments).and_return([])
end
let(:latest_comment_url) { 'https://api.github.com/repos/fastladder/fastladder/pulls/170' }
- it { should eq('https://github.com/fastladder/fastladder/pull/170') }
+ it { is_expected.to eq('https://github.com/fastladder/fastladder/pull/170') }
end
end
end