croudia 0.0.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/README.md +31 -14
  4. data/Rakefile +11 -11
  5. data/croudia.gemspec +10 -8
  6. data/lib/croudia/api/favorites.rb +43 -0
  7. data/lib/croudia/api/oauth.rb +32 -0
  8. data/lib/croudia/api/statuses.rb +55 -0
  9. data/lib/croudia/api/timelines.rb +57 -0
  10. data/lib/croudia/base.rb +44 -0
  11. data/lib/croudia/client.rb +64 -0
  12. data/lib/croudia/configurable.rb +39 -0
  13. data/lib/croudia/creatable.rb +9 -0
  14. data/lib/croudia/default.rb +63 -0
  15. data/lib/croudia/ext/openssl.rb +19 -0
  16. data/lib/croudia/identity.rb +22 -39
  17. data/lib/croudia/status.rb +26 -0
  18. data/lib/croudia/user.rb +12 -43
  19. data/lib/croudia/version.rb +1 -1
  20. data/lib/croudia.rb +21 -12
  21. data/spec/croudia/api/favorites_spec.rb +35 -0
  22. data/spec/croudia/api/oauth_spec.rb +53 -0
  23. data/spec/croudia/api/statuses_spec.rb +73 -0
  24. data/spec/croudia/api/timelines_spec.rb +93 -0
  25. data/spec/croudia/base_spec.rb +27 -0
  26. data/spec/croudia/client_spec.rb +115 -0
  27. data/spec/croudia/identity_spec.rb +29 -65
  28. data/spec/croudia/status_spec.rb +30 -0
  29. data/spec/croudia/user_spec.rb +30 -43
  30. data/spec/croudia_spec.rb +48 -49
  31. data/spec/fixtures/access_token.json +6 -0
  32. data/spec/fixtures/status.json +1 -0
  33. data/spec/fixtures/timeline.json +1 -0
  34. data/spec/helper.rb +49 -32
  35. metadata +80 -84
  36. data/lib/croudia/api.rb +0 -5
  37. data/lib/croudia/error.rb +0 -5
  38. data/lib/croudia/scraper/friendships.rb +0 -72
  39. data/lib/croudia/scraper/login.rb +0 -42
  40. data/lib/croudia/scraper/parser/users.rb +0 -59
  41. data/lib/croudia/scraper/parser/voices.rb +0 -32
  42. data/lib/croudia/scraper/parser.rb +0 -13
  43. data/lib/croudia/scraper/users.rb +0 -20
  44. data/lib/croudia/scraper/voices.rb +0 -59
  45. data/lib/croudia/scraper.rb +0 -63
  46. data/lib/croudia/voice.rb +0 -21
  47. data/spec/croudia/api_spec.rb +0 -7
  48. data/spec/croudia/error_spec.rb +0 -13
  49. data/spec/croudia/scraper/friendships_spec.rb +0 -115
  50. data/spec/croudia/scraper/login_spec.rb +0 -137
  51. data/spec/croudia/scraper/parser/users_spec.rb +0 -292
  52. data/spec/croudia/scraper/parser/voices_spec.rb +0 -119
  53. data/spec/croudia/scraper/users_spec.rb +0 -78
  54. data/spec/croudia/scraper/voices_spec.rb +0 -178
  55. data/spec/croudia/scraper_spec.rb +0 -120
  56. data/spec/croudia/version_spec.rb +0 -7
  57. data/spec/croudia/voice_spec.rb +0 -16
  58. data/spec/fixtures/follow_request.html +0 -69
  59. data/spec/fixtures/follower_wktk.html +0 -89
  60. data/spec/fixtures/following_wktk.html +0 -89
  61. data/spec/fixtures/user_wktk1.html +0 -72
  62. data/spec/fixtures/user_wktk2.html +0 -75
  63. data/spec/fixtures/user_wktk3.html +0 -83
  64. data/spec/fixtures/voices_reply_list.html +0 -55
  65. data/spec/fixtures/voices_timeline.html +0 -60
  66. data/spec/fixtures/voices_written.html +0 -20
@@ -1,72 +0,0 @@
1
- module Croudia
2
- class Scraper
3
- module Friendships
4
- def follow(username)
5
- require_login
6
- post('/follows/target_follow',
7
- :target_user_name => username,
8
- :follow_action => 'enable',
9
- )
10
- end
11
-
12
- def unfollow(username)
13
- require_login
14
- post('/follows/target_follow',
15
- :target_user_name => username,
16
- :follow_action => 'diable', # Yes, it is!
17
- )
18
- end
19
-
20
- def approve(username)
21
- require_login
22
- post('/follows/follow_approve',
23
- :target_user_name => username,
24
- :follow_action => 'approve',
25
- )
26
- end
27
-
28
- def refusal(username)
29
- require_login
30
- post('/follows/follow_refusal',
31
- :target_user_name => username,
32
- :follow_action => 'refusal',
33
- )
34
- end
35
- alias refuse refusal
36
-
37
- def block(username)
38
- require_login
39
- post('/blocks/setting',
40
- :target_user_name => username,
41
- :block_action => 'enable',
42
- )
43
- end
44
-
45
- def unblock(username)
46
- require_login
47
- post('/blocks/setting',
48
- :target_user_name => username,
49
- :block_action => 'diable', # Yes, it's diable
50
- )
51
- end
52
-
53
- def following(username=nil, params={})
54
- username = @current_user.username unless username
55
- Parser.user_list(get("/follows/following/#{username}", params))
56
- end
57
- alias followings following
58
-
59
- def follower(username=nil, params={})
60
- username = @current_user.username unless username
61
- Parser.user_list(get("/follows/follower/#{username}", params))
62
- end
63
- alias followers follower
64
-
65
- def follow_request
66
- require_login
67
- Parser.user_list(get('/follows/follow_request'))
68
- end
69
- alias follow_requests follow_request
70
- end
71
- end
72
- end
@@ -1,42 +0,0 @@
1
- require 'croudia/error'
2
-
3
- module Croudia
4
- class Scraper
5
- module Login
6
- def login(username, password)
7
- get('/')
8
- params = {
9
- :username => username,
10
- :password => password,
11
- :auto_login => 'on',
12
- }
13
- post('/', params)
14
- raise ArgumentError, 'Wrong ID or password' if not logged_in?
15
- end
16
- alias login! login
17
-
18
- def logout
19
- require_login
20
- post('/login/logout', :method_name => 'logout')
21
- @current_user = nil
22
- @logged_in = false
23
- end
24
- alias logout! logout
25
-
26
- def logged_in?(force=false)
27
- @logged_in = nil if force
28
- @logged_in = @logged_in.nil? ? '/' != get('/').uri.path : @logged_in
29
- end
30
- alias logged_in logged_in?
31
-
32
- def logged_out?(force=false)
33
- !logged_in?(force)
34
- end
35
- alias logged_out logged_out?
36
-
37
- def require_login
38
- raise NotLoggedInError, 'Not logged in' if logged_out?
39
- end
40
- end
41
- end
42
- end
@@ -1,59 +0,0 @@
1
- module Croudia
2
- class Scraper
3
- module Parser
4
- module Users
5
- def user_page(page)
6
- return nil if /on Croudia$/ !~ page.title
7
- doc = page.parser
8
- attrs = {
9
- :username => doc.xpath('//a[contains(@href, "/voices/user/")]').first.attribute('href').content.sub(%r{^/voices/user/}, ''),
10
- :nickname => doc.css('.avatar_l').first.attribute('alt').content,
11
- :avatar => "#{page.uri.scheme}://#{page.uri.host}" + doc.css('.avatar_l').first.attribute('src').content,
12
- :self_introduction => doc.css('.fontg').first.content.strip,
13
- :voices_count => doc.xpath('//span[preceding-sibling::a[contains(@href,"/voices/user/")]]').first.content,
14
- :following_count => doc.xpath('//span[preceding-sibling::a[contains(@href,"/following/")]]').first.content,
15
- :followers_count => doc.xpath('//span[preceding-sibling::a[contains(@href,"/follower/")]]').first.content,
16
- :album_count => doc.xpath('//span[preceding-sibling::a[contains(@href,"/album")]]').first.content,
17
- :spreadia => doc.xpath('//span[preceding-sibling::a[contains(@href,"/spreadia/")]]').first.content,
18
- :favodia => doc.xpath('//span[preceding-sibling::a[contains(@href,"/favodia/")]]').first.content,
19
- }
20
- if (location = doc.xpath('//a[contains(@href, "/users/google_maps")]')).size.nonzero?
21
- attrs[:position] = location.first.content
22
- end
23
- if (url = doc.xpath('//a[@target="_blank"][name(..)="li"]')).size.nonzero?
24
- attrs[:user_url] = url.first.content
25
- end
26
- if (friendships = doc.css('.font1')).size.nonzero?
27
- attrs[:following] = /#e/i !~ friendships[0].attribute('style').value
28
- attrs[:followed_by] = /#e/i !~ friendships[1].attribute('style').value
29
- end
30
- Croudia::User.new(attrs)
31
- end
32
-
33
- def user_list(page)
34
- user_nodes = page.parser.xpath('//div[@data-role="content"]/ul[@data-role="listview"]/li[not(@data-role="list-divider")]')
35
- users = []
36
- user_nodes.each do |user_node|
37
- attrs = {
38
- :nickname => user_node.css('.bord').first.content,
39
- :avatar => "#{page.uri.scheme}://#{page.uri.host}" + user_node.css('img').first.attribute('src').value,
40
- :self_introduction => user_node.css('.fontg').first.content.strip,
41
- }
42
- if (links = user_node.css('a')).size.nonzero?
43
- # For following/followers page
44
- attrs[:username] = links.first.attribute('href').value.sub(%r{^/}, '')
45
- elsif (forms = user_node.xpath('//form[not(contains(@action,"/follows/"))]')).size.nonzero?
46
- # For follow_request page
47
- attrs[:username] = forms.first.attribute('action').value.sub(%r{^/}, '')
48
- end
49
- if (following = user_node.css('.font1')).size.nonzero?
50
- attrs[:following] = /#e/i !~ following.first.attribute('style').value
51
- end
52
- users << Croudia::User.new(attrs)
53
- end
54
- users
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,32 +0,0 @@
1
- module Croudia
2
- class Scraper
3
- module Parser
4
- module Voices
5
- def voices(page)
6
- voice_nodes = page.parser.xpath('//div[@data-role="content"]/ul[@data-role="listview"]/li[child::a]')
7
- voices = []
8
- voice_nodes.each do |voice|
9
- user = Croudia::User.new(
10
- :username => voice.xpath('//a[parent::span[@class="test_span"]]').first.attribute('href').value.gsub(/\W/, ''),
11
- :nickname => voice.xpath('//span[@class="bord"][parent::p]').first.content,
12
- :avatar => "#{page.uri.scheme}://#{page.uri.host}" + voice.xpath('//img[@class="avatar"]').attribute('src').value,
13
- )
14
- attrs = {
15
- :id => voice.xpath('//a[contains(@href,"/voices/show/")]').first.attribute('href').value.gsub(/\D/, ''),
16
- :user => user,
17
- :voice_desc => voice.css('.voice_desc').first.content,
18
- :spreaded_count => voice.xpath('//span[contains(@style,"#396")]').first.content.gsub(/\D/, ''),
19
- :favorited_count => voice.xpath('//span[contains(@style,"520")]').first.content.gsub(/\D/, ''),
20
- }
21
- if (time = voice.xpath('//p[@data-time]')).size.nonzero?
22
- # For timeline
23
- attrs[:time] = time.first.attribute('data-time').value
24
- end
25
- voices << Croudia::Voice.new(attrs)
26
- end
27
- voices
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,13 +0,0 @@
1
- require 'croudia/scraper/parser/users'
2
- require 'croudia/scraper/parser/voices'
3
-
4
- module Croudia
5
- class Scraper
6
- module Parser
7
- class << self
8
- include Croudia::Scraper::Parser::Users
9
- include Croudia::Scraper::Parser::Voices
10
- end
11
- end
12
- end
13
- end
@@ -1,20 +0,0 @@
1
- module Croudia
2
- class Scraper
3
- module Users
4
- def current_user(force=false)
5
- require_login
6
- @current_user = nil if force
7
- @current_user ||= Parser.user_page(get('/users/redirect_user'))
8
- end
9
- alias verify_credentials current_user
10
-
11
- def user(username=nil, params={})
12
- if username
13
- Parser.user_page(get("/#{username}", params))
14
- else
15
- current_user
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,59 +0,0 @@
1
- module Croudia
2
- class Scraper
3
- module Voices
4
- def timeline(params={})
5
- require_login
6
- Parser.voices(get('/voices/timeline', params))
7
- end
8
- alias home_timeline timeline
9
-
10
- def reply_list(params={})
11
- require_login
12
- Parser.voices(get('/voices/reply_list', params))
13
- end
14
- alias mentions reply_list
15
- alias mentions_timeline reply_list
16
-
17
- def update(text)
18
- require_login
19
- page = get('/voices/written')
20
- form = page.form_with(:action => '/voices/write')
21
- form['voice[tweet]'] = text
22
- result = form.submit
23
- raise 'Update failed' if result.body.include? 'error_popup'
24
- end
25
-
26
- def favorite(voice_id)
27
- require_login
28
- post('/favorites',
29
- :favorites_action => 'enable',
30
- :voice_id => voice_id,
31
- )
32
- end
33
-
34
- def unfavorite(voice_id)
35
- require_login
36
- post('/favorites',
37
- :favorites_action => 'disable',
38
- :voice_id => voice_id,
39
- )
40
- end
41
-
42
- def spread(voice_id)
43
- require_login
44
- post('/spreads/spread_voice',
45
- :favorites_action => 'enable',
46
- :voice_id => voice_id,
47
- )
48
- end
49
-
50
- def unspread(voice_id)
51
- require_login
52
- post('/spreads/spread_voice',
53
- :favorites_action => 'disable',
54
- :voice_id => voice_id,
55
- )
56
- end
57
- end
58
- end
59
- end
@@ -1,63 +0,0 @@
1
- require 'croudia/error'
2
- require 'croudia/scraper/friendships'
3
- require 'croudia/scraper/login'
4
- require 'croudia/scraper/parser'
5
- require 'croudia/scraper/users'
6
- require 'croudia/scraper/voices'
7
- require 'croudia/user'
8
- require 'croudia/version'
9
- require 'croudia/voice'
10
- require 'mechanize'
11
-
12
- module Croudia
13
- class Scraper
14
- include Croudia::Scraper::Friendships
15
- include Croudia::Scraper::Login
16
- include Croudia::Scraper::Users
17
- include Croudia::Scraper::Voices
18
-
19
- attr_accessor :agent, :endpoint
20
-
21
- def initialize(username=nil, password=nil)
22
- yield self if block_given?
23
-
24
- @endpoint ||= 'https://croudia.com'
25
- @user_agent ||= "The Croudia Gem/#{Croudia::VERSION} (https://github.com/wktk/croudia-gem)"
26
- @agent ||= Mechanize.new do |s|
27
- s.verify_mode = OpenSSL::SSL::VERIFY_NONE
28
- end
29
- self.user_agent = @user_agent
30
-
31
- username && password && login(username, password)
32
- end
33
-
34
- def user_agent
35
- @agent.user_agent
36
- end
37
-
38
- def user_agent=(ua)
39
- unless @agent
40
- @user_agent = ua
41
- else
42
- @agent.user_agent = ua
43
- end
44
- end
45
-
46
- def get(path, params={})
47
- pick_token(@agent.get(@endpoint + path, params))
48
- end
49
-
50
- def post(path, params={})
51
- params = { :authenticity_token => @authenticity_token }.merge(params)
52
- pick_token(@agent.post(@endpoint + path, params))
53
- end
54
-
55
- private
56
- def pick_token(page)
57
- page.respond_to?('parser') &&
58
- (token = page.parser.xpath('//meta[@name="csrf-token"]')).size.nonzero? &&
59
- @authenticity_token = token.first.attribute('content').content
60
- page
61
- end
62
- end
63
- end
data/lib/croudia/voice.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'croudia/identity'
2
-
3
- module Croudia
4
- class Voice < Croudia::Identity
5
- attr_reader :user, :voice_desc, :spreaded_count, :favorited_count, :time
6
- alias from_user user
7
- alias text voice_desc
8
- alias description voice_desc
9
- alias desc voice_desc
10
- alias spread_count spreaded_count
11
- alias favorite_count favorited_count
12
-
13
- def to_s
14
- "@#{user.username}: #{voice_desc}"
15
- end
16
-
17
- def to_i
18
- @id.to_i
19
- end
20
- end
21
- end
@@ -1,7 +0,0 @@
1
- require 'croudia/api'
2
-
3
- describe Croudia::API do
4
- it 'is a Module' do
5
- Croudia::API.should be_a Module
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- require 'helper'
2
-
3
- describe Croudia::Error do
4
- it 'is a kind of Error' do
5
- Croudia::Error.kind_of? StandardError
6
- end
7
- end
8
-
9
- describe Croudia::NotLoggedInError do
10
- it 'is a kind of Croudia::Error' do
11
- Croudia::NotLoggedInError.kind_of? Croudia::Error
12
- end
13
- end
@@ -1,115 +0,0 @@
1
- require 'helper'
2
-
3
- describe Croudia::Scraper::Friendships do
4
- context 'when logged in' do
5
- before do
6
- @croudia = Croudia::Scraper.new
7
- @croudia.instance_variable_set('@logged_in', true)
8
- end
9
-
10
- describe '#follow' do
11
- it 'posts to the correct resource' do
12
- stub_post('/follows/target_follow').to_return(:headers => {:content_type => 'text/html'})
13
- @croudia.follow('wktk')
14
- a_post('/follows/target_follow').with(:body => /target_user_name=wktk/).should have_been_made
15
- end
16
- end
17
-
18
- describe '#unfollow' do
19
- it 'posts to the correct resource' do
20
- stub_post('/follows/target_follow').to_return(:headers => {:content_type => 'text/html'})
21
- @croudia.follow('wktk')
22
- a_post('/follows/target_follow').with(:body => /target_user_name=wktk/).should have_been_made
23
- end
24
- end
25
-
26
- describe '#approve' do
27
- it 'posts to the correct resource' do
28
- stub_post('/follows/follow_approve').to_return(:headers => {:content_type => 'text/html'})
29
- @croudia.approve('wktk')
30
- a_post('/follows/follow_approve').with(:body => /target_user_name=wktk/).should have_been_made
31
- end
32
- end
33
-
34
- describe '#refusal' do
35
- it 'posts to the correct resource' do
36
- stub_post('/follows/follow_refusal').to_return(:headers => {:content_type => 'text/html'})
37
- @croudia.refusal('wktk')
38
- a_post('/follows/follow_refusal').with(:body => /target_user_name=wktk/).should have_been_made
39
- end
40
- end
41
-
42
- describe '#block' do
43
- it 'posts to the correct resource' do
44
- stub_post('/blocks/setting').to_return(:headers => {:content_type => 'text/html'})
45
- @croudia.block('wktk')
46
- a_post('/blocks/setting').with(:body => /target_user_name=wktk/).should have_been_made
47
- end
48
- end
49
-
50
- describe '#unblock' do
51
- it 'posts to the correct resource' do
52
- stub_post('/blocks/setting').to_return(:headers => {:content_type => 'text/html'})
53
- @croudia.unblock('wktk')
54
- a_post('/blocks/setting').with(:body => /target_user_name=wktk/).should have_been_made
55
- end
56
- end
57
- end
58
-
59
- context 'when not logged in' do
60
- before do
61
- @croudia = Croudia::Scraper.new
62
- @croudia.instance_variable_set('@logged_in', false)
63
- end
64
-
65
- describe '#follow' do
66
- it 'raises an error' do
67
- expect{ @croudia.follow('wktk') }.to raise_error Croudia::NotLoggedInError
68
- end
69
- end
70
-
71
- describe '#unfollow' do
72
- it 'raises an error' do
73
- expect{ @croudia.follow('wktk') }.to raise_error Croudia::NotLoggedInError
74
- end
75
- end
76
-
77
- describe '#approve' do
78
- it 'raises an error' do
79
- expect{ @croudia.approve('wktk') }.to raise_error Croudia::NotLoggedInError
80
- end
81
- end
82
-
83
- describe '#refusal' do
84
- it 'raises an error' do
85
- expect{ @croudia.refusal('wktk') }.to raise_error Croudia::NotLoggedInError
86
- end
87
- end
88
- end
89
-
90
- describe '#follower' do
91
- it 'gets the correct resource' do
92
- stub_get('/follows/follower/wktk').to_return(:headers => {:content_type => 'text/html'})
93
- Croudia::Scraper.new.follower('wktk')
94
- a_get('/follows/follower/wktk').should have_been_made
95
- end
96
- end
97
-
98
- describe '#following' do
99
- it 'gets the correct resource' do
100
- stub_get('/follows/following/wktk').to_return(:headers => {:content_type => 'text/html'})
101
- Croudia::Scraper.new.following('wktk')
102
- a_get('/follows/following/wktk').should have_been_made
103
- end
104
- end
105
-
106
- describe '#follow_request' do
107
- it 'gets the correct resource' do
108
- stub_get('/follows/follow_request').to_return(:headers => {:content_type => 'text/html'})
109
- @croudia = Croudia::Scraper.new
110
- @croudia.instance_variable_set('@logged_in', true)
111
- @croudia.follow_request
112
- a_get('/follows/follow_request').should have_been_made
113
- end
114
- end
115
- end
@@ -1,137 +0,0 @@
1
- require 'helper'
2
-
3
- describe Croudia::Scraper::Login do
4
- describe '#login' do
5
- before do
6
- stub_get('/').to_return do |request|
7
- if /logged_in=yes/ =~ request.headers['Cookie']
8
- {:status => 302, :headers => {:location => Croudia.endpoint + '/logged_in'}}
9
- else
10
- {:headers => {:content_type => 'text/html'}}
11
- end
12
- end
13
- stub_post('/').to_return do |request|
14
- headers = {:content_type => 'text/html'}
15
- if /username=username/ =~ request.body
16
- headers.merge!(:set_cookie => 'logged_in=yes')
17
- end
18
- {:headers => headers}
19
- end
20
- stub_get('/logged_in').to_return(:headers => {:content_type => 'text/html'})
21
- end
22
-
23
- it 'gets "/" before login' do
24
- Croudia::Scraper.new.login('username', 'password')
25
- a_get('/').should have_been_made.twice
26
- end
27
-
28
- it 'posts the provided username and password to "/"' do
29
- Croudia::Scraper.new.login('username', 'password')
30
- a_post('/').with(:body => /username=username/).should have_been_made
31
- end
32
-
33
- it 'checks if succeeded or not' do
34
- Croudia::Scraper.new.login('username', 'password')
35
- a_get('/').with(:headers => {:cookie => /logged_in=yes/}).should have_been_made
36
- end
37
-
38
- context 'when the provided username and password are correct' do
39
- it 'does not raise an error' do
40
- expect{ Croudia::Scraper.new.login('username', 'password') }.not_to raise_error
41
- end
42
-
43
- it 'sets @logged_in as true' do
44
- @croudia = Croudia::Scraper.new
45
- @croudia.login('username', 'password')
46
- @croudia.instance_variable_get('@logged_in').should be_true
47
- end
48
- end
49
-
50
- context 'when the provided username and password are incorrect' do
51
- it 'raises an error' do
52
- expect{ Croudia::Scraper.new.login('wrong', 'wrong') }.to raise_error ArgumentError
53
- end
54
- end
55
- end
56
-
57
- describe '#logout' do
58
- context 'when already logged out' do
59
- it 'raises an error' do
60
- @croudia = Croudia::Scraper.new
61
- @croudia.instance_variable_set('@logged_in', false)
62
- expect{ @croudia.logout }.to raise_error Croudia::NotLoggedInError
63
- end
64
- end
65
-
66
- context 'when logged in' do
67
- before do
68
- stub_post('/login/logout')
69
- @croudia = Croudia::Scraper.new
70
- @croudia.instance_variable_set('@logged_in', true)
71
- end
72
-
73
- it 'posts a request to the correct resource' do
74
- @croudia.logout
75
- a_post('/login/logout').should have_been_made
76
- end
77
-
78
- it 'sets @logged_in as false' do
79
- @croudia.logout
80
- @croudia.instance_variable_get('@logged_in').should be_false
81
- end
82
-
83
- it 'sets @current_user nil' do
84
- @croudia.logout
85
- @croudia.instance_variable_get('@current_user').should be_nil
86
- end
87
- end
88
- end
89
-
90
- describe '#logged_in?' do
91
- context 'when @logged_in is set' do
92
- it 'returns @logged_in' do
93
- @croudia = Croudia::Scraper.new
94
- @croudia.instance_variable_set('@logged_in', true)
95
- @croudia.logged_in?.should be_true
96
- @croudia.instance_variable_set('@logged_in', false)
97
- @croudia.logged_in?.should be_false
98
- end
99
- end
100
-
101
- context 'when @logged_in is not set' do
102
- it 'gets "/" to confirm logged-in or not' do
103
- stub_get('/')
104
- Croudia::Scraper.new.logged_in?
105
- a_get('/').should have_been_made
106
- end
107
- end
108
- end
109
-
110
- describe '#logged_out?' do
111
- it 'returns !self.logged_in' do
112
- @croudia = Croudia::Scraper.new
113
- @croudia.instance_variable_set('@logged_in', true)
114
- @croudia.logged_out?.should be_false
115
- @croudia.instance_variable_set('@logged_in', false)
116
- @croudia.logged_out?.should be_true
117
- end
118
- end
119
-
120
- describe '#require_login' do
121
- context 'when logged out' do
122
- it 'raises an errror' do
123
- @croudia = Croudia::Scraper.new
124
- @croudia.instance_variable_set('@logged_in', false)
125
- expect{ @croudia.require_login }.to raise_error Croudia::NotLoggedInError
126
- end
127
- end
128
-
129
- context 'when logged in' do
130
- it 'does not raise an error' do
131
- @croudia = Croudia::Scraper.new
132
- @croudia.instance_variable_set('@logged_in', true)
133
- expect{ @croudia.require_login }.not_to raise_error
134
- end
135
- end
136
- end
137
- end