koala 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ describe "Koala::UploadableIO" do
16
16
  :tempfile => tempfile,
17
17
  :original_filename => "bar"
18
18
  )
19
- tempfile.stub(:respond_to?).with(:path).and_return(true)
19
+ allow(tempfile).to receive(:respond_to?).with(:path).and_return(true)
20
20
 
21
21
  [tempfile, uploaded_file]
22
22
  end
@@ -39,15 +39,15 @@ describe "Koala::UploadableIO" do
39
39
  end
40
40
 
41
41
  it "returns an UploadIO with the same file path" do
42
- Koala::UploadableIO.new(*@koala_io_params).io_or_path.should == @path
42
+ expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@path)
43
43
  end
44
44
 
45
45
  it "returns an UploadIO with the same content type" do
46
- Koala::UploadableIO.new(*@koala_io_params).content_type.should == @stub_type
46
+ expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(@stub_type)
47
47
  end
48
48
 
49
49
  it "returns an UploadIO with the file's name" do
50
- Koala::UploadableIO.new(*@koala_io_params).filename.should == File.basename(@path)
50
+ expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@path))
51
51
  end
52
52
  end
53
53
 
@@ -68,16 +68,16 @@ describe "Koala::UploadableIO" do
68
68
  end
69
69
 
70
70
  it "returns an UploadIO with the same io" do
71
- Koala::UploadableIO.new(*@koala_io_params).io_or_path.should == @koala_io_params[0]
71
+ expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@koala_io_params[0])
72
72
  end
73
73
 
74
74
  it "returns an UploadableIO with the same content_type" do
75
75
  content_stub = @koala_io_params[1] = double('Content Type')
76
- Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
76
+ expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
77
77
  end
78
78
 
79
79
  it "returns an UploadableIO with the right filename" do
80
- Koala::UploadableIO.new(*@koala_io_params).filename.should == File.basename(@file.path)
80
+ expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@file.path))
81
81
  end
82
82
  end
83
83
 
@@ -100,16 +100,16 @@ describe "Koala::UploadableIO" do
100
100
 
101
101
  it "returns an UploadIO with the same io" do
102
102
  #Problem comparing Tempfile in Ruby 1.8, REE and Rubinius mode 1.8
103
- Koala::UploadableIO.new(*@koala_io_params).io_or_path.path.should == @koala_io_params[0].path
103
+ expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path.path).to eq(@koala_io_params[0].path)
104
104
  end
105
105
 
106
106
  it "returns an UploadableIO with the same content_type" do
107
107
  content_stub = @koala_io_params[1] = double('Content Type')
108
- Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
108
+ expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
109
109
  end
110
110
 
111
111
  it "returns an UploadableIO with the right filename" do
112
- Koala::UploadableIO.new(*@koala_io_params).filename.should == File.basename(@file.path)
112
+ expect(Koala::UploadableIO.new(*@koala_io_params).filename).to eq(File.basename(@file.path))
113
113
  end
114
114
  end
115
115
 
@@ -130,18 +130,18 @@ describe "Koala::UploadableIO" do
130
130
  end
131
131
 
132
132
  it "returns an UploadableIO with the same io" do
133
- Koala::UploadableIO.new(*@koala_io_params).io_or_path.should == @koala_io_params[0]
133
+ expect(Koala::UploadableIO.new(*@koala_io_params).io_or_path).to eq(@koala_io_params[0])
134
134
  end
135
135
 
136
136
  it "returns an UploadableIO with the same content_type" do
137
137
  content_stub = @koala_io_params[1] = double('Content Type')
138
- Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
138
+ expect(Koala::UploadableIO.new(*@koala_io_params).content_type).to eq(content_stub)
139
139
  end
140
140
  end
141
141
 
142
142
  describe "and no content type" do
143
143
  it "raises an exception" do
144
- lambda { Koala::UploadableIO.new(*@koala_io_params) }.should raise_exception(Koala::KoalaError)
144
+ expect { Koala::UploadableIO.new(*@koala_io_params) }.to raise_exception(Koala::KoalaError)
145
145
  end
146
146
  end
147
147
  end
@@ -153,18 +153,18 @@ describe "Koala::UploadableIO" do
153
153
 
154
154
  it "gets the path from the tempfile associated with the UploadedFile" do
155
155
  expected_path = double('Tempfile')
156
- @tempfile.should_receive(:path).and_return(expected_path)
157
- Koala::UploadableIO.new(@uploaded_file).io_or_path.should == expected_path
156
+ expect(@tempfile).to receive(:path).and_return(expected_path)
157
+ expect(Koala::UploadableIO.new(@uploaded_file).io_or_path).to eq(expected_path)
158
158
  end
159
159
 
160
160
  it "gets the content type via the content_type method" do
161
161
  expected_content_type = double('Content Type')
162
- @uploaded_file.should_receive(:content_type).and_return(expected_content_type)
163
- Koala::UploadableIO.new(@uploaded_file).content_type.should == expected_content_type
162
+ expect(@uploaded_file).to receive(:content_type).and_return(expected_content_type)
163
+ expect(Koala::UploadableIO.new(@uploaded_file).content_type).to eq(expected_content_type)
164
164
  end
165
165
 
166
166
  it "gets the filename from the UploadedFile" do
167
- Koala::UploadableIO.new(@uploaded_file).filename.should == @uploaded_file.original_filename
167
+ expect(Koala::UploadableIO.new(@uploaded_file).filename).to eq(@uploaded_file.original_filename)
168
168
  end
169
169
  end
170
170
 
@@ -178,7 +178,7 @@ describe "Koala::UploadableIO" do
178
178
  @file_hash[:tempfile] = expected_file
179
179
 
180
180
  uploadable = Koala::UploadableIO.new(@file_hash)
181
- uploadable.io_or_path.should == expected_file
181
+ expect(uploadable.io_or_path).to eq(expected_file)
182
182
  end
183
183
 
184
184
  it "gets the content type from the :type key" do
@@ -186,12 +186,12 @@ describe "Koala::UploadableIO" do
186
186
  @file_hash[:type] = expected_content_type
187
187
 
188
188
  uploadable = Koala::UploadableIO.new(@file_hash)
189
- uploadable.content_type.should == expected_content_type
189
+ expect(uploadable.content_type).to eq(expected_content_type)
190
190
  end
191
191
 
192
192
  it "gets the content type from the :type key" do
193
193
  uploadable = Koala::UploadableIO.new(@file_hash)
194
- uploadable.filename.should == @file_hash[:filename]
194
+ expect(uploadable.filename).to eq(@file_hash[:filename])
195
195
  end
196
196
  end
197
197
 
@@ -199,12 +199,12 @@ describe "Koala::UploadableIO" do
199
199
  # what that means is tested below
200
200
  it "should accept a file object alone" do
201
201
  params = [BEACH_BALL_PATH]
202
- lambda { Koala::UploadableIO.new(*params) }.should_not raise_exception
202
+ expect { Koala::UploadableIO.new(*params) }.not_to raise_exception
203
203
  end
204
204
 
205
205
  it "should accept a file path alone" do
206
206
  params = [BEACH_BALL_PATH]
207
- lambda { Koala::UploadableIO.new(*params) }.should_not raise_exception
207
+ expect { Koala::UploadableIO.new(*params) }.not_to raise_exception
208
208
  end
209
209
  end
210
210
  end
@@ -212,20 +212,20 @@ describe "Koala::UploadableIO" do
212
212
  describe "getting an UploadableIO" do
213
213
  before(:each) do
214
214
  @upload_io = double("UploadIO")
215
- UploadIO.stub(:new).with(anything, anything, anything).and_return(@upload_io)
215
+ allow(UploadIO).to receive(:new).with(anything, anything, anything).and_return(@upload_io)
216
216
  end
217
217
 
218
218
  context "if no filename was provided" do
219
219
  it "should call the constructor with the content type, file name, and a dummy file name" do
220
- UploadIO.should_receive(:new).with(BEACH_BALL_PATH, "content/type", anything).and_return(@upload_io)
221
- Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type").to_upload_io.should == @upload_io
220
+ expect(UploadIO).to receive(:new).with(BEACH_BALL_PATH, "content/type", anything).and_return(@upload_io)
221
+ expect(Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type").to_upload_io).to eq(@upload_io)
222
222
  end
223
223
  end
224
224
 
225
225
  context "if a filename was provided" do
226
226
  it "should call the constructor with the content type, file name, and the filename" do
227
227
  filename = "file"
228
- UploadIO.should_receive(:new).with(BEACH_BALL_PATH, "content/type", filename).and_return(@upload_io)
228
+ expect(UploadIO).to receive(:new).with(BEACH_BALL_PATH, "content/type", filename).and_return(@upload_io)
229
229
  Koala::UploadableIO.new(BEACH_BALL_PATH, "content/type", filename).to_upload_io
230
230
  end
231
231
  end
@@ -234,33 +234,33 @@ describe "Koala::UploadableIO" do
234
234
  describe "getting a file" do
235
235
  it "returns the File if initialized with a file" do
236
236
  f = File.new(BEACH_BALL_PATH)
237
- Koala::UploadableIO.new(f).to_file.should == f
237
+ expect(Koala::UploadableIO.new(f).to_file).to eq(f)
238
238
  end
239
239
 
240
240
  it "should open up and return a file corresponding to the path if io_or_path is a path" do
241
241
  result = double("File")
242
- File.should_receive(:open).with(BEACH_BALL_PATH).and_return(result)
243
- Koala::UploadableIO.new(BEACH_BALL_PATH).to_file.should == result
242
+ expect(File).to receive(:open).with(BEACH_BALL_PATH).and_return(result)
243
+ expect(Koala::UploadableIO.new(BEACH_BALL_PATH).to_file).to eq(result)
244
244
  end
245
245
  end
246
246
 
247
247
  describe ".binary_content?" do
248
248
  it "returns true for Rails 3 file uploads" do
249
- Koala::UploadableIO.binary_content?(rails_3_mocks.last).should be_true
249
+ expect(Koala::UploadableIO.binary_content?(rails_3_mocks.last)).to be_truthy
250
250
  end
251
251
 
252
252
  it "returns true for Sinatra file uploads" do
253
- Koala::UploadableIO.binary_content?(rails_3_mocks.last).should be_true
253
+ expect(Koala::UploadableIO.binary_content?(rails_3_mocks.last)).to be_truthy
254
254
  end
255
255
 
256
256
  it "returns true for File objects" do
257
- Koala::UploadableIO.binary_content?(File.open(BEACH_BALL_PATH)).should be_true
257
+ expect(Koala::UploadableIO.binary_content?(File.open(BEACH_BALL_PATH))).to be_truthy
258
258
  end
259
259
 
260
260
  it "returns false for everything else" do
261
- Koala::UploadableIO.binary_content?(StringIO.new).should be_false
262
- Koala::UploadableIO.binary_content?(BEACH_BALL_PATH).should be_false
263
- Koala::UploadableIO.binary_content?(nil).should be_false
261
+ expect(Koala::UploadableIO.binary_content?(StringIO.new)).to be_falsey
262
+ expect(Koala::UploadableIO.binary_content?(BEACH_BALL_PATH)).to be_falsey
263
+ expect(Koala::UploadableIO.binary_content?(nil)).to be_falsey
264
264
  end
265
265
  end
266
266
  end # describe UploadableIO
@@ -4,29 +4,29 @@ describe Koala::Utils do
4
4
  describe ".deprecate" do
5
5
  before :each do
6
6
  # unstub deprecate so we can test it
7
- Koala::Utils.unstub(:deprecate)
7
+ allow(Koala::Utils).to receive(:deprecate).and_call_original
8
8
  end
9
9
 
10
10
  it "has a deprecation prefix that includes the words Koala and deprecation" do
11
- Koala::Utils::DEPRECATION_PREFIX.should =~ /koala/i
12
- Koala::Utils::DEPRECATION_PREFIX.should =~ /deprecation/i
11
+ expect(Koala::Utils::DEPRECATION_PREFIX).to match(/koala/i)
12
+ expect(Koala::Utils::DEPRECATION_PREFIX).to match(/deprecation/i)
13
13
  end
14
14
 
15
15
  it "prints a warning with Kernel.warn" do
16
16
  message = Time.now.to_s + rand.to_s
17
- Kernel.should_receive(:warn)
17
+ expect(Kernel).to receive(:warn)
18
18
  Koala::Utils.deprecate(message)
19
19
  end
20
20
 
21
21
  it "prints the deprecation prefix and the warning" do
22
22
  message = Time.now.to_s + rand.to_s
23
- Kernel.should_receive(:warn).with(Koala::Utils::DEPRECATION_PREFIX + message)
23
+ expect(Kernel).to receive(:warn).with(Koala::Utils::DEPRECATION_PREFIX + message)
24
24
  Koala::Utils.deprecate(message)
25
25
  end
26
26
 
27
27
  it "only prints each unique message once" do
28
28
  message = Time.now.to_s + rand.to_s
29
- Kernel.should_receive(:warn).once
29
+ expect(Kernel).to receive(:warn).once
30
30
  Koala::Utils.deprecate(message)
31
31
  Koala::Utils.deprecate(message)
32
32
  end
@@ -34,20 +34,20 @@ describe Koala::Utils do
34
34
 
35
35
  describe ".logger" do
36
36
  it "has an accessor for logger" do
37
- Koala::Utils.methods.map(&:to_sym).should include(:logger)
38
- Koala::Utils.methods.map(&:to_sym).should include(:logger=)
37
+ expect(Koala::Utils.methods.map(&:to_sym)).to include(:logger)
38
+ expect(Koala::Utils.methods.map(&:to_sym)).to include(:logger=)
39
39
  end
40
40
 
41
41
  it "defaults to the standard ruby logger with level set to ERROR" do |variable|
42
- Koala::Utils.logger.should be_kind_of(Logger)
43
- Koala::Utils.logger.level.should == Logger::ERROR
42
+ expect(Koala::Utils.logger).to be_kind_of(Logger)
43
+ expect(Koala::Utils.logger.level).to eq(Logger::ERROR)
44
44
  end
45
45
 
46
46
  logger_methods = [:debug, :info, :warn, :error, :fatal]
47
47
 
48
48
  logger_methods.each do |logger_method|
49
49
  it "should delegate #{logger_method} to the attached logger" do
50
- Koala::Utils.logger.should_receive(logger_method)
50
+ expect(Koala::Utils.logger).to receive(logger_method)
51
51
  Koala::Utils.send(logger_method, "Test #{logger_method} message")
52
52
  end
53
53
  end
data/spec/spec_helper.rb CHANGED
@@ -1,22 +1,3 @@
1
- if RUBY_VERSION == '1.9.2' && RUBY_PATCHLEVEL < 290 && RUBY_ENGINE != "macruby"
2
- # In Ruby 1.9.2 versions before patchlevel 290, the default Psych
3
- # parser has an issue with YAML merge keys, which
4
- # fixtures/mock_facebook_responses.yml relies heavily on.
5
- #
6
- # Anyone using an earlier version will see missing mock response
7
- # errors when running the test suite similar to this:
8
- #
9
- # RuntimeError:
10
- # Missing a mock response for graph_api: /me/videos: source=[FILE]: post: with_token
11
- # API PATH: /me/videos?source=[FILE]&format=json&access_token=*
12
- #
13
- # For now, it seems the best fix is to just downgrade to the old syck YAML parser
14
- # for these troubled versions.
15
- #
16
- # See https://github.com/tenderlove/psych/issues/8 for more details
17
- YAML::ENGINE.yamler = 'syck'
18
- end
19
-
20
1
  # load the library
21
2
  require 'koala'
22
3
 
@@ -7,14 +7,14 @@ RSpec::Matchers.define :match_url do |url|
7
7
  original_query_hash = query_to_params(original_query_string)
8
8
 
9
9
  # the base URLs need to match
10
- base.should == original_base
10
+ expect(base).to eq(original_base)
11
11
 
12
12
  # the number of parameters should match (avoid one being a subset of the other)
13
- query_hash.values.length.should == original_query_hash.values.length
13
+ expect(query_hash.values.length).to eq(original_query_hash.values.length)
14
14
 
15
15
  # and ensure all the keys and values match
16
16
  query_hash.each_pair do |key, value|
17
- original_query_hash[key].should == value
17
+ expect(original_query_hash[key]).to eq(value)
18
18
  end
19
19
  end
20
20