koala 1.8.0 → 1.9.0rc1

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.
@@ -2,13 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe Koala do
4
4
  it "has an http_service accessor" do
5
- Koala.should respond_to(:http_service)
6
- Koala.should respond_to(:http_service=)
5
+ expect(Koala).to respond_to(:http_service)
6
+ expect(Koala).to respond_to(:http_service=)
7
7
  end
8
8
 
9
9
  describe "constants" do
10
10
  it "has a version" do
11
- Koala.const_defined?("VERSION").should be_true
11
+ expect(Koala.const_defined?("VERSION")).to be_truthy
12
12
  end
13
13
  end
14
14
 
@@ -23,21 +23,21 @@ describe Koala do
23
23
 
24
24
  it "invokes deprecated_interface if present" do
25
25
  mock_service = double("http service")
26
- mock_service.should_receive(:deprecated_interface)
26
+ expect(mock_service).to receive(:deprecated_interface)
27
27
  Koala.http_service = mock_service
28
28
  end
29
29
 
30
30
  it "does not set the service if it's deprecated" do
31
31
  mock_service = double("http service")
32
- mock_service.stub(:deprecated_interface)
32
+ allow(mock_service).to receive(:deprecated_interface)
33
33
  Koala.http_service = mock_service
34
- Koala.http_service.should == @service
34
+ expect(Koala.http_service).to eq(@service)
35
35
  end
36
36
 
37
37
  it "sets the service if it's not deprecated" do
38
38
  mock_service = double("http service")
39
39
  Koala.http_service = mock_service
40
- Koala.http_service.should == mock_service
40
+ expect(Koala.http_service).to eq(mock_service)
41
41
  end
42
42
  end
43
43
 
@@ -48,7 +48,7 @@ describe Koala do
48
48
  verb = "get"
49
49
  options = {:c => :d}
50
50
 
51
- Koala.http_service.should_receive(:make_request).with(path, args, verb, options)
51
+ expect(Koala.http_service).to receive(:make_request).with(path, args, verb, options)
52
52
  Koala.make_request(path, args, verb, options)
53
53
  end
54
54
  end
@@ -77,7 +77,7 @@ describe Koala do
77
77
  Koala.configure do |config|
78
78
  config.graph_server = "some-new.graph_server.com"
79
79
  end
80
- Koala.config.graph_server.should == "some-new.graph_server.com"
80
+ expect(Koala.config.graph_server).to eq("some-new.graph_server.com")
81
81
  end
82
82
  end
83
83
 
@@ -5,27 +5,27 @@ describe "legacy APIs" do
5
5
 
6
6
  it "deprecates the REST API" do
7
7
  api = Koala::Facebook::API.new
8
- api.stub(:api)
9
- Koala::Utils.should_receive(:deprecate)
8
+ allow(api).to receive(:api)
9
+ expect(Koala::Utils).to receive(:deprecate)
10
10
  api.rest_call("stuff")
11
11
  end
12
12
 
13
13
  describe Koala::Facebook::GraphAPI do
14
14
  describe "class consolidation" do
15
15
  before :each do
16
- Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
16
+ allow(Koala::Utils).to receive(:deprecate) # avoid actual messages to stderr
17
17
  end
18
18
 
19
19
  it "still allows you to instantiate a GraphAndRestAPI object" do
20
- api = Koala::Facebook::GraphAPI.new("token").should be_a(Koala::Facebook::GraphAPI)
20
+ api = expect(Koala::Facebook::GraphAPI.new("token")).to be_a(Koala::Facebook::GraphAPI)
21
21
  end
22
22
 
23
23
  it "ultimately creates an API object" do
24
- api = Koala::Facebook::GraphAPI.new("token").should be_a(Koala::Facebook::API)
24
+ api = expect(Koala::Facebook::GraphAPI.new("token")).to be_a(Koala::Facebook::API)
25
25
  end
26
26
 
27
27
  it "fires a depreciation warning" do
28
- Koala::Utils.should_receive(:deprecate)
28
+ expect(Koala::Utils).to receive(:deprecate)
29
29
  api = Koala::Facebook::GraphAPI.new("token")
30
30
  end
31
31
  end
@@ -34,19 +34,19 @@ describe "legacy APIs" do
34
34
  describe Koala::Facebook::RestAPI do
35
35
  describe "class consolidation" do
36
36
  before :each do
37
- Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
37
+ allow(Koala::Utils).to receive(:deprecate) # avoid actual messages to stderr
38
38
  end
39
39
 
40
40
  it "still allows you to instantiate a GraphAndRestAPI object" do
41
- api = Koala::Facebook::RestAPI.new("token").should be_a(Koala::Facebook::RestAPI)
41
+ api = expect(Koala::Facebook::RestAPI.new("token")).to be_a(Koala::Facebook::RestAPI)
42
42
  end
43
43
 
44
44
  it "ultimately creates an API object" do
45
- api = Koala::Facebook::RestAPI.new("token").should be_a(Koala::Facebook::API)
45
+ api = expect(Koala::Facebook::RestAPI.new("token")).to be_a(Koala::Facebook::API)
46
46
  end
47
47
 
48
48
  it "fires a depreciation warning" do
49
- Koala::Utils.should_receive(:deprecate)
49
+ expect(Koala::Utils).to receive(:deprecate)
50
50
  api = Koala::Facebook::RestAPI.new("token")
51
51
  end
52
52
  end
@@ -55,19 +55,19 @@ describe "legacy APIs" do
55
55
  describe Koala::Facebook::GraphAndRestAPI do
56
56
  describe "class consolidation" do
57
57
  before :each do
58
- Koala::Utils.stub(:deprecate) # avoid actual messages to stderr
58
+ allow(Koala::Utils).to receive(:deprecate) # avoid actual messages to stderr
59
59
  end
60
60
 
61
61
  it "still allows you to instantiate a GraphAndRestAPI object" do
62
- api = Koala::Facebook::GraphAndRestAPI.new("token").should be_a(Koala::Facebook::GraphAndRestAPI)
62
+ api = expect(Koala::Facebook::GraphAndRestAPI.new("token")).to be_a(Koala::Facebook::GraphAndRestAPI)
63
63
  end
64
64
 
65
65
  it "ultimately creates an API object" do
66
- api = Koala::Facebook::GraphAndRestAPI.new("token").should be_a(Koala::Facebook::API)
66
+ api = expect(Koala::Facebook::GraphAndRestAPI.new("token")).to be_a(Koala::Facebook::API)
67
67
  end
68
68
 
69
69
  it "fires a depreciation warning" do
70
- Koala::Utils.should_receive(:deprecate)
70
+ expect(Koala::Utils).to receive(:deprecate)
71
71
  api = Koala::Facebook::GraphAndRestAPI.new("token")
72
72
  end
73
73
  end
@@ -76,40 +76,40 @@ describe "legacy APIs" do
76
76
  {:typhoeus => Koala::TyphoeusService, :net_http => Koala::NetHTTPService}.each_pair do |adapter, module_class|
77
77
  describe module_class.to_s do
78
78
  it "responds to deprecated_interface" do
79
- module_class.should respond_to(:deprecated_interface)
79
+ expect(module_class).to respond_to(:deprecated_interface)
80
80
  end
81
81
 
82
82
  it "issues a deprecation warning" do
83
- Koala::Utils.should_receive(:deprecate)
83
+ expect(Koala::Utils).to receive(:deprecate)
84
84
  module_class.deprecated_interface
85
85
  end
86
86
 
87
87
  it "sets the default adapter to #{adapter}" do
88
88
  module_class.deprecated_interface
89
- Faraday.default_adapter.should == adapter
89
+ expect(Faraday.default_adapter).to eq(adapter)
90
90
  end
91
91
  end
92
92
  end
93
93
 
94
94
  describe "moved classes" do
95
95
  it "allows you to access Koala::HTTPService::MultipartRequest through the Koala module" do
96
- Koala::MultipartRequest.should == Koala::HTTPService::MultipartRequest
96
+ expect(Koala::MultipartRequest).to eq(Koala::HTTPService::MultipartRequest)
97
97
  end
98
98
 
99
99
  it "allows you to access Koala::Response through the Koala module" do
100
- Koala::Response.should == Koala::HTTPService::Response
100
+ expect(Koala::Response).to eq(Koala::HTTPService::Response)
101
101
  end
102
102
 
103
103
  it "allows you to access Koala::Response through the Koala module" do
104
- Koala::UploadableIO.should == Koala::HTTPService::UploadableIO
104
+ expect(Koala::UploadableIO).to eq(Koala::HTTPService::UploadableIO)
105
105
  end
106
106
 
107
107
  it "allows you to access Koala::Facebook::GraphBatchAPI::BatchOperation through the Koala::Facebook module" do
108
- Koala::Facebook::BatchOperation.should == Koala::Facebook::GraphBatchAPI::BatchOperation
108
+ expect(Koala::Facebook::BatchOperation).to eq(Koala::Facebook::GraphBatchAPI::BatchOperation)
109
109
  end
110
110
 
111
111
  it "allows you to access Koala::Facebook::API::GraphCollection through the Koala::Facebook module" do
112
- Koala::Facebook::GraphCollection.should == Koala::Facebook::API::GraphCollection
112
+ expect(Koala::Facebook::GraphCollection).to eq(Koala::Facebook::API::GraphCollection)
113
113
  end
114
114
  end
115
115
  end
@@ -2,65 +2,64 @@ require 'spec_helper'
2
2
 
3
3
  describe Koala::HTTPService::MultipartRequest do
4
4
  it "is a subclass of Faraday::Request::Multipart" do
5
- Koala::HTTPService::MultipartRequest.superclass.should == Faraday::Request::Multipart
5
+ expect(Koala::HTTPService::MultipartRequest.superclass).to eq(Faraday::Request::Multipart)
6
6
  end
7
-
7
+
8
8
  it "defines mime_type as multipart/form-data" do
9
- Koala::HTTPService::MultipartRequest.mime_type.should == 'multipart/form-data'
9
+ expect(Koala::HTTPService::MultipartRequest.mime_type).to eq('multipart/form-data')
10
10
  end
11
-
11
+
12
12
  describe "#process_request?" do
13
13
  before :each do
14
- @env = {}
14
+ @env = Faraday::Env.new
15
15
  @multipart = Koala::HTTPService::MultipartRequest.new
16
- @multipart.stub(:request_type).and_return("")
16
+ allow(@multipart).to receive(:request_type).and_return("")
17
17
  end
18
-
18
+
19
19
  # no way to test the call to super, unfortunately
20
20
  it "returns true if env[:body] is a hash with at least one hash in its values" do
21
21
  @env[:body] = {:a => {:c => 2}}
22
- @multipart.process_request?(@env).should be_true
22
+ expect(@multipart.process_request?(@env)).to be_truthy
23
23
  end
24
24
 
25
25
  it "returns true if env[:body] is a hash with at least one array in its values" do
26
26
  @env[:body] = {:a => [:c, 2]}
27
- @multipart.process_request?(@env).should be_true
27
+ expect(@multipart.process_request?(@env)).to be_truthy
28
28
  end
29
29
 
30
30
  it "returns true if env[:body] is a hash with mixed objects in its values" do
31
31
  @env[:body] = {:a => [:c, 2], :b => {:e => :f}}
32
- @multipart.process_request?(@env).should be_true
32
+ expect(@multipart.process_request?(@env)).to be_truthy
33
33
  end
34
34
 
35
35
  it "returns false if env[:body] is a string" do
36
36
  @env[:body] = "my body"
37
- @multipart.process_request?(@env).should be_false
37
+ expect(@multipart.process_request?(@env)).to be_falsey
38
38
  end
39
39
 
40
40
  it "returns false if env[:body] is a hash without an array or hash value" do
41
41
  @env[:body] = {:a => 3}
42
- @multipart.process_request?(@env).should be_false
43
- end
42
+ expect(@multipart.process_request?(@env)).to be_falsey
43
+ end
44
44
  end
45
-
45
+
46
46
  describe "#process_params" do
47
47
  before :each do
48
48
  @parent = Faraday::Request::Multipart.new
49
- @multipart = Koala::HTTPService::MultipartRequest.new
50
- @block = lambda {|k, v| "#{k}=#{v}"}
49
+ @multipart = Koala::HTTPService::MultipartRequest.new
50
+ @block = lambda {|k, v| "#{k}=#{v}"}
51
51
  end
52
-
52
+
53
53
  it "is identical to the parent for requests without a prefix" do
54
54
  hash = {:a => 2, :c => "3"}
55
- @multipart.process_params(hash, &@block).should == @parent.process_params(hash, &@block)
55
+ expect(@multipart.process_params(hash, &@block)).to eq(@parent.process_params(hash, &@block))
56
56
  end
57
-
57
+
58
58
  it "replaces encodes [ and ] if the request has a prefix" do
59
59
  hash = {:a => 2, :c => "3"}
60
60
  prefix = "foo"
61
61
  # process_params returns an array
62
- @multipart.process_params(hash, prefix, &@block).join("&").should == @parent.process_params(hash, prefix, &@block).join("&").gsub(/\[/, "%5B").gsub(/\]/, "%5D")
62
+ expect(@multipart.process_params(hash, prefix, &@block).join("&")).to eq(@parent.process_params(hash, prefix, &@block).join("&").gsub(/\[/, "%5B").gsub(/\]/, "%5D"))
63
63
  end
64
64
  end
65
-
66
65
  end
@@ -28,19 +28,19 @@ describe "Koala::Facebook::OAuth" do
28
28
 
29
29
  before :each do
30
30
  @time = Time.now
31
- Time.stub(:now).and_return(@time)
32
- @time.stub(:to_i).and_return(1273363199)
31
+ allow(Time).to receive(:now).and_return(@time)
32
+ allow(@time).to receive(:to_i).and_return(1273363199)
33
33
  end
34
34
 
35
35
  describe ".new" do
36
36
  it "properly initializes" do
37
- @oauth.should
37
+ expect(@oauth).to be_truthy
38
38
  end
39
39
 
40
40
  it "properly sets attributes" do
41
- (@oauth.app_id == @app_id &&
41
+ expect(@oauth.app_id == @app_id &&
42
42
  @oauth.app_secret == @secret &&
43
- @oauth.oauth_callback_url == @callback_url).should be_true
43
+ @oauth.oauth_callback_url == @callback_url).to be_truthy
44
44
  end
45
45
 
46
46
  it "properly initializes without a callback_url" do
@@ -49,9 +49,9 @@ describe "Koala::Facebook::OAuth" do
49
49
 
50
50
  it "properly sets attributes without a callback URL" do
51
51
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
52
- (@oauth.app_id == @app_id &&
52
+ expect(@oauth.app_id == @app_id &&
53
53
  @oauth.app_secret == @secret &&
54
- @oauth.oauth_callback_url == nil).should be_true
54
+ @oauth.oauth_callback_url == nil).to be_truthy
55
55
  end
56
56
  end
57
57
 
@@ -62,71 +62,71 @@ describe "Koala::Facebook::OAuth" do
62
62
  # we don't actually want to make requests to Facebook to redeem the code
63
63
  @cookie = KoalaTest.oauth_test_data["valid_signed_cookies"]
64
64
  @token = "my token"
65
- @oauth.stub(:get_access_token_info).and_return("access_token" => @token)
65
+ allow(@oauth).to receive(:get_access_token_info).and_return("access_token" => @token)
66
66
  end
67
67
 
68
68
  it "parses valid cookies" do
69
69
  result = @oauth.get_user_info_from_cookies(@cookie)
70
- result.should be_a(Hash)
70
+ expect(result).to be_a(Hash)
71
71
  end
72
72
 
73
73
  it "returns all the components in the signed request" do
74
74
  result = @oauth.get_user_info_from_cookies(@cookie)
75
75
  @oauth.parse_signed_request(@cookie.values.first).each_pair do |k, v|
76
- result[k].should == v
76
+ expect(result[k]).to eq(v)
77
77
  end
78
78
  end
79
79
 
80
80
  it "makes a request to Facebook to redeem the code if present" do
81
81
  code = "foo"
82
- @oauth.stub(:parse_signed_request).and_return({"code" => code})
83
- @oauth.should_receive(:get_access_token_info).with(code, anything)
82
+ allow(@oauth).to receive(:parse_signed_request).and_return({"code" => code})
83
+ expect(@oauth).to receive(:get_access_token_info).with(code, anything)
84
84
  @oauth.get_user_info_from_cookies(@cookie)
85
85
  end
86
86
 
87
87
  it "sets the code redemption redirect_uri to ''" do
88
- @oauth.should_receive(:get_access_token_info).with(anything, :redirect_uri => '')
88
+ expect(@oauth).to receive(:get_access_token_info).with(anything, :redirect_uri => '')
89
89
  @oauth.get_user_info_from_cookies(@cookie)
90
90
  end
91
91
 
92
92
  context "if the code is missing" do
93
93
  it "doesn't make a request to Facebook" do
94
- @oauth.stub(:parse_signed_request).and_return({})
95
- @oauth.should_receive(:get_access_token_info).never
94
+ allow(@oauth).to receive(:parse_signed_request).and_return({})
95
+ expect(@oauth).to receive(:get_access_token_info).never
96
96
  @oauth.get_user_info_from_cookies(@cookie)
97
97
  end
98
98
 
99
99
  it "returns nil" do
100
- @oauth.stub(:parse_signed_request).and_return({})
101
- @oauth.get_user_info_from_cookies(@cookie).should be_nil
100
+ allow(@oauth).to receive(:parse_signed_request).and_return({})
101
+ expect(@oauth.get_user_info_from_cookies(@cookie)).to be_nil
102
102
  end
103
103
 
104
104
  it "logs a warning" do
105
- @oauth.stub(:parse_signed_request).and_return({})
106
- Koala::Utils.logger.should_receive(:warn)
105
+ allow(@oauth).to receive(:parse_signed_request).and_return({})
106
+ expect(Koala::Utils.logger).to receive(:warn)
107
107
  @oauth.get_user_info_from_cookies(@cookie)
108
108
  end
109
109
  end
110
110
 
111
111
  context "if the code is present" do
112
112
  it "adds the access_token into the hash" do
113
- @oauth.get_user_info_from_cookies(@cookie)["access_token"].should == @token
113
+ expect(@oauth.get_user_info_from_cookies(@cookie)["access_token"]).to eq(@token)
114
114
  end
115
115
 
116
116
  it "returns nil if the call to FB returns no data" do
117
- @oauth.stub(:get_access_token_info).and_return(nil)
118
- @oauth.get_user_info_from_cookies(@cookie).should be_nil
117
+ allow(@oauth).to receive(:get_access_token_info).and_return(nil)
118
+ expect(@oauth.get_user_info_from_cookies(@cookie)).to be_nil
119
119
  end
120
120
 
121
121
  it "returns nil if the call to FB returns an expired code error" do
122
- @oauth.stub(:get_access_token_info).and_raise(Koala::Facebook::OAuthTokenRequestError.new(400,
122
+ allow(@oauth).to receive(:get_access_token_info).and_raise(Koala::Facebook::OAuthTokenRequestError.new(400,
123
123
  '{ "error": { "type": "OAuthException", "message": "Code was invalid or expired. Session has expired at unix time 1324044000. The current unix time is 1324300957." } }'
124
124
  ))
125
- @oauth.get_user_info_from_cookies(@cookie).should be_nil
125
+ expect(@oauth.get_user_info_from_cookies(@cookie)).to be_nil
126
126
  end
127
127
 
128
128
  it "raises the error if the call to FB returns a different error" do
129
- @oauth.stub(:get_access_token_info).and_raise(Koala::Facebook::OAuthTokenRequestError.new(400,
129
+ allow(@oauth).to receive(:get_access_token_info).and_raise(Koala::Facebook::OAuthTokenRequestError.new(400,
130
130
  '{ "error": { "type": "OtherError", "message": "A Facebook Error" } }'))
131
131
  expect { @oauth.get_user_info_from_cookies(@cookie) }.to raise_exception(Koala::Facebook::OAuthTokenRequestError)
132
132
  end
@@ -136,46 +136,46 @@ describe "Koala::Facebook::OAuth" do
136
136
  # make an invalid string by replacing some values
137
137
  bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
138
138
  result = @oauth.get_user_info_from_cookies(bad_cookie_hash)
139
- result.should be_nil
139
+ expect(result).to be_nil
140
140
  end
141
141
  end
142
142
 
143
143
  context "for unsigned cookies" do
144
144
  it "properly parses valid cookies" do
145
145
  result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["valid_cookies"])
146
- result.should be_a(Hash)
146
+ expect(result).to be_a(Hash)
147
147
  end
148
148
 
149
149
  it "returns all the cookie components from valid cookie string" do
150
150
  cookie_data = KoalaTest.oauth_test_data["valid_cookies"]
151
151
  parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
152
152
  number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
153
- parsing_results.length.should == number_of_components
153
+ expect(parsing_results.length).to eq(number_of_components)
154
154
  end
155
155
 
156
156
  it "properly parses valid offline access cookies (e.g. no expiration)" do
157
157
  result = @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["offline_access_cookies"])
158
- result["uid"].should
158
+ expect(result["uid"]).to be_truthy
159
159
  end
160
160
 
161
161
  it "returns all the cookie components from offline access cookies" do
162
162
  cookie_data = KoalaTest.oauth_test_data["offline_access_cookies"]
163
163
  parsing_results = @oauth.get_user_info_from_cookies(cookie_data)
164
164
  number_of_components = cookie_data["fbs_#{@app_id.to_s}"].scan(/\=/).length
165
- parsing_results.length.should == number_of_components
165
+ expect(parsing_results.length).to eq(number_of_components)
166
166
  end
167
167
 
168
168
  it "doesn't parse expired cookies" do
169
169
  new_time = @time.to_i * 2
170
- @time.stub(:to_i).and_return(new_time)
171
- @oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["valid_cookies"]).should be_nil
170
+ allow(@time).to receive(:to_i).and_return(new_time)
171
+ expect(@oauth.get_user_info_from_cookies(KoalaTest.oauth_test_data["valid_cookies"])).to be_nil
172
172
  end
173
173
 
174
174
  it "doesn't parse invalid cookies" do
175
175
  # make an invalid string by replacing some values
176
176
  bad_cookie_hash = KoalaTest.oauth_test_data["valid_cookies"].inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
177
177
  result = @oauth.get_user_info_from_cookies(bad_cookie_hash)
178
- result.should be_nil
178
+ expect(result).to be_nil
179
179
  end
180
180
  end
181
181
  end
@@ -185,28 +185,28 @@ describe "Koala::Facebook::OAuth" do
185
185
  before :each do
186
186
  # we don't actually want to make requests to Facebook to redeem the code
187
187
  @cookie = KoalaTest.oauth_test_data["valid_signed_cookies"]
188
- @oauth.stub(:get_access_token_info).and_return("access_token" => "my token")
188
+ allow(@oauth).to receive(:get_access_token_info).and_return("access_token" => "my token")
189
189
  end
190
190
 
191
191
  it "does not uses get_user_info_from_cookies to parse the cookies" do
192
- @oauth.should_not_receive(:get_user_info_from_cookies).with(@cookie)
192
+ expect(@oauth).not_to receive(:get_user_info_from_cookies).with(@cookie)
193
193
  @oauth.get_user_from_cookies(@cookie)
194
194
  end
195
195
 
196
196
  it "uses return the facebook user id string if the cookies are valid" do
197
197
  result = @oauth.get_user_from_cookies(@cookie)
198
- result.should == "2905623" # the user who generated the original test cookie
198
+ expect(result).to eq("2905623") # the user who generated the original test cookie
199
199
  end
200
200
 
201
201
  it "returns nil if the cookies are invalid" do
202
202
  # make an invalid string by replacing some values
203
203
  bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
204
204
  result = @oauth.get_user_from_cookies(bad_cookie_hash)
205
- result.should be_nil
205
+ expect(result).to be_nil
206
206
  end
207
207
 
208
208
  it "is deprecated" do
209
- Koala::Utils.should_receive(:deprecate)
209
+ expect(Koala::Utils).to receive(:deprecate)
210
210
  @oauth.get_user_from_cookies({})
211
211
  end
212
212
  end
@@ -218,20 +218,20 @@ describe "Koala::Facebook::OAuth" do
218
218
  end
219
219
 
220
220
  it "uses get_user_info_from_cookies to parse the cookies" do
221
- @oauth.should_receive(:get_user_info_from_cookies).with(@cookie).and_return({})
221
+ expect(@oauth).to receive(:get_user_info_from_cookies).with(@cookie).and_return({})
222
222
  @oauth.get_user_from_cookies(@cookie)
223
223
  end
224
224
 
225
225
  it "uses return a string if the cookies are valid" do
226
226
  result = @oauth.get_user_from_cookies(@cookie)
227
- result.should == "2905623" # the user who generated the original test cookie
227
+ expect(result).to eq("2905623") # the user who generated the original test cookie
228
228
  end
229
229
 
230
230
  it "returns nil if the cookies are invalid" do
231
231
  # make an invalid string by replacing some values
232
232
  bad_cookie_hash = @cookie.inject({}) { |hash, value| hash[value[0]] = value[1].gsub(/[0-9]/, "3") }
233
233
  result = @oauth.get_user_from_cookies(bad_cookie_hash)
234
- result.should be_nil
234
+ expect(result).to be_nil
235
235
  end
236
236
  end
237
237
  end
@@ -241,42 +241,42 @@ describe "Koala::Facebook::OAuth" do
241
241
  describe "#url_for_oauth_code" do
242
242
  it "generates a properly formatted OAuth code URL with the default values" do
243
243
  url = @oauth.url_for_oauth_code
244
- url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
244
+ expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}")
245
245
  end
246
246
 
247
247
  it "generates a properly formatted OAuth code URL when a callback is given" do
248
248
  callback = "foo.com"
249
249
  url = @oauth.url_for_oauth_code(:callback => callback)
250
- url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{callback}")
250
+ expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&redirect_uri=#{callback}")
251
251
  end
252
252
 
253
253
  it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
254
254
  permissions = "publish_stream,read_stream"
255
255
  url = @oauth.url_for_oauth_code(:permissions => permissions)
256
- url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape @callback_url}")
256
+ expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape @callback_url}")
257
257
  end
258
258
 
259
259
  it "generates a properly formatted OAuth code URL when permissions are requested as a string" do
260
260
  permissions = ["publish_stream", "read_stream"]
261
261
  url = @oauth.url_for_oauth_code(:permissions => permissions)
262
- url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions.join(",")}&redirect_uri=#{CGI.escape @callback_url}")
262
+ expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions.join(",")}&redirect_uri=#{CGI.escape @callback_url}")
263
263
  end
264
264
 
265
265
  it "generates a properly formatted OAuth code URL when both permissions and callback are provided" do
266
266
  permissions = "publish_stream,read_stream"
267
267
  callback = "foo.com"
268
268
  url = @oauth.url_for_oauth_code(:callback => callback, :permissions => permissions)
269
- url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape callback}")
269
+ expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&scope=#{CGI.escape permissions}&redirect_uri=#{CGI.escape callback}")
270
270
  end
271
271
 
272
272
  it "generates a properly formatted OAuth code URL when a display is given as a string" do
273
273
  url = @oauth.url_for_oauth_code(:display => "page")
274
- url.should match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&display=page&redirect_uri=#{CGI.escape @callback_url}")
274
+ expect(url).to match_url("https://#{Koala.config.dialog_host}/dialog/oauth?client_id=#{@app_id}&display=page&redirect_uri=#{CGI.escape @callback_url}")
275
275
  end
276
276
 
277
277
  it "raises an exception if no callback is given in initialization or the call" do
278
278
  oauth2 = Koala::Facebook::OAuth.new(@app_id, @secret)
279
- lambda { oauth2.url_for_oauth_code }.should raise_error(ArgumentError)
279
+ expect { oauth2.url_for_oauth_code }.to raise_error(ArgumentError)
280
280
  end
281
281
 
282
282
  it "includes any additional options as URL parameters, appropriately escaped" do
@@ -286,7 +286,7 @@ describe "Koala::Facebook::OAuth" do
286
286
  }
287
287
  url = @oauth.url_for_oauth_code(params)
288
288
  params.each_pair do |key, value|
289
- url.should =~ /[\&\?]#{key}=#{CGI.escape value}/
289
+ expect(url).to match(/[\&\?]#{key}=#{CGI.escape value}/)
290
290
  end
291
291
  end
292
292
  end
@@ -299,13 +299,13 @@ describe "Koala::Facebook::OAuth" do
299
299
 
300
300
  it "generates a properly formatted OAuth token URL when provided a code" do
301
301
  url = @oauth.url_for_access_token(@code)
302
- url.should match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
302
+ expect(url).to match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape @callback_url}")
303
303
  end
304
304
 
305
305
  it "generates a properly formatted OAuth token URL when provided a callback" do
306
306
  callback = "foo.com"
307
307
  url = @oauth.url_for_access_token(@code, :callback => callback)
308
- url.should match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape callback}")
308
+ expect(url).to match_url("https://#{Koala.config.graph_server}/oauth/access_token?client_id=#{@app_id}&code=#{@code}&client_secret=#{@secret}&redirect_uri=#{CGI.escape callback}")
309
309
  end
310
310
 
311
311
  it "includes any additional options as URL parameters, appropriately escaped" do
@@ -315,7 +315,7 @@ describe "Koala::Facebook::OAuth" do
315
315
  }
316
316
  url = @oauth.url_for_access_token(@code, params)
317
317
  params.each_pair do |key, value|
318
- url.should =~ /[\&\?]#{key}=#{CGI.escape value}/
318
+ expect(url).to match(/[\&\?]#{key}=#{CGI.escape value}/)
319
319
  end
320
320
  end
321
321
  end
@@ -323,7 +323,7 @@ describe "Koala::Facebook::OAuth" do
323
323
  describe "#url_for_dialog" do
324
324
  it "builds the base properly" do
325
325
  dialog_type = "my_dialog_type"
326
- @oauth.url_for_dialog(dialog_type).should =~ /^http:\/\/#{Koala.config.dialog_host}\/dialog\/#{dialog_type}/
326
+ expect(@oauth.url_for_dialog(dialog_type)).to match(/^http:\/\/#{Koala.config.dialog_host}\/dialog\/#{dialog_type}/)
327
327
  end
328
328
 
329
329
  it "adds the app_id/client_id to the url" do
@@ -331,7 +331,7 @@ describe "Koala::Facebook::OAuth" do
331
331
  url = @oauth.url_for_dialog("foo", automatic_params)
332
332
  automatic_params.each_pair do |key, value|
333
333
  # we're slightly simplifying how encode_params works, but for strings/ints, it's okay
334
- url.should =~ /[\&\?]#{key}=#{CGI.escape value.to_s}/
334
+ expect(url).to match(/[\&\?]#{key}=#{CGI.escape value.to_s}/)
335
335
  end
336
336
  end
337
337
 
@@ -343,7 +343,7 @@ describe "Koala::Facebook::OAuth" do
343
343
  url = @oauth.url_for_dialog("friends", params)
344
344
  params.each_pair do |key, value|
345
345
  # we're slightly simplifying how encode_params works, but strings/ints, it's okay
346
- url.should =~ /[\&\?]#{key}=#{CGI.escape value.to_s}/
346
+ expect(url).to match(/[\&\?]#{key}=#{CGI.escape value.to_s}/)
347
347
  end
348
348
  end
349
349
 
@@ -352,22 +352,22 @@ describe "Koala::Facebook::OAuth" do
352
352
  # slightly brittle (e.g. if parameter order changes), but still useful
353
353
  it "can generate a send dialog" do
354
354
  url = @oauth.url_for_dialog("send", :name => "People Argue Just to Win", :link => "http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html")
355
- url.should match_url("http://www.facebook.com/dialog/send?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
355
+ expect(url).to match_url("http://www.facebook.com/dialog/send?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
356
356
  end
357
357
 
358
358
  it "can generate a feed dialog" do
359
359
  url = @oauth.url_for_dialog("feed", :name => "People Argue Just to Win", :link => "http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html")
360
- url.should match_url("http://www.facebook.com/dialog/feed?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
360
+ expect(url).to match_url("http://www.facebook.com/dialog/feed?app_id=#{@app_id}&client_id=#{@app_id}&link=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html&name=People+Argue+Just+to+Win&redirect_uri=#{CGI.escape @callback_url}")
361
361
  end
362
362
 
363
363
  it "can generate a oauth dialog" do
364
364
  url = @oauth.url_for_dialog("oauth", :scope => "email", :response_type => "token")
365
- url.should match_url("http://www.facebook.com/dialog/oauth?app_id=#{@app_id}&client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}&response_type=token&scope=email")
365
+ expect(url).to match_url("http://www.facebook.com/dialog/oauth?app_id=#{@app_id}&client_id=#{@app_id}&redirect_uri=#{CGI.escape @callback_url}&response_type=token&scope=email")
366
366
  end
367
367
 
368
368
  it "can generate a pay dialog" do
369
369
  url = @oauth.url_for_dialog("pay", :order_id => "foo", :credits_purchase => false)
370
- url.should match_url("http://www.facebook.com/dialog/pay?app_id=#{@app_id}&client_id=#{@app_id}&order_id=foo&credits_purchase=false&redirect_uri=#{CGI.escape @callback_url}")
370
+ expect(url).to match_url("http://www.facebook.com/dialog/pay?app_id=#{@app_id}&client_id=#{@app_id}&order_id=foo&credits_purchase=false&redirect_uri=#{CGI.escape @callback_url}")
371
371
  end
372
372
  end
373
373
  end
@@ -377,35 +377,35 @@ describe "Koala::Facebook::OAuth" do
377
377
  describe '#generate_client_code' do
378
378
  if KoalaTest.mock_interface? || KoalaTest.oauth_token
379
379
  it 'makes a request using the correct endpoint' do
380
- Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
380
+ expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
381
381
  @oauth.generate_client_code(KoalaTest.oauth_token)
382
382
  end
383
383
 
384
384
  it 'gets a valid client code returned' do
385
- Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
385
+ expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
386
386
  result = @oauth.generate_client_code(KoalaTest.oauth_token)
387
- result.should be_a(String)
388
- result.should eq('fake_client_code')
387
+ expect(result).to be_a(String)
388
+ expect(result).to eq('fake_client_code')
389
389
  end
390
390
 
391
391
  it 'raises a BadFacebookResponse error when empty response body is returned' do
392
- Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '', {}))
393
- lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::BadFacebookResponse)
392
+ expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '', {}))
393
+ expect { @oauth.generate_client_code(KoalaTest.oauth_token) }.to raise_error(Koala::Facebook::BadFacebookResponse)
394
394
  end
395
395
 
396
396
  it 'raises an OAuthTokenRequestError when empty response body is returned' do
397
- Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(400, '', {}))
398
- lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::OAuthTokenRequestError)
397
+ expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(400, '', {}))
398
+ expect { @oauth.generate_client_code(KoalaTest.oauth_token) }.to raise_error(Koala::Facebook::OAuthTokenRequestError)
399
399
  end
400
400
 
401
401
  it 'raises a ServerError when empty response body is returned' do
402
- Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(500, '', {}))
403
- lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::ServerError)
402
+ expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(500, '', {}))
403
+ expect { @oauth.generate_client_code(KoalaTest.oauth_token) }.to raise_error(Koala::Facebook::ServerError)
404
404
  end
405
405
 
406
406
  it 'raises a KoalaError when empty response body is returned' do
407
- Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"client_code":"should_not_be_returned"}', {}))
408
- lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::KoalaError)
407
+ expect(Koala).to receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"client_code":"should_not_be_returned"}', {}))
408
+ expect { @oauth.generate_client_code(KoalaTest.oauth_token) }.to raise_error(Koala::KoalaError)
409
409
  end
410
410
  else
411
411
  pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
@@ -417,33 +417,33 @@ describe "Koala::Facebook::OAuth" do
417
417
  describe "#get_access_token_info" do
418
418
  it "uses options[:redirect_uri] if provided" do
419
419
  uri = "foo"
420
- Koala.should_receive(:make_request).with(anything, hash_including(:redirect_uri => uri), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
420
+ expect(Koala).to receive(:make_request).with(anything, hash_including(:redirect_uri => uri), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
421
421
  @oauth.get_access_token_info(@code, :redirect_uri => uri)
422
422
  end
423
423
 
424
424
  it "uses the redirect_uri used to create the @oauth if no :redirect_uri option is provided" do
425
- Koala.should_receive(:make_request).with(anything, hash_including(:redirect_uri => @callback_url), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
425
+ expect(Koala).to receive(:make_request).with(anything, hash_including(:redirect_uri => @callback_url), anything, anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
426
426
  @oauth.get_access_token_info(@code)
427
427
  end
428
428
 
429
429
  it "makes a GET request" do
430
- Koala.should_receive(:make_request).with(anything, anything, "get", anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
430
+ expect(Koala).to receive(:make_request).with(anything, anything, "get", anything).and_return(Koala::HTTPService::Response.new(200, "", {}))
431
431
  @oauth.get_access_token_info(@code)
432
432
  end
433
433
 
434
434
  if KoalaTest.code
435
435
  it "properly gets and parses an access token token results into a hash" do
436
436
  result = @oauth.get_access_token_info(@code)
437
- result.should be_a(Hash)
437
+ expect(result).to be_a(Hash)
438
438
  end
439
439
 
440
440
  it "properly includes the access token results" do
441
441
  result = @oauth.get_access_token_info(@code)
442
- result["access_token"].should
442
+ expect(result["access_token"]).to be_truthy
443
443
  end
444
444
 
445
445
  it "raises an error when get_access_token is called with a bad code" do
446
- lambda { @oauth.get_access_token_info("foo") }.should raise_error(Koala::Facebook::OAuthTokenRequestError)
446
+ expect { @oauth.get_access_token_info("foo") }.to raise_error(Koala::Facebook::OAuthTokenRequestError)
447
447
  end
448
448
  end
449
449
  end
@@ -452,24 +452,24 @@ describe "Koala::Facebook::OAuth" do
452
452
  # TODO refactor these to be proper tests with stubs and tests against real data
453
453
  it "passes on any options provided to make_request" do
454
454
  options = {:a => 2}
455
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
455
+ expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
456
456
  @oauth.get_access_token(@code, options)
457
457
  end
458
458
 
459
459
  if KoalaTest.code
460
460
  it "uses get_access_token_info to get and parse an access token token results" do
461
461
  result = @oauth.get_access_token(@code)
462
- result.should be_a(String)
462
+ expect(result).to be_a(String)
463
463
  end
464
464
 
465
465
  it "returns the access token as a string" do
466
466
  result = @oauth.get_access_token(@code)
467
467
  original = @oauth.get_access_token_info(@code)
468
- result.should == original["access_token"]
468
+ expect(result).to eq(original["access_token"])
469
469
  end
470
470
 
471
471
  it "raises an error when get_access_token is called with a bad code" do
472
- lambda { @oauth.get_access_token("foo") }.should raise_error(Koala::Facebook::OAuthTokenRequestError)
472
+ expect { @oauth.get_access_token("foo") }.to raise_error(Koala::Facebook::OAuthTokenRequestError)
473
473
  end
474
474
  end
475
475
  end
@@ -481,17 +481,17 @@ describe "Koala::Facebook::OAuth" do
481
481
  describe "get_app_access_token_info" do
482
482
  it "properly gets and parses an app's access token as a hash" do
483
483
  result = @oauth.get_app_access_token_info
484
- result.should be_a(Hash)
484
+ expect(result).to be_a(Hash)
485
485
  end
486
486
 
487
487
  it "includes the access token" do
488
488
  result = @oauth.get_app_access_token_info
489
- result["access_token"].should
489
+ expect(result["access_token"]).to be_truthy
490
490
  end
491
491
 
492
492
  it "passes on any options provided to make_request" do
493
493
  options = {:a => 2}
494
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
494
+ expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
495
495
  @oauth.get_app_access_token_info(options)
496
496
  end
497
497
  end
@@ -499,18 +499,18 @@ describe "Koala::Facebook::OAuth" do
499
499
  describe "get_app_access_token" do
500
500
  it "uses get_access_token_info to get and parse an access token token results" do
501
501
  result = @oauth.get_app_access_token
502
- result.should be_a(String)
502
+ expect(result).to be_a(String)
503
503
  end
504
504
 
505
505
  it "returns the access token as a string" do
506
506
  result = @oauth.get_app_access_token
507
507
  original = @oauth.get_app_access_token_info
508
- result.should == original["access_token"]
508
+ expect(result).to eq(original["access_token"])
509
509
  end
510
510
 
511
511
  it "passes on any options provided to make_request" do
512
512
  options = {:a => 2}
513
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
513
+ expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
514
514
  @oauth.get_app_access_token(options)
515
515
  end
516
516
  end
@@ -519,12 +519,12 @@ describe "Koala::Facebook::OAuth" do
519
519
  if KoalaTest.mock_interface? || KoalaTest.oauth_token
520
520
  it "properly gets and parses an app's access token as a hash" do
521
521
  result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
522
- result.should be_a(Hash)
522
+ expect(result).to be_a(Hash)
523
523
  end
524
524
 
525
525
  it "includes the access token" do
526
526
  result = @oauth.exchange_access_token_info(KoalaTest.oauth_token)
527
- result["access_token"].should
527
+ expect(result["access_token"]).not_to be_nil
528
528
  end
529
529
  else
530
530
  pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
@@ -532,25 +532,25 @@ describe "Koala::Facebook::OAuth" do
532
532
 
533
533
  it "passes on any options provided to make_request" do
534
534
  options = {:a => 2}
535
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
535
+ expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
536
536
  @oauth.exchange_access_token_info(KoalaTest.oauth_token, options)
537
537
  end
538
538
 
539
539
  it "raises an error when exchange_access_token_info is called with a bad code" do
540
- lambda { @oauth.exchange_access_token_info("foo") }.should raise_error(Koala::Facebook::OAuthTokenRequestError)
540
+ expect { @oauth.exchange_access_token_info("foo") }.to raise_error(Koala::Facebook::OAuthTokenRequestError)
541
541
  end
542
542
  end
543
543
 
544
544
  describe "exchange_access_token" do
545
545
  it "uses get_access_token_info to get and parse an access token token results" do
546
546
  hash = {"access_token" => Time.now.to_i * rand}
547
- @oauth.stub(:exchange_access_token_info).and_return(hash)
548
- @oauth.exchange_access_token(KoalaTest.oauth_token).should == hash["access_token"]
547
+ allow(@oauth).to receive(:exchange_access_token_info).and_return(hash)
548
+ expect(@oauth.exchange_access_token(KoalaTest.oauth_token)).to eq(hash["access_token"])
549
549
  end
550
550
 
551
551
  it "passes on any options provided to make_request" do
552
552
  options = {:a => 2}
553
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
553
+ expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "", {}))
554
554
  @oauth.exchange_access_token(KoalaTest.oauth_token, options)
555
555
  end
556
556
  end
@@ -563,13 +563,13 @@ describe "Koala::Facebook::OAuth" do
563
563
  it "properly parses access token results" do
564
564
  result = @oauth.send(:parse_access_token, @raw_token_string)
565
565
  has_both_parts = result["access_token"] && result["expires"]
566
- has_both_parts.should
566
+ expect(has_both_parts).to be_truthy
567
567
  end
568
568
 
569
569
  it "properly parses offline access token results" do
570
570
  result = @oauth.send(:parse_access_token, @raw_offline_access_token_string)
571
571
  has_both_parts = result["access_token"] && !result["expires"]
572
- has_both_parts.should
572
+ expect(has_both_parts).to be true
573
573
  end
574
574
 
575
575
  # fetch_token_string
@@ -578,7 +578,7 @@ describe "Koala::Facebook::OAuth" do
578
578
  if KoalaTest.code
579
579
  it "fetches a proper token string from Facebook when given a code" do
580
580
  result = @oauth.send(:fetch_token_string, :code => @code, :redirect_uri => @callback_url)
581
- result.should =~ /^access_token/
581
+ expect(result).to match(/^access_token/)
582
582
  end
583
583
  else
584
584
  it "fetch_token_string code test will not be run since the code field in facebook_data.yml is blank."
@@ -586,7 +586,7 @@ describe "Koala::Facebook::OAuth" do
586
586
 
587
587
  it "fetches a proper token string from Facebook when asked for the app token" do
588
588
  result = @oauth.send(:fetch_token_string, {:grant_type => 'client_credentials'}, true)
589
- result.should =~ /^access_token/
589
+ expect(result).to match(/^access_token/)
590
590
  end
591
591
  end
592
592
  end
@@ -596,41 +596,41 @@ describe "Koala::Facebook::OAuth" do
596
596
  describe "with get_token_info_from_session_keys" do
597
597
  it "gets an array of session keys from Facebook when passed a single key" do
598
598
  result = @oauth.get_tokens_from_session_keys([KoalaTest.session_key])
599
- result.should be_an(Array)
600
- result.length.should == 1
599
+ expect(result).to be_an(Array)
600
+ expect(result.length).to eq(1)
601
601
  end
602
602
 
603
603
  it "gets an array of session keys from Facebook when passed multiple keys" do
604
604
  result = @oauth.get_tokens_from_session_keys(@multiple_session_keys)
605
- result.should be_an(Array)
606
- result.length.should == 2
605
+ expect(result).to be_an(Array)
606
+ expect(result.length).to eq(2)
607
607
  end
608
608
 
609
609
  it "returns the original hashes" do
610
610
  result = @oauth.get_token_info_from_session_keys(@multiple_session_keys)
611
- result[0].should be_a(Hash)
611
+ expect(result[0]).to be_a(Hash)
612
612
  end
613
613
 
614
614
  it "properly handles invalid session keys" do
615
615
  result = @oauth.get_token_info_from_session_keys(["foo", "bar"])
616
616
  #it should return nil for each of the invalid ones
617
- result.each {|r| r.should be_nil}
617
+ result.each {|r| expect(r).to be_nil}
618
618
  end
619
619
 
620
620
  it "properly handles a mix of valid and invalid session keys" do
621
621
  result = @oauth.get_token_info_from_session_keys(["foo"].concat(@multiple_session_keys))
622
622
  # it should return nil for each of the invalid ones
623
- result.each_with_index {|r, index| index > 0 ? r.should(be_a(Hash)) : r.should(be_nil)}
623
+ result.each_with_index {|r, index| index > 0 ? expect(r).to(be_a(Hash)) : expect(r).to(be_nil)}
624
624
  end
625
625
 
626
626
  it "throws a BadFacebookResponse if Facebook returns an empty body (as happens for instance when the API breaks)" do
627
- @oauth.should_receive(:fetch_token_string).and_return("")
628
- lambda { @oauth.get_token_info_from_session_keys(@multiple_session_keys) }.should raise_error(Koala::Facebook::BadFacebookResponse)
627
+ expect(@oauth).to receive(:fetch_token_string).and_return("")
628
+ expect { @oauth.get_token_info_from_session_keys(@multiple_session_keys) }.to raise_error(Koala::Facebook::BadFacebookResponse)
629
629
  end
630
630
 
631
631
  it "passes on any options provided to make_request" do
632
632
  options = {:a => 2}
633
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "[{}]", {}))
633
+ expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "[{}]", {}))
634
634
  @oauth.get_token_info_from_session_keys([], options)
635
635
  end
636
636
  end
@@ -638,31 +638,31 @@ describe "Koala::Facebook::OAuth" do
638
638
  describe "with get_tokens_from_session_keys" do
639
639
  it "calls get_token_info_from_session_keys" do
640
640
  args = @multiple_session_keys
641
- @oauth.should_receive(:get_token_info_from_session_keys).with(args, anything).and_return([])
641
+ expect(@oauth).to receive(:get_token_info_from_session_keys).with(args, anything).and_return([])
642
642
  @oauth.get_tokens_from_session_keys(args)
643
643
  end
644
644
 
645
645
  it "returns an array of strings" do
646
646
  args = @multiple_session_keys
647
647
  result = @oauth.get_tokens_from_session_keys(args)
648
- result.each {|r| r.should be_a(String) }
648
+ result.each {|r| expect(r).to be_a(String) }
649
649
  end
650
650
 
651
651
  it "properly handles invalid session keys" do
652
652
  result = @oauth.get_tokens_from_session_keys(["foo", "bar"])
653
653
  # it should return nil for each of the invalid ones
654
- result.each {|r| r.should be_nil}
654
+ result.each {|r| expect(r).to be_nil}
655
655
  end
656
656
 
657
657
  it "properly handles a mix of valid and invalid session keys" do
658
658
  result = @oauth.get_tokens_from_session_keys(["foo"].concat(@multiple_session_keys))
659
659
  # it should return nil for each of the invalid ones
660
- result.each_with_index {|r, index| index > 0 ? r.should(be_a(String)) : r.should(be_nil)}
660
+ result.each_with_index {|r, index| index > 0 ? expect(r).to(be_a(String)) : expect(r).to(be_nil)}
661
661
  end
662
662
 
663
663
  it "passes on any options provided to make_request" do
664
664
  options = {:a => 2}
665
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "[{}]", {}))
665
+ expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "[{}]", {}))
666
666
  @oauth.get_tokens_from_session_keys([], options)
667
667
  end
668
668
  end
@@ -670,29 +670,29 @@ describe "Koala::Facebook::OAuth" do
670
670
  describe "get_token_from_session_key" do
671
671
  it "calls get_tokens_from_session_keys when the get_token_from_session_key is called" do
672
672
  key = KoalaTest.session_key
673
- @oauth.should_receive(:get_tokens_from_session_keys).with([key], anything).and_return([])
673
+ expect(@oauth).to receive(:get_tokens_from_session_keys).with([key], anything).and_return([])
674
674
  @oauth.get_token_from_session_key(key)
675
675
  end
676
676
 
677
677
  it "gets back the access token string from get_token_from_session_key" do
678
678
  result = @oauth.get_token_from_session_key(KoalaTest.session_key)
679
- result.should be_a(String)
679
+ expect(result).to be_a(String)
680
680
  end
681
681
 
682
682
  it "returns the first value in the array" do
683
683
  result = @oauth.get_token_from_session_key(KoalaTest.session_key)
684
684
  array = @oauth.get_tokens_from_session_keys([KoalaTest.session_key])
685
- result.should == array[0]
685
+ expect(result).to eq(array[0])
686
686
  end
687
687
 
688
688
  it "properly handles an invalid session key" do
689
689
  result = @oauth.get_token_from_session_key("foo")
690
- result.should be_nil
690
+ expect(result).to be_nil
691
691
  end
692
692
 
693
693
  it "passes on any options provided to make_request" do
694
694
  options = {:a => 2}
695
- Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "[{}]", {}))
695
+ expect(Koala).to receive(:make_request).with(anything, anything, anything, hash_including(options)).and_return(Koala::HTTPService::Response.new(200, "[{}]", {}))
696
696
  @oauth.get_token_from_session_key("", options)
697
697
  end
698
698
  end
@@ -705,24 +705,24 @@ describe "Koala::Facebook::OAuth" do
705
705
  # the signed request code is ported directly from Facebook
706
706
  # so we only need to test at a high level that it works
707
707
  it "throws an error if the algorithm is unsupported" do
708
- MultiJson.stub(:load).and_return("algorithm" => "my fun algorithm")
709
- lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
708
+ allow(MultiJson).to receive(:load).and_return("algorithm" => "my fun algorithm")
709
+ expect { @oauth.parse_signed_request(@signed_request) }.to raise_error
710
710
  end
711
711
 
712
712
  it "throws an error if the signature is invalid" do
713
- OpenSSL::HMAC.stub(:hexdigest).and_return("i'm an invalid signature")
714
- lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
713
+ allow(OpenSSL::HMAC).to receive(:hexdigest).and_return("i'm an invalid signature")
714
+ expect { @oauth.parse_signed_request(@signed_request) }.to raise_error
715
715
  end
716
716
 
717
717
  it "throws an error if the signature string is empty" do
718
718
  # this occasionally happens due to Facebook error
719
- lambda { @oauth.parse_signed_request("") }.should raise_error
720
- lambda { @oauth.parse_signed_request("abc-def") }.should raise_error
719
+ expect { @oauth.parse_signed_request("") }.to raise_error
720
+ expect { @oauth.parse_signed_request("abc-def") }.to raise_error
721
721
  end
722
722
 
723
723
  it "properly parses requests" do
724
724
  @oauth = Koala::Facebook::OAuth.new(@app_id, @secret || @app_secret)
725
- @oauth.parse_signed_request(@signed_params).should == @signed_params_result
725
+ expect(@oauth.parse_signed_request(@signed_params)).to eq(@signed_params_result)
726
726
  end
727
727
  end
728
728