koala 1.8.0 → 1.9.0rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,21 +17,21 @@ describe 'Koala::Facebook::GraphAPIMethods' do
17
17
  # and the other methods which do some post-processing locally
18
18
  context '#get_object' do
19
19
  it 'returns result of block' do
20
- @api.stub(:api).and_return(double("other results"))
21
- @api.get_object('koppel', &post_processing)["result"].should == result
20
+ allow(@api).to receive(:api).and_return(double("other results"))
21
+ expect(@api.get_object('koppel', &post_processing)["result"]).to eq(result)
22
22
  end
23
23
  end
24
24
 
25
25
  context '#get_picture' do
26
26
  it 'returns result of block' do
27
- @api.stub(:api).and_return("Location" => double("other result"))
28
- @api.get_picture('lukeshepard', &post_processing)["result"].should == result
27
+ allow(@api).to receive(:api).and_return("Location" => double("other result"))
28
+ expect(@api.get_picture('lukeshepard', &post_processing)["result"]).to eq(result)
29
29
  end
30
30
  end
31
31
 
32
32
  context '#fql_multiquery' do
33
33
  before do
34
- @api.should_receive(:get_object).and_return([
34
+ expect(@api).to receive(:get_object).and_return([
35
35
  {"name" => "query1", "fql_result_set" => [{"id" => 123}]},
36
36
  {"name" => "query2", "fql_result_set" => ["id" => 456]}
37
37
  ])
@@ -43,18 +43,41 @@ describe 'Koala::Facebook::GraphAPIMethods' do
43
43
  'query2' => [{'id' => 456}]
44
44
  }
45
45
  response = @api.fql_multiquery({}, &post_processing)
46
- response["args"].should == resolved_result
47
- response["result"].should == result
46
+ expect(response["args"]).to eq(resolved_result)
47
+ expect(response["result"]).to eq(result)
48
48
  end
49
49
  end
50
50
 
51
51
  context '#get_page_access_token' do
52
52
  it 'returns result of block' do
53
53
  token = Koala::MockHTTPService::APP_ACCESS_TOKEN
54
- @api.stub(:api).and_return("access_token" => token)
54
+ allow(@api).to receive(:api).and_return("access_token" => token)
55
55
  response = @api.get_page_access_token('facebook', &post_processing)
56
- response["args"].should == token
57
- response["result"].should == result
56
+ expect(response["args"]).to eq(token)
57
+ expect(response["result"]).to eq(result)
58
+ end
59
+ end
60
+ end
61
+
62
+ context '#graph_call' do
63
+ describe "the appsecret_proof option" do
64
+ let(:path) { '/path' }
65
+
66
+ it "is enabled by default if an app secret is present" do
67
+ api = Koala::Facebook::API.new(@token, "mysecret")
68
+ expect(api).to receive(:api).with(path, {}, 'get', :appsecret_proof => true)
69
+ api.graph_call(path)
70
+ end
71
+
72
+ it "can be disabled manually" do
73
+ api = Koala::Facebook::API.new(@token, "mysecret")
74
+ expect(api).to receive(:api).with(path, {}, 'get', hash_not_including(appsecret_proof: true))
75
+ api.graph_call(path, {}, "get", appsecret_proof: false)
76
+ end
77
+
78
+ it "isn't included if no app secret is present" do
79
+ expect(@api).to receive(:api).with(path, {}, 'get', {})
80
+ @api.graph_call(path)
58
81
  end
59
82
  end
60
83
  end
@@ -13,32 +13,32 @@ describe Koala::Facebook::GraphCollection do
13
13
  end
14
14
 
15
15
  it "subclasses Array" do
16
- Koala::Facebook::GraphCollection.ancestors.should include(Array)
16
+ expect(Koala::Facebook::GraphCollection.ancestors).to include(Array)
17
17
  end
18
18
 
19
19
  it "creates an array-like object" do
20
- Koala::Facebook::GraphCollection.new(@result, @api).should be_an(Array)
20
+ expect(Koala::Facebook::GraphCollection.new(@result, @api)).to be_an(Array)
21
21
  end
22
22
 
23
23
  it "contains the result data" do
24
- @result["data"].each_with_index {|r, i| @collection[i].should == r}
24
+ @result["data"].each_with_index {|r, i| expect(@collection[i]).to eq(r)}
25
25
  end
26
26
 
27
27
  it "has a read-only paging attribute" do
28
- @collection.methods.map(&:to_sym).should include(:paging)
29
- @collection.methods.map(&:to_sym).should_not include(:paging=)
28
+ expect(@collection.methods.map(&:to_sym)).to include(:paging)
29
+ expect(@collection.methods.map(&:to_sym)).not_to include(:paging=)
30
30
  end
31
31
 
32
32
  it "sets paging to results['paging']" do
33
- @collection.paging.should == @result["paging"]
33
+ expect(@collection.paging).to eq(@result["paging"])
34
34
  end
35
35
 
36
36
  it "sets raw_response to the original results" do
37
- @collection.raw_response.should == @result
37
+ expect(@collection.raw_response).to eq(@result)
38
38
  end
39
39
 
40
40
  it "sets the API to the provided API" do
41
- @collection.api.should == @api
41
+ expect(@collection.api).to eq(@api)
42
42
  end
43
43
 
44
44
  describe "when getting a whole page" do
@@ -53,24 +53,24 @@ describe Koala::Facebook::GraphCollection do
53
53
  end
54
54
 
55
55
  it "should return the previous page of results" do
56
- @collection.should_receive(:previous_page_params).and_return([@base, @args])
57
- @api.should_receive(:api).with(@base, @args, anything, anything).and_return(@second_page)
58
- Koala::Facebook::GraphCollection.should_receive(:new).with(@second_page, @api).and_return(@page_of_results)
59
- @collection.previous_page.should == @page_of_results
56
+ expect(@collection).to receive(:previous_page_params).and_return([@base, @args])
57
+ expect(@api).to receive(:api).with(@base, @args, anything, anything).and_return(@second_page)
58
+ expect(Koala::Facebook::GraphCollection).to receive(:new).with(@second_page, @api).and_return(@page_of_results)
59
+ expect(@collection.previous_page).to eq(@page_of_results)
60
60
  end
61
61
 
62
62
  it "should return the next page of results" do
63
- @collection.should_receive(:next_page_params).and_return([@base, @args])
64
- @api.should_receive(:api).with(@base, @args, anything, anything).and_return(@second_page)
65
- Koala::Facebook::GraphCollection.should_receive(:new).with(@second_page, @api).and_return(@page_of_results)
63
+ expect(@collection).to receive(:next_page_params).and_return([@base, @args])
64
+ expect(@api).to receive(:api).with(@base, @args, anything, anything).and_return(@second_page)
65
+ expect(Koala::Facebook::GraphCollection).to receive(:new).with(@second_page, @api).and_return(@page_of_results)
66
66
 
67
- @collection.next_page.should == @page_of_results
67
+ expect(@collection.next_page).to eq(@page_of_results)
68
68
  end
69
69
 
70
70
  it "should return nil it there are no other pages" do
71
71
  %w{next previous}.each do |this|
72
- @collection.should_receive("#{this}_page_params".to_sym).and_return(nil)
73
- @collection.send("#{this}_page").should == nil
72
+ expect(@collection).to receive("#{this}_page_params".to_sym).and_return(nil)
73
+ expect(@collection.send("#{this}_page")).to eq(nil)
74
74
  end
75
75
  end
76
76
  end
@@ -79,38 +79,38 @@ describe Koala::Facebook::GraphCollection do
79
79
  describe "#parse_page_url" do
80
80
  it "should pass the url to the class method" do
81
81
  url = double("url")
82
- Koala::Facebook::GraphCollection.should_receive(:parse_page_url).with(url)
82
+ expect(Koala::Facebook::GraphCollection).to receive(:parse_page_url).with(url)
83
83
  @collection.parse_page_url(url)
84
84
  end
85
85
 
86
86
  it "should return the result of the class method" do
87
87
  parsed_content = double("parsed_content")
88
- Koala::Facebook::GraphCollection.stub(:parse_page_url).and_return(parsed_content)
89
- @collection.parse_page_url(double("url")).should == parsed_content
88
+ allow(Koala::Facebook::GraphCollection).to receive(:parse_page_url).and_return(parsed_content)
89
+ expect(@collection.parse_page_url(double("url"))).to eq(parsed_content)
90
90
  end
91
91
  end
92
92
 
93
93
  describe ".parse_page_url" do
94
94
  it "should return the base as the first array entry" do
95
95
  base = "url_path"
96
- Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?anything").first.should == base
96
+ expect(Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?anything").first).to eq(base)
97
97
  end
98
98
 
99
99
  it "should return the arguments as a hash as the last array entry" do
100
100
  args_hash = {"one" => "val_one", "two" => "val_two"}
101
- Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last.should == args_hash
101
+ expect(Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/anything?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").last).to eq(args_hash)
102
102
  end
103
103
 
104
104
  it "works with non-.com addresses" do
105
105
  base = "url_path"
106
106
  args_hash = {"one" => "val_one", "two" => "val_two"}
107
- Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}").should == [base, args_hash]
107
+ expect(Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/#{base}?#{args_hash.map {|k,v| "#{k}=#{v}" }.join("&")}")).to eq([base, args_hash])
108
108
  end
109
109
 
110
110
  it "works with addresses with irregular characters" do
111
111
  access_token = "appid123a|fdcba"
112
112
  base, args_hash = Koala::Facebook::GraphCollection.parse_page_url("http://facebook.com/foo?token=#{access_token}")
113
- args_hash["token"].should == access_token
113
+ expect(args_hash["token"]).to eq(access_token)
114
114
  end
115
115
  end
116
116
  end
@@ -118,29 +118,29 @@ describe Koala::Facebook::GraphCollection do
118
118
  describe ".evaluate" do
119
119
  it "returns the original result if it's provided a non-hash result" do
120
120
  result = []
121
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
121
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(result)
122
122
  end
123
123
 
124
124
  it "returns the original result if it's provided a nil result" do
125
125
  result = nil
126
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
126
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(result)
127
127
  end
128
128
 
129
129
  it "returns the original result if the result doesn't have a data key" do
130
130
  result = {"paging" => {}}
131
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
131
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(result)
132
132
  end
133
133
 
134
134
  it "returns the original result if the result's data key isn't an array" do
135
135
  result = {"data" => {}, "paging" => {}}
136
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == result
136
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(result)
137
137
  end
138
138
 
139
139
  it "returns a new GraphCollection of the result if it has an array data key and a paging key" do
140
140
  result = {"data" => [], "paging" => {}}
141
141
  expected = :foo
142
- Koala::Facebook::GraphCollection.should_receive(:new).with(result, @api).and_return(expected)
143
- Koala::Facebook::GraphCollection.evaluate(result, @api).should == expected
142
+ expect(Koala::Facebook::GraphCollection).to receive(:new).with(result, @api).and_return(expected)
143
+ expect(Koala::Facebook::GraphCollection.evaluate(result, @api)).to eq(expected)
144
144
  end
145
145
  end
146
146
 
@@ -148,12 +148,12 @@ describe Koala::Facebook::GraphCollection do
148
148
  let(:paging){ {"next" => "http://example.com/?a=2&b=3"} }
149
149
 
150
150
  it "should get next page" do
151
- @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
151
+ expect(@api).to receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
152
152
  @collection.next_page
153
153
  end
154
154
 
155
155
  it "should get next page with extra parameters" do
156
- @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
156
+ expect(@api).to receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
157
157
  @collection.next_page("c" => "4")
158
158
  end
159
159
  end
@@ -162,12 +162,12 @@ describe Koala::Facebook::GraphCollection do
162
162
  let(:paging){ {"previous" => "http://example.com/?a=2&b=3"} }
163
163
 
164
164
  it "should get previous page" do
165
- @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
165
+ expect(@api).to receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
166
166
  @collection.previous_page
167
167
  end
168
168
 
169
169
  it "should get previous page with extra parameters" do
170
- @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
170
+ expect(@api).to receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
171
171
  @collection.previous_page("c" => "4")
172
172
  end
173
173
  end
@@ -2,45 +2,45 @@ require 'spec_helper'
2
2
 
3
3
  describe Koala::HTTPService do
4
4
  it "has a faraday_middleware accessor" do
5
- Koala::HTTPService.methods.map(&:to_sym).should include(:faraday_middleware)
6
- Koala::HTTPService.methods.map(&:to_sym).should include(:faraday_middleware=)
5
+ expect(Koala::HTTPService.methods.map(&:to_sym)).to include(:faraday_middleware)
6
+ expect(Koala::HTTPService.methods.map(&:to_sym)).to include(:faraday_middleware=)
7
7
  end
8
8
 
9
9
  it "has an http_options accessor" do
10
- Koala::HTTPService.should respond_to(:http_options)
11
- Koala::HTTPService.should respond_to(:http_options=)
10
+ expect(Koala::HTTPService).to respond_to(:http_options)
11
+ expect(Koala::HTTPService).to respond_to(:http_options=)
12
12
  end
13
13
 
14
14
  it "sets http_options to {} by default" do
15
- Koala::HTTPService.http_options.should == {}
15
+ expect(Koala::HTTPService.http_options).to eq({})
16
16
  end
17
17
 
18
18
  describe "DEFAULT_MIDDLEWARE" do
19
19
  before :each do
20
20
  @builder = double("Faraday connection builder")
21
- @builder.stub(:request)
22
- @builder.stub(:adapter)
23
- @builder.stub(:use)
21
+ allow(@builder).to receive(:request)
22
+ allow(@builder).to receive(:adapter)
23
+ allow(@builder).to receive(:use)
24
24
  end
25
25
 
26
26
  it "is defined" do
27
- Koala::HTTPService.const_defined?("DEFAULT_MIDDLEWARE").should be_true
27
+ expect(Koala::HTTPService.const_defined?("DEFAULT_MIDDLEWARE")).to be_truthy
28
28
  end
29
29
 
30
30
  it "adds multipart" do
31
- @builder.should_receive(:use).with(Koala::HTTPService::MultipartRequest)
31
+ expect(@builder).to receive(:use).with(Koala::HTTPService::MultipartRequest)
32
32
  Koala::HTTPService::DEFAULT_MIDDLEWARE.call(@builder)
33
33
  end
34
34
 
35
35
  it "adds url_encoded" do
36
- @builder.should_receive(:request).with(:url_encoded)
36
+ expect(@builder).to receive(:request).with(:url_encoded)
37
37
  Koala::HTTPService::DEFAULT_MIDDLEWARE.call(@builder)
38
38
  end
39
39
 
40
40
  it "uses the default adapter" do
41
41
  adapter = :testing_now
42
- Faraday.stub(:default_adapter).and_return(adapter)
43
- @builder.should_receive(:adapter).with(adapter)
42
+ allow(Faraday).to receive(:default_adapter).and_return(adapter)
43
+ expect(@builder).to receive(:adapter).with(adapter)
44
44
  Koala::HTTPService::DEFAULT_MIDDLEWARE.call(@builder)
45
45
  end
46
46
  end
@@ -49,39 +49,39 @@ describe Koala::HTTPService do
49
49
  let(:defaults) { Koala::HTTPService::DEFAULT_SERVERS }
50
50
 
51
51
  it "defines the graph server" do
52
- defaults[:graph_server].should == "graph.facebook.com"
52
+ expect(defaults[:graph_server]).to eq("graph.facebook.com")
53
53
  end
54
54
 
55
55
  it "defines the rest server" do
56
- defaults[:rest_server].should == "api.facebook.com"
56
+ expect(defaults[:rest_server]).to eq("api.facebook.com")
57
57
  end
58
58
 
59
59
  it "defines the dialog host" do
60
- defaults[:dialog_host].should == "www.facebook.com"
60
+ expect(defaults[:dialog_host]).to eq("www.facebook.com")
61
61
  end
62
62
 
63
63
  it "defines the path replacement regular expression" do
64
- defaults[:host_path_matcher].should == /\.facebook/
64
+ expect(defaults[:host_path_matcher]).to eq(/\.facebook/)
65
65
  end
66
66
 
67
67
  it "defines the video server replacement for uploads" do
68
- defaults[:video_replace].should == "-video.facebook"
68
+ expect(defaults[:video_replace]).to eq("-video.facebook")
69
69
  end
70
70
 
71
71
  it "defines the beta tier replacement" do
72
- defaults[:beta_replace].should == ".beta.facebook"
72
+ expect(defaults[:beta_replace]).to eq(".beta.facebook")
73
73
  end
74
74
  end
75
75
 
76
76
  describe "server" do
77
77
  describe "with no options" do
78
78
  it "returns the REST server if options[:rest_api]" do
79
- Koala::HTTPService.server(:rest_api => true).should =~ Regexp.new(Koala.config.rest_server)
79
+ expect(Koala::HTTPService.server(:rest_api => true)).to match(Regexp.new(Koala.config.rest_server))
80
80
  end
81
81
 
82
82
  it "returns the graph server if !options[:rest_api]" do
83
- Koala::HTTPService.server(:rest_api => false).should =~ Regexp.new(Koala.config.graph_server)
84
- Koala::HTTPService.server({}).should =~ Regexp.new(Koala.config.graph_server)
83
+ expect(Koala::HTTPService.server(:rest_api => false)).to match(Regexp.new(Koala.config.graph_server))
84
+ expect(Koala::HTTPService.server({})).to match(Regexp.new(Koala.config.graph_server))
85
85
  end
86
86
  end
87
87
 
@@ -92,12 +92,12 @@ describe Koala::HTTPService do
92
92
 
93
93
  it "returns the beta REST server if options[:rest_api]" do
94
94
  server = Koala::HTTPService.server(@options.merge(:rest_api => true))
95
- server.should =~ Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, ".beta.facebook"))
95
+ expect(server).to match(Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, ".beta.facebook")))
96
96
  end
97
97
 
98
98
  it "returns the beta rest server if !options[:rest_api]" do
99
99
  server = Koala::HTTPService.server(@options)
100
- server.should =~ Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, ".beta.facebook"))
100
+ expect(server).to match(Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, ".beta.facebook")))
101
101
  end
102
102
  end
103
103
 
@@ -108,26 +108,26 @@ describe Koala::HTTPService do
108
108
 
109
109
  it "returns the REST video server if options[:rest_api]" do
110
110
  server = Koala::HTTPService.server(@options.merge(:rest_api => true))
111
- server.should =~ Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, "-video.facebook"))
111
+ expect(server).to match(Regexp.new(Koala.config.rest_server.gsub(/\.facebook/, "-video.facebook")))
112
112
  end
113
113
 
114
114
  it "returns the graph video server if !options[:rest_api]" do
115
115
  server = Koala::HTTPService.server(@options)
116
- server.should =~ Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, "-video.facebook"))
116
+ expect(server).to match(Regexp.new(Koala.config.graph_server.gsub(/\.facebook/, "-video.facebook")))
117
117
  end
118
118
  end
119
119
  end
120
120
 
121
121
  describe ".encode_params" do
122
122
  it "returns an empty string if param_hash evaluates to false" do
123
- Koala::HTTPService.encode_params(nil).should == ''
123
+ expect(Koala::HTTPService.encode_params(nil)).to eq('')
124
124
  end
125
125
 
126
126
  it "converts values to JSON if the value is not a String" do
127
127
  val = 'json_value'
128
128
  not_a_string = 'not_a_string'
129
- not_a_string.stub(:is_a?).and_return(false)
130
- MultiJson.should_receive(:dump).with(not_a_string).and_return(val)
129
+ allow(not_a_string).to receive(:is_a?).and_return(false)
130
+ expect(MultiJson).to receive(:dump).with(not_a_string).and_return(val)
131
131
 
132
132
  string = "hi"
133
133
 
@@ -137,9 +137,9 @@ describe Koala::HTTPService do
137
137
  }
138
138
 
139
139
  result = Koala::HTTPService.encode_params(args)
140
- result.split('&').find do |key_and_val|
140
+ expect(result.split('&').find do |key_and_val|
141
141
  key_and_val.match("#{not_a_string}=#{val}")
142
- end.should be_true
142
+ end).to be_truthy
143
143
  end
144
144
 
145
145
  it "escapes all values" do
@@ -148,7 +148,7 @@ describe Koala::HTTPService do
148
148
  result = Koala::HTTPService.encode_params(args)
149
149
  result.split('&').each do |key_val|
150
150
  key, val = key_val.split('=')
151
- val.should == CGI.escape(args[key])
151
+ expect(val).to eq(CGI.escape(args[key]))
152
152
  end
153
153
  end
154
154
 
@@ -156,7 +156,7 @@ describe Koala::HTTPService do
156
156
  args = {:b => '2', 'a' => '1'}
157
157
 
158
158
  result = Koala::HTTPService.encode_params(args)
159
- result.split('&').map{|key_val| key_val.split('=')[0]}.should == ['a', 'b']
159
+ expect(result.split('&').map{|key_val| key_val.split('=')[0]}).to eq(['a', 'b'])
160
160
  end
161
161
 
162
162
  it "converts all keys to Strings" do
@@ -165,7 +165,7 @@ describe Koala::HTTPService do
165
165
  result = Koala::HTTPService.encode_params(args)
166
166
  result.split('&').each do |key_val|
167
167
  key, val = key_val.split('=')
168
- key.should == args.find{|key_val_arr| key_val_arr.last == val}.first.to_s
168
+ expect(key).to eq(args.find{|key_val_arr| key_val_arr.last == val}.first.to_s)
169
169
  end
170
170
  end
171
171
  end
@@ -178,103 +178,103 @@ describe Koala::HTTPService do
178
178
  @mock_http_response = double("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
179
179
 
180
180
  @mock_connection = double("Faraday connection")
181
- @mock_connection.stub(:get).and_return(@mock_http_response)
182
- @mock_connection.stub(:post).and_return(@mock_http_response)
183
- Faraday.stub(:new).and_return(@mock_connection)
181
+ allow(@mock_connection).to receive(:get).and_return(@mock_http_response)
182
+ allow(@mock_connection).to receive(:post).and_return(@mock_http_response)
183
+ allow(Faraday).to receive(:new).and_return(@mock_connection)
184
184
  end
185
185
 
186
186
  describe "creating the Faraday connection" do
187
187
  it "creates a Faraday connection using the server" do
188
188
  server = "foo"
189
- Koala::HTTPService.stub(:server).and_return(server)
190
- Faraday.should_receive(:new).with(server, anything).and_return(@mock_connection)
189
+ allow(Koala::HTTPService).to receive(:server).and_return(server)
190
+ expect(Faraday).to receive(:new).with(server, anything).and_return(@mock_connection)
191
191
  Koala::HTTPService.make_request("anything", {}, "anything")
192
192
  end
193
193
 
194
194
  it "merges Koala::HTTPService.http_options into the request params" do
195
195
  http_options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
196
196
  Koala::HTTPService.http_options = http_options
197
- Faraday.should_receive(:new).with(anything, hash_including(http_options)).and_return(@mock_connection)
197
+ expect(Faraday).to receive(:new).with(anything, hash_including(http_options)).and_return(@mock_connection)
198
198
  Koala::HTTPService.make_request("anything", {}, "get")
199
199
  end
200
200
 
201
201
  it "does not merge invalid Faraday options from Koala::HTTPService.http_options into the request params" do
202
202
  http_options = {:invalid => "fake param"}
203
203
  Koala::HTTPService.http_options = http_options
204
- Faraday.should_receive(:new).with(anything, hash_not_including(http_options)).and_return(@mock_connection)
204
+ expect(Faraday).to receive(:new).with(anything, hash_not_including(http_options)).and_return(@mock_connection)
205
205
  Koala::HTTPService.make_request("anything", {}, "get")
206
206
  end
207
207
 
208
208
  it "merges any provided options into the request params" do
209
209
  options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
210
- Faraday.should_receive(:new).with(anything, hash_including(options)).and_return(@mock_connection)
210
+ expect(Faraday).to receive(:new).with(anything, hash_including(options)).and_return(@mock_connection)
211
211
  Koala::HTTPService.make_request("anything", {}, "get", options)
212
212
  end
213
213
 
214
214
  it "overrides Koala::HTTPService.http_options with any provided options for the request params" do
215
215
  options = {:proxy => "http://user:password@proxy.org/", :request => { :timeout => 10 }}
216
216
  http_options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
217
- Koala::HTTPService.stub(:http_options).and_return(http_options)
217
+ allow(Koala::HTTPService).to receive(:http_options).and_return(http_options)
218
218
 
219
- Faraday.should_receive(:new).with(anything, hash_including(http_options.merge(options))).and_return(@mock_connection)
219
+ expect(Faraday).to receive(:new).with(anything, hash_including(http_options.merge(options))).and_return(@mock_connection)
220
220
  Koala::HTTPService.make_request("anything", {}, "get", options)
221
221
  end
222
222
 
223
223
  it "forces use_ssl to true if an access token is present" do
224
224
  options = {:use_ssl => false}
225
- Koala::HTTPService.stub(:http_options).and_return(:use_ssl => false)
226
- Faraday.should_receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
225
+ allow(Koala::HTTPService).to receive(:http_options).and_return(:use_ssl => false)
226
+ expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
227
227
  Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
228
228
  end
229
229
 
230
230
  it "defaults verify to true if use_ssl is true" do
231
- Faraday.should_receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
231
+ expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
232
232
  Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get")
233
233
  end
234
234
 
235
235
  it "allows you to set other verify modes if you really want" do
236
236
  options = {:ssl => {:verify => :foo}}
237
- Faraday.should_receive(:new).with(anything, hash_including(options)).and_return(@mock_connection)
237
+ expect(Faraday).to receive(:new).with(anything, hash_including(options)).and_return(@mock_connection)
238
238
  Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
239
239
  end
240
240
 
241
241
  it "calls server with the composite options" do
242
242
  options = {:a => 2, :c => "3"}
243
243
  http_options = {:a => :a}
244
- Koala::HTTPService.stub(:http_options).and_return(http_options)
245
- Koala::HTTPService.should_receive(:server).with(hash_including(http_options.merge(options))).and_return("foo")
244
+ allow(Koala::HTTPService).to receive(:http_options).and_return(http_options)
245
+ expect(Koala::HTTPService).to receive(:server).with(hash_including(http_options.merge(options))).and_return("foo")
246
246
  Koala::HTTPService.make_request("anything", {}, "get", options)
247
247
  end
248
248
 
249
249
  it "uses the default builder block if HTTPService.faraday_middleware block is not defined" do
250
250
  block = Proc.new {}
251
251
  stub_const("Koala::HTTPService::DEFAULT_MIDDLEWARE", block)
252
- Koala::HTTPService.stub(:faraday_middleware).and_return(nil)
253
- Faraday.should_receive(:new).with(anything, anything, &block).and_return(@mock_connection)
252
+ allow(Koala::HTTPService).to receive(:faraday_middleware).and_return(nil)
253
+ expect(Faraday).to receive(:new).with(anything, anything, &block).and_return(@mock_connection)
254
254
  Koala::HTTPService.make_request("anything", {}, "get")
255
255
  end
256
256
 
257
257
  it "uses the defined HTTPService.faraday_middleware block if defined" do
258
258
  block = Proc.new { }
259
- Koala::HTTPService.should_receive(:faraday_middleware).and_return(block)
260
- Faraday.should_receive(:new).with(anything, anything, &block).and_return(@mock_connection)
259
+ expect(Koala::HTTPService).to receive(:faraday_middleware).and_return(block)
260
+ expect(Faraday).to receive(:new).with(anything, anything, &block).and_return(@mock_connection)
261
261
  Koala::HTTPService.make_request("anything", {}, "get")
262
262
  end
263
263
  end
264
264
 
265
265
  it "makes a POST request if the verb isn't get" do
266
- @mock_connection.should_receive(:post).and_return(@mock_http_response)
266
+ expect(@mock_connection).to receive(:post).and_return(@mock_http_response)
267
267
  Koala::HTTPService.make_request("anything", {}, "anything")
268
268
  end
269
269
 
270
270
  it "includes the verb in the body if the verb isn't get" do
271
271
  verb = "eat"
272
- @mock_connection.should_receive(:post).with(anything, hash_including("method" => verb)).and_return(@mock_http_response)
272
+ expect(@mock_connection).to receive(:post).with(anything, hash_including("method" => verb)).and_return(@mock_http_response)
273
273
  Koala::HTTPService.make_request("anything", {}, verb)
274
274
  end
275
275
 
276
276
  it "makes a GET request if the verb is get" do
277
- @mock_connection.should_receive(:get).and_return(@mock_http_response)
277
+ expect(@mock_connection).to receive(:get).and_return(@mock_http_response)
278
278
  Koala::HTTPService.make_request("anything", {}, "get")
279
279
  end
280
280
 
@@ -282,27 +282,27 @@ describe Koala::HTTPService do
282
282
  it "submits the arguments in the body" do
283
283
  # technically this is done for all requests, but you don't send GET requests with files
284
284
  args = {"a" => :b, "c" => 3}
285
- Faraday.should_receive(:new).with(anything, hash_including(:params => args)).and_return(@mock_connection)
285
+ expect(Faraday).to receive(:new).with(anything, hash_including(:params => args)).and_return(@mock_connection)
286
286
  Koala::HTTPService.make_request("anything", args, "get")
287
287
  end
288
288
 
289
289
  it "submits nothing to the body" do
290
290
  # technically this is done for all requests, but you don't send GET requests with files
291
291
  args = {"a" => :b, "c" => 3}
292
- @mock_connection.should_receive(:get).with(anything, {}).and_return(@mock_http_response)
292
+ expect(@mock_connection).to receive(:get).with(anything, {}).and_return(@mock_http_response)
293
293
  Koala::HTTPService.make_request("anything", args, "get")
294
294
  end
295
295
 
296
296
  it "logs verb, url and params to debug" do
297
297
  args = {"a" => :b, "c" => 3}
298
298
  log_message_stem = "GET: anything params: "
299
- Koala::Utils.logger.should_receive(:debug) do |log_message|
299
+ expect(Koala::Utils.logger).to receive(:debug) do |log_message|
300
300
  # unordered hashes are a bane
301
301
  # Ruby in 1.8 modes tends to return different hash orderings,
302
302
  # which makes checking the content of the stringified hash hard
303
303
  # it's enough just to ensure that there's hash content in the string, I think
304
- log_message.should include(log_message_stem)
305
- log_message.match(/\{.*\}/).should_not be_nil
304
+ expect(log_message).to include(log_message_stem)
305
+ expect(log_message.match(/\{.*\}/)).not_to be_nil
306
306
  end
307
307
 
308
308
  Koala::HTTPService.make_request("anything", args, "get")
@@ -313,7 +313,7 @@ describe Koala::HTTPService do
313
313
  it "submits the arguments in the body" do
314
314
  # technically this is done for all requests, but you don't send GET requests with files
315
315
  args = {"a" => :b, "c" => 3}
316
- @mock_connection.should_receive(:post).with(anything, hash_including(args)).and_return(@mock_http_response)
316
+ expect(@mock_connection).to receive(:post).with(anything, hash_including(args)).and_return(@mock_http_response)
317
317
  Koala::HTTPService.make_request("anything", args, "post")
318
318
  end
319
319
 
@@ -321,21 +321,21 @@ describe Koala::HTTPService do
321
321
  # technically this is done for all requests, but you don't send GET requests with files
322
322
  upload_io = double("UploadIO")
323
323
  u = Koala::UploadableIO.new("/path/to/stuff", "img/jpg")
324
- u.stub(:to_upload_io).and_return(upload_io)
325
- @mock_connection.should_receive(:post).with(anything, hash_including("source" => upload_io)).and_return(@mock_http_response)
324
+ allow(u).to receive(:to_upload_io).and_return(upload_io)
325
+ expect(@mock_connection).to receive(:post).with(anything, hash_including("source" => upload_io)).and_return(@mock_http_response)
326
326
  Koala::HTTPService.make_request("anything", {:source => u}, "post")
327
327
  end
328
328
 
329
329
  it "logs verb, url and params to debug" do
330
330
  args = {"a" => :b, "c" => 3}
331
331
  log_message_stem = "POST: anything params: "
332
- Koala::Utils.logger.should_receive(:debug) do |log_message|
332
+ expect(Koala::Utils.logger).to receive(:debug) do |log_message|
333
333
  # unordered hashes are a bane
334
334
  # Ruby in 1.8 modes tends to return different hash orderings,
335
335
  # which makes checking the content of the stringified hash hard
336
336
  # it's enough just to ensure that there's hash content in the string, I think
337
- log_message.should include(log_message_stem)
338
- log_message.match(/\{.*\}/).should_not be_nil
337
+ expect(log_message).to include(log_message_stem)
338
+ expect(log_message.match(/\{.*\}/)).not_to be_nil
339
339
  end
340
340
  Koala::HTTPService.make_request("anything", args, "post")
341
341
  end
@@ -344,7 +344,7 @@ describe Koala::HTTPService do
344
344
 
345
345
  describe "deprecated options" do
346
346
  before :each do
347
- Koala::HTTPService.stub(:http_options).and_return({})
347
+ allow(Koala::HTTPService).to receive(:http_options).and_return({})
348
348
  @service = Koala.http_service
349
349
  end
350
350
 
@@ -362,11 +362,11 @@ describe Koala::HTTPService do
362
362
  it "reads http_options[:#{parameter}]" do
363
363
  value = "foo"
364
364
  Koala::HTTPService.http_options[parameter] = value
365
- Koala::HTTPService.send(deprecated_method).should == value
365
+ expect(Koala::HTTPService.send(deprecated_method)).to eq(value)
366
366
  end
367
367
 
368
368
  it "generates a deprecation warning" do
369
- Koala::Utils.should_receive(:deprecate)
369
+ expect(Koala::Utils).to receive(:deprecate)
370
370
  Koala::HTTPService.send(deprecated_method)
371
371
  end
372
372
  end
@@ -376,11 +376,11 @@ describe Koala::HTTPService do
376
376
  Koala::HTTPService.http_options[parameter] = nil
377
377
  value = "foo"
378
378
  Koala::HTTPService.send(:"#{deprecated_method}=", value)
379
- Koala::HTTPService.http_options[parameter].should == value
379
+ expect(Koala::HTTPService.http_options[parameter]).to eq(value)
380
380
  end
381
381
 
382
382
  it "generates a deprecation warning" do
383
- Koala::Utils.should_receive(:deprecate)
383
+ expect(Koala::Utils).to receive(:deprecate)
384
384
  Koala::HTTPService.send(:"#{deprecated_method}=", 2)
385
385
  end
386
386
  end
@@ -394,15 +394,15 @@ describe Koala::HTTPService do
394
394
  it "reads http_options[:ssl][:#{deprecated_method}] if http_options[:ssl]" do
395
395
  value = "foo"
396
396
  Koala::HTTPService.http_options[:ssl] = {deprecated_method => value}
397
- Koala::HTTPService.send(deprecated_method).should == value
397
+ expect(Koala::HTTPService.send(deprecated_method)).to eq(value)
398
398
  end
399
399
 
400
400
  it "returns nil if http_options[:ssl] is not defined" do
401
- Koala::HTTPService.send(deprecated_method).should be_nil
401
+ expect(Koala::HTTPService.send(deprecated_method)).to be_nil
402
402
  end
403
403
 
404
404
  it "generates a deprecation warning" do
405
- Koala::Utils.should_receive(:deprecate)
405
+ expect(Koala::Utils).to receive(:deprecate)
406
406
  Koala::HTTPService.send(deprecated_method)
407
407
  end
408
408
  end
@@ -412,25 +412,25 @@ describe Koala::HTTPService do
412
412
  Koala::HTTPService.http_options[:ssl] = nil
413
413
  value = "foo"
414
414
  Koala::HTTPService.send(:"#{deprecated_method}=", value)
415
- Koala::HTTPService.http_options[:ssl].should
415
+ expect(Koala::HTTPService.http_options[:ssl]).to be_a(Hash)
416
416
  end
417
417
 
418
418
  it "writes to http_options[:ssl][:#{deprecated_method}]" do
419
419
  value = "foo"
420
420
  Koala::HTTPService.send(:"#{deprecated_method}=", value)
421
- Koala::HTTPService.http_options[:ssl].should
422
- Koala::HTTPService.http_options[:ssl][deprecated_method].should == value
421
+ expect(Koala::HTTPService.http_options[:ssl]).to be_a(Hash)
422
+ expect(Koala::HTTPService.http_options[:ssl][deprecated_method]).to eq(value)
423
423
  end
424
424
 
425
425
  it "does not redefine http_options[:ssl] if already defined" do
426
426
  hash = {:a => 2}
427
427
  Koala::HTTPService.http_options[:ssl] = hash
428
428
  Koala::HTTPService.send(:"#{deprecated_method}=", 3)
429
- Koala::HTTPService.http_options[:ssl].should include(hash)
429
+ expect(Koala::HTTPService.http_options[:ssl]).to include(hash)
430
430
  end
431
431
 
432
432
  it "generates a deprecation warning" do
433
- Koala::Utils.should_receive(:deprecate)
433
+ expect(Koala::Utils).to receive(:deprecate)
434
434
  Koala::HTTPService.send(:"#{deprecated_method}=", 2)
435
435
  end
436
436
  end
@@ -445,21 +445,21 @@ describe Koala::HTTPService do
445
445
  @mock_http_response = double("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
446
446
 
447
447
  @mock_connection = double("Faraday connection")
448
- @mock_connection.stub(:get).and_return(@mock_http_response)
449
- @mock_connection.stub(:post).and_return(@mock_http_response)
450
- Faraday.stub(:new).and_return(@mock_connection)
448
+ allow(@mock_connection).to receive(:get).and_return(@mock_http_response)
449
+ allow(@mock_connection).to receive(:post).and_return(@mock_http_response)
450
+ allow(Faraday).to receive(:new).and_return(@mock_connection)
451
451
  end
452
452
 
453
453
  describe ":typhoeus_options" do
454
454
  it "merges any typhoeus_options into options" do
455
455
  typhoeus_options = {:proxy => "http://user:password@example.org/" }
456
- Faraday.should_receive(:new).with(anything, hash_including(typhoeus_options)).and_return(@mock_connection)
456
+ expect(Faraday).to receive(:new).with(anything, hash_including(typhoeus_options)).and_return(@mock_connection)
457
457
  Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
458
458
  end
459
459
 
460
460
  it "deletes the typhoeus_options key" do
461
461
  typhoeus_options = {:proxy => "http://user:password@example.org/" }
462
- Faraday.should_receive(:new).with(anything, hash_not_including(:typhoeus_options => typhoeus_options)).and_return(@mock_connection)
462
+ expect(Faraday).to receive(:new).with(anything, hash_not_including(:typhoeus_options => typhoeus_options)).and_return(@mock_connection)
463
463
  Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
464
464
  end
465
465
  end
@@ -467,13 +467,13 @@ describe Koala::HTTPService do
467
467
  describe ":ca_path" do
468
468
  it "sets any ca_path into options[:ssl]" do
469
469
  ca_path = :foo
470
- Faraday.should_receive(:new).with(anything, hash_including(:ssl => hash_including(:ca_path => ca_path))).and_return(@mock_connection)
470
+ expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => hash_including(:ca_path => ca_path))).and_return(@mock_connection)
471
471
  Koala::HTTPService.make_request("anything", {}, "get", :ca_path => ca_path)
472
472
  end
473
473
 
474
474
  it "deletes the ca_path key" do
475
475
  ca_path = :foo
476
- Faraday.should_receive(:new).with(anything, hash_not_including(:ca_path => ca_path)).and_return(@mock_connection)
476
+ expect(Faraday).to receive(:new).with(anything, hash_not_including(:ca_path => ca_path)).and_return(@mock_connection)
477
477
  Koala::HTTPService.make_request("anything", {}, "get", :ca_path => ca_path)
478
478
  end
479
479
  end
@@ -481,13 +481,13 @@ describe Koala::HTTPService do
481
481
  describe ":ca_file" do
482
482
  it "sets any ca_file into options[:ssl]" do
483
483
  ca_file = :foo
484
- Faraday.should_receive(:new).with(anything, hash_including(:ssl => hash_including(:ca_file => ca_file))).and_return(@mock_connection)
484
+ expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => hash_including(:ca_file => ca_file))).and_return(@mock_connection)
485
485
  Koala::HTTPService.make_request("anything", {}, "get", :ca_file => ca_file)
486
486
  end
487
487
 
488
488
  it "deletes the ca_file key" do
489
489
  ca_file = :foo
490
- Faraday.should_receive(:new).with(anything, hash_not_including(:ca_file => ca_file)).and_return(@mock_connection)
490
+ expect(Faraday).to receive(:new).with(anything, hash_not_including(:ca_file => ca_file)).and_return(@mock_connection)
491
491
  Koala::HTTPService.make_request("anything", {}, "get", :ca_file => ca_file)
492
492
  end
493
493
  end
@@ -495,13 +495,13 @@ describe Koala::HTTPService do
495
495
  describe ":verify_mode" do
496
496
  it "sets any verify_mode into options[:ssl]" do
497
497
  verify_mode = :foo
498
- Faraday.should_receive(:new).with(anything, hash_including(:ssl => hash_including(:verify_mode => verify_mode))).and_return(@mock_connection)
498
+ expect(Faraday).to receive(:new).with(anything, hash_including(:ssl => hash_including(:verify_mode => verify_mode))).and_return(@mock_connection)
499
499
  Koala::HTTPService.make_request("anything", {}, "get", :verify_mode => verify_mode)
500
500
  end
501
501
 
502
502
  it "deletes the verify_mode key" do
503
503
  verify_mode = :foo
504
- Faraday.should_receive(:new).with(anything, hash_not_including(:verify_mode => verify_mode)).and_return(@mock_connection)
504
+ expect(Faraday).to receive(:new).with(anything, hash_not_including(:verify_mode => verify_mode)).and_return(@mock_connection)
505
505
  Koala::HTTPService.make_request("anything", {}, "get", :verify_mode => verify_mode)
506
506
  end
507
507
  end