ethon 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmNjNTQxNTQxNzI0YTBkMjgyNjYwOWU0YTZjYWIzMDcyYTYyYTdlNw==
5
+ data.tar.gz: !binary |-
6
+ YTFlM2RhMTE2ZWUxYzY1YzhhMzY2OTEwMGY5ZWMyNGMwNmM4OTViMA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YWEzMGY4NTlhZWM5MGRmOTkyNGE2ZjNkOTVjMjBhMjVjODJjM2Q1MjAzMGZj
10
+ ZWMyOWIyZjUxNzE3YTBiZDA3N2Q0OWNlNWQwZjFiNmI5M2Y2NDZjOTY5NDQ4
11
+ ZjM2M2FjMDkwNzczMDQwYjhkMTkxM2U5MmM4MzNjODU2YmFiZDI=
12
+ data.tar.gz: !binary |-
13
+ OWMxNDk4NWIyZjAxZGNmNjRmMWViMTEzNGI5MGFhNzIwODFiYjYwMGU4NzE0
14
+ NDYxNjg1NjBlYjk0YzdmNWQ3NGU5ODU5YzcwODdkNDA1MjA1YzBkYTAwZTFh
15
+ MGE0ZDY5ODM2ZGUzNmIzMDI4YzVlZWFiYjIyZTc0ZWVjYWU5ODY=
@@ -2,14 +2,17 @@
2
2
 
3
3
  ## Master
4
4
 
5
- Not backwards compatible changes:
6
-
7
- * `mime-types` are no longer a dependency. The gem will be still used if available to determine the mime type of a file which is uploaded. That means you have to have take care of the gem installation yourself.
8
-
9
5
  [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.7.0...master)
10
6
 
7
+ * MS Windows determination delegated to `Gem.windows?` for better accuracy.
8
+ * FFI data-types updated to work on MS Windows.
9
+
11
10
  ## 0.7.0
12
11
 
12
+ Not backwards compatible changes:
13
+
14
+ * `mime-types` are no longer a dependency. The gem will be still used if available to determine the mime type of a file which is uploaded. That means you have to have take care of the gem installation yourself.
15
+
13
16
  [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.6.3...v0.7.0)
14
17
 
15
18
  ## 0.6.3
@@ -20,7 +20,7 @@ module Ethon
20
20
 
21
21
  # :nodoc:
22
22
  def self.windows?
23
- !(RbConfig::CONFIG['host_os'] !~ /mingw|mswin|bccwin/)
23
+ Libc.windows?
24
24
  end
25
25
 
26
26
  require 'ethon/curls/constants'
@@ -13,8 +13,8 @@ module Ethon
13
13
  # :nodoc:
14
14
  class FDSet < ::FFI::Struct
15
15
  if Curl.windows?
16
- layout :fd_count, :u_int,
17
- :fd_array, [:u_int, 64] # 2048 FDs
16
+ layout :fd_count, :uint,
17
+ :fd_array, [:uint, 64] # 2048 FDs
18
18
 
19
19
  def clear; self[:fd_count] = 0; end
20
20
  else
@@ -29,8 +29,13 @@ module Ethon
29
29
 
30
30
  # :nodoc:
31
31
  class Timeval < ::FFI::Struct
32
- layout :sec, :time_t,
33
- :usec, :suseconds_t
32
+ if Curl.windows?
33
+ layout :sec, :long,
34
+ :usec, :long
35
+ else
36
+ layout :sec, :time_t,
37
+ :usec, :suseconds_t
38
+ end
34
39
  end
35
40
  end
36
41
  end
@@ -42,6 +42,12 @@ module Ethon
42
42
  when :string
43
43
  func=:string
44
44
  value=value.to_s unless value.nil?
45
+ when :string_as_pointer
46
+ func = :ffipointer
47
+ s = ''
48
+ s = value.to_s unless value.nil?
49
+ value = FFI::MemoryPointer.new(:char, s.bytesize)
50
+ value.put_bytes(0, s)
45
51
  when :string_escape_null
46
52
  func=:string
47
53
  value=Util.escape_zero_byte(value) unless value.nil?
@@ -107,6 +113,7 @@ module Ethon
107
113
  # :all defaults to all bits set
108
114
  :string => :objectpoint,
109
115
  :string_escape_null => :objectpoint,
116
+ :string_as_pointer => :objectpoint,
110
117
  :ffipointer => :objectpoint, # FFI::Pointer
111
118
  :curl_slist => :objectpoint,
112
119
  :buffer => :objectpoint, # A memory buffer of size defined in the options
@@ -302,7 +309,7 @@ module Ethon
302
309
  option :easy, :postfields, :string, 15
303
310
  option :easy, :postfieldsize, :int, 60
304
311
  option :easy, :postfieldsize_large, :off_t, 120
305
- option :easy, :copypostfields, :string, 165
312
+ option :easy, :copypostfields, :string_as_pointer, 165
306
313
  option :easy, :httppost, :ffipointer, 24
307
314
  option :easy, :referer, :string, 16
308
315
  option :easy, :useragent, :string, 18
@@ -40,10 +40,9 @@ module Ethon
40
40
  @headers_called = true
41
41
  headers
42
42
  end
43
- if :unyielded == body(chunk = stream.read_string(size * num))
44
- @response_body << chunk
45
- end
46
- size * num
43
+ result = body(chunk = stream.read_string(size * num))
44
+ @response_body << chunk if result == :unyielded
45
+ result != :abort ? size*num : -1
47
46
  }
48
47
  end
49
48
 
@@ -60,6 +60,8 @@ module Ethon
60
60
  # be read with http_connect_code and not this.
61
61
  :response_code => :long,
62
62
 
63
+ :request_size => :long,
64
+
63
65
  # Return the total number of redirections that were
64
66
  # actually followed.
65
67
  :redirect_count => :long
@@ -10,7 +10,7 @@ module Ethon
10
10
  end
11
11
 
12
12
  def self.informations_to_log
13
- [:url, :response_code, :return_code, :total_time]
13
+ [:effective_url, :response_code, :return_code, :total_time]
14
14
  end
15
15
 
16
16
  def self.from_easy(easy)
@@ -86,7 +86,12 @@ module Ethon
86
86
  # @return [ Object ] If there are no on_body callbacks, returns the symbol :unyielded.
87
87
  def body(chunk)
88
88
  if defined?(@on_body) and not @on_body.nil?
89
- @on_body.each{ |callback| callback.call(chunk, self) }
89
+ result = nil
90
+ @on_body.each do |callback|
91
+ result = callback.call(chunk, self)
92
+ break if result == :abort
93
+ end
94
+ result
90
95
  else
91
96
  :unyielded
92
97
  end
@@ -9,7 +9,7 @@ module Ethon
9
9
 
10
10
  # :nodoc:
11
11
  def self.windows?
12
- !(RbConfig::CONFIG['host_os'] !~ /mingw|mswin|bccwin/)
12
+ Gem.win_platform?
13
13
  end
14
14
 
15
15
  unless windows?
@@ -1,5 +1,5 @@
1
1
  module Ethon
2
2
 
3
3
  # Ethon version.
4
- VERSION = '0.7.0'
4
+ VERSION = '0.7.1'
5
5
  end
@@ -6,20 +6,20 @@ describe Ethon::Curl do
6
6
 
7
7
  context "when global_init fails" do
8
8
  it "raises global init error" do
9
- Ethon::Curl.should_receive(:global_init).and_return(1)
9
+ expect(Ethon::Curl).to receive(:global_init).and_return(1)
10
10
  expect{ Ethon::Curl.init }.to raise_error(Ethon::Errors::GlobalInit)
11
11
  end
12
12
  end
13
13
 
14
14
  context "when global_init works" do
15
- before { Ethon::Curl.should_receive(:global_init).and_return(0) }
15
+ before { expect(Ethon::Curl).to receive(:global_init).and_return(0) }
16
16
 
17
17
  it "doesn't raises global init error" do
18
- expect{ Ethon::Curl.init }.to_not raise_error(Ethon::Errors::GlobalInit)
18
+ expect{ Ethon::Curl.init }.to_not raise_error
19
19
  end
20
20
 
21
21
  it "logs" do
22
- Ethon.logger.should_receive(:debug)
22
+ expect(Ethon.logger).to receive(:debug)
23
23
  Ethon::Curl.init
24
24
  end
25
25
  end
@@ -5,7 +5,7 @@ describe Ethon::Easy::Callbacks do
5
5
 
6
6
  describe "#set_callbacks" do
7
7
  before do
8
- Ethon::Curl.should_receive(:set_option).exactly(3).times
8
+ expect(Ethon::Curl).to receive(:set_option).exactly(3).times
9
9
  end
10
10
 
11
11
  it "sets write- and headerfunction" do
@@ -26,6 +26,27 @@ describe Ethon::Easy::Callbacks do
26
26
  easy.set_callbacks
27
27
  expect(easy.instance_variable_get(:@debug_info).to_a).to eq([])
28
28
  end
29
+ end
30
+
31
+ describe "#body_write_callback" do
32
+ let(:body_write_callback) { easy.instance_variable_get(:@body_write_callback) }
33
+ let(:stream) { double(read_string: "") }
34
+ context "when body returns not :abort" do
35
+ it "returns number bigger than 0" do
36
+ expect(body_write_callback.call(stream, 1, 1, nil) > 0).to be(true)
37
+ end
38
+ end
29
39
 
40
+ context "when body returns :abort" do
41
+ before do
42
+ easy.on_body.clear
43
+ easy.on_body { :abort }
44
+ end
45
+ let(:body_write_callback) { easy.instance_variable_get(:@body_write_callback) }
46
+
47
+ it "returns -1 to indicate abort to libcurl" do
48
+ expect(body_write_callback.call(stream, 1, 1, nil)).to eq(-1)
49
+ end
50
+ end
30
51
  end
31
52
  end
@@ -30,7 +30,7 @@ describe Ethon::Easy::Form do
30
30
  let(:pairs) { [['a', '1'], ['b', '2']] }
31
31
 
32
32
  it "returns false" do
33
- expect(form.multipart?).to be_false
33
+ expect(form.multipart?).to be_falsey
34
34
  end
35
35
  end
36
36
 
@@ -38,7 +38,7 @@ describe Ethon::Easy::Form do
38
38
  let(:pairs) { [['a', '1'], ['b', ['path', 'encoding', 'abs_path']]] }
39
39
 
40
40
  it "returns true" do
41
- expect(form.multipart?).to be_true
41
+ expect(form.multipart?).to be_truthy
42
42
  end
43
43
  end
44
44
  end
@@ -50,7 +50,7 @@ describe Ethon::Easy::Form do
50
50
  let(:pairs) { [['a', '1']] }
51
51
 
52
52
  it "adds params to form" do
53
- Ethon::Curl.should_receive(:formadd)
53
+ expect(Ethon::Curl).to receive(:formadd)
54
54
  form.materialize
55
55
  end
56
56
  end
@@ -59,7 +59,7 @@ describe Ethon::Easy::Form do
59
59
  let(:pairs) { [['a', nil]] }
60
60
 
61
61
  it "adds params to form" do
62
- Ethon::Curl.should_receive(:formadd)
62
+ expect(Ethon::Curl).to receive(:formadd)
63
63
  form.materialize
64
64
  end
65
65
  end
@@ -68,7 +68,7 @@ describe Ethon::Easy::Form do
68
68
  let(:pairs) { [['a', ["file", "type", "path/file"]]] }
69
69
 
70
70
  it "adds file to form" do
71
- Ethon::Curl.should_receive(:formadd)
71
+ expect(Ethon::Curl).to receive(:formadd)
72
72
  form.materialize
73
73
  end
74
74
  end
@@ -7,8 +7,8 @@ describe Ethon::Easy::Header do
7
7
  let(:headers) { { 'User-Agent' => 'Ethon' } }
8
8
 
9
9
  it "sets header" do
10
- Ethon::Easy.any_instance.should_receive(:set_callbacks)
11
- Ethon::Curl.should_receive(:set_option)
10
+ expect_any_instance_of(Ethon::Easy).to receive(:set_callbacks)
11
+ expect(Ethon::Curl).to receive(:set_option)
12
12
  easy.headers = headers
13
13
  end
14
14
 
@@ -55,7 +55,7 @@ describe Ethon::Easy::Http::Custom do
55
55
  let(:form) { {:a => File.open(__FILE__, 'r')} }
56
56
 
57
57
  it "sets httppost" do
58
- easy.should_receive(:httppost=)
58
+ expect(easy).to receive(:httppost=)
59
59
  custom.setup(easy)
60
60
  end
61
61
 
@@ -93,12 +93,12 @@ describe Ethon::Easy::Http::Custom do
93
93
  let(:encoded) { "a=1%26b%3D2" }
94
94
 
95
95
  it "sets escaped copypostfields" do
96
- easy.should_receive(:copypostfields=).with(encoded)
96
+ expect(easy).to receive(:copypostfields=).with(encoded)
97
97
  custom.setup(easy)
98
98
  end
99
99
 
100
100
  it "sets postfieldsize" do
101
- easy.should_receive(:postfieldsize=).with{ |value| expect(value).to be(encoded.bytesize) }
101
+ expect(easy).to receive(:postfieldsize=).with(encoded.bytesize)
102
102
  custom.setup(easy)
103
103
  end
104
104
 
@@ -17,14 +17,14 @@ describe Ethon::Easy::Http::Get do
17
17
  let(:form) { { :a => 1 } }
18
18
 
19
19
  it "sets customrequest" do
20
- easy.should_receive(:customrequest=).with("GET")
20
+ expect(easy).to receive(:customrequest=).with("GET")
21
21
  get.setup(easy)
22
22
  end
23
23
  end
24
24
 
25
25
  context "when no body" do
26
26
  it "doesn't set customrequest" do
27
- easy.should_receive(:customrequest=).never
27
+ expect(easy).to receive(:customrequest=).never
28
28
  get.setup(easy)
29
29
  end
30
30
  end
@@ -10,7 +10,7 @@ describe Ethon::Easy::Http::Head do
10
10
  describe "#setup" do
11
11
  context "when nothing" do
12
12
  it "sets nobody" do
13
- easy.should_receive(:nobody=).with(true)
13
+ expect(easy).to receive(:nobody=).with(true)
14
14
  head.setup(easy)
15
15
  end
16
16
 
@@ -24,7 +24,7 @@ describe Ethon::Easy::Http::Head do
24
24
  let(:params) { {:a => "1&b=2"} }
25
25
 
26
26
  it "sets nobody" do
27
- easy.should_receive(:nobody=).with(true)
27
+ expect(easy).to receive(:nobody=).with(true)
28
28
  head.setup(easy)
29
29
  end
30
30
 
@@ -9,7 +9,7 @@ describe Ethon::Easy::Http::Options do
9
9
 
10
10
  describe "#setup" do
11
11
  it "sets customrequest" do
12
- easy.should_receive(:customrequest=).with("OPTIONS")
12
+ expect(easy).to receive(:customrequest=).with("OPTIONS")
13
13
  options.setup(easy)
14
14
  end
15
15
 
@@ -9,7 +9,7 @@ describe Ethon::Easy::Http::Patch do
9
9
 
10
10
  describe "#setup" do
11
11
  it "sets customrequest" do
12
- easy.should_receive(:customrequest=).with("PATCH")
12
+ expect(easy).to receive(:customrequest=).with("PATCH")
13
13
  patch.setup(easy)
14
14
  end
15
15
 
@@ -15,12 +15,12 @@ describe Ethon::Easy::Http::Post do
15
15
  end
16
16
 
17
17
  it "sets postfield_size" do
18
- easy.should_receive(:postfieldsize=).with(0)
18
+ expect(easy).to receive(:postfieldsize=).with(0)
19
19
  post.setup(easy)
20
20
  end
21
21
 
22
22
  it "sets copy_postfields" do
23
- easy.should_receive(:copypostfields=).with("")
23
+ expect(easy).to receive(:copypostfields=).with("")
24
24
  post.setup(easy)
25
25
  end
26
26
 
@@ -40,12 +40,12 @@ describe Ethon::Easy::Http::Post do
40
40
  end
41
41
 
42
42
  it "sets postfieldsize" do
43
- easy.should_receive(:postfieldsize=).with(0)
43
+ expect(easy).to receive(:postfieldsize=).with(0)
44
44
  post.setup(easy)
45
45
  end
46
46
 
47
47
  it "sets copypostfields" do
48
- easy.should_receive(:copypostfields=).with("")
48
+ expect(easy).to receive(:copypostfields=).with("")
49
49
  post.setup(easy)
50
50
  end
51
51
 
@@ -99,7 +99,7 @@ describe Ethon::Easy::Http::Post do
99
99
  let(:form) { {:a => File.open(__FILE__, 'r')} }
100
100
 
101
101
  it "sets httppost" do
102
- easy.should_receive(:httppost=)
102
+ expect(easy).to receive(:httppost=)
103
103
  post.setup(easy)
104
104
  end
105
105
 
@@ -137,12 +137,12 @@ describe Ethon::Easy::Http::Post do
137
137
  let(:encoded) { "a=1%26b%3D2" }
138
138
 
139
139
  it "sets escaped copypostfields" do
140
- easy.should_receive(:copypostfields=).with(encoded)
140
+ expect(easy).to receive(:copypostfields=).with(encoded)
141
141
  post.setup(easy)
142
142
  end
143
143
 
144
144
  it "sets postfieldsize" do
145
- easy.should_receive(:postfieldsize=).with{ |value| expect(value).to be(encoded.bytesize) }
145
+ expect(easy).to receive(:postfieldsize=).with(encoded.bytesize)
146
146
  post.setup(easy)
147
147
  end
148
148
 
@@ -194,6 +194,26 @@ describe Ethon::Easy::Http::Post do
194
194
  end
195
195
  end
196
196
  end
197
+
198
+ context "when binary with null bytes" do
199
+ let(:form) { [1, 0, 1].pack('c*') }
200
+
201
+ context "when requesting" do
202
+ before do
203
+ easy.headers = { 'Expect' => '' }
204
+ post.setup(easy)
205
+ easy.perform
206
+ end
207
+
208
+ it "returns ok" do
209
+ expect(easy.return_code).to eq(:ok)
210
+ end
211
+
212
+ it "sends binary data" do
213
+ expect(easy.response_body).to include('"body":"\\u0001\\u0000\\u0001"')
214
+ end
215
+ end
216
+ end
197
217
  end
198
218
 
199
219
  context "when params and body" do
@@ -15,12 +15,12 @@ describe Ethon::Easy::Http::Put do
15
15
  end
16
16
 
17
17
  it "sets upload" do
18
- easy.should_receive(:upload=).with(true)
18
+ expect(easy).to receive(:upload=).with(true)
19
19
  put.setup(easy)
20
20
  end
21
21
 
22
22
  it "sets infilesize" do
23
- easy.should_receive(:infilesize=).with(0)
23
+ expect(easy).to receive(:infilesize=).with(0)
24
24
  put.setup(easy)
25
25
  end
26
26
 
@@ -42,12 +42,12 @@ describe Ethon::Easy::Http::Put do
42
42
  end
43
43
 
44
44
  it "sets upload" do
45
- easy.should_receive(:upload=).with(true)
45
+ expect(easy).to receive(:upload=).with(true)
46
46
  put.setup(easy)
47
47
  end
48
48
 
49
49
  it "sets infilesize" do
50
- easy.should_receive(:infilesize=).with(0)
50
+ expect(easy).to receive(:infilesize=).with(0)
51
51
  put.setup(easy)
52
52
  end
53
53
 
@@ -67,17 +67,17 @@ describe Ethon::Easy::Http::Put do
67
67
  let(:form) { {:a => "1&b=2"} }
68
68
 
69
69
  it "sets infilesize" do
70
- easy.should_receive(:infilesize=).with(11)
70
+ expect(easy).to receive(:infilesize=).with(11)
71
71
  put.setup(easy)
72
72
  end
73
73
 
74
74
  it "sets readfunction" do
75
- easy.should_receive(:readfunction)
75
+ expect(easy).to receive(:readfunction)
76
76
  put.setup(easy)
77
77
  end
78
78
 
79
79
  it "sets upload" do
80
- easy.should_receive(:upload=).with(true)
80
+ expect(easy).to receive(:upload=).with(true)
81
81
  put.setup(easy)
82
82
  end
83
83
 
@@ -12,8 +12,8 @@ describe Ethon::Easy::Http do
12
12
  let(:get_class) { Ethon::Easy::Http::Get }
13
13
 
14
14
  it "instanciates action" do
15
- get.should_receive(:setup)
16
- get_class.should_receive(:new).and_return(get)
15
+ expect(get).to receive(:setup)
16
+ expect(get_class).to receive(:new).and_return(get)
17
17
  easy.http_request(url, action_name, options)
18
18
  end
19
19
 
@@ -74,9 +74,15 @@ describe Ethon::Easy::Informations do
74
74
  end
75
75
  end
76
76
 
77
+ describe "#request_size" do
78
+ it "returns 53" do
79
+ expect(easy.request_size).to eq(53)
80
+ end
81
+ end
82
+
77
83
  describe "#supports_zlib?" do
78
84
  it "returns true" do
79
- expect(easy.supports_zlib?).to be_true
85
+ expect(easy.supports_zlib?).to be_truthy
80
86
  end
81
87
  end
82
88
  end
@@ -32,6 +32,12 @@ describe Ethon::Easy::Mirror do
32
32
  expect(mirror.log_informations).to be_a(Hash)
33
33
  end
34
34
 
35
+ it "only calls methods that exist" do
36
+ described_class.informations_to_log.each do |method_name|
37
+ expect(mirror.respond_to? method_name).to eql(true)
38
+ end
39
+ end
40
+
35
41
  it "includes return code" do
36
42
  expect(mirror.log_informations).to include(options)
37
43
  end
@@ -46,17 +46,17 @@ describe Ethon::Easy::Operations do
46
46
  end
47
47
 
48
48
  it "calls Curl.easy_perform" do
49
- Ethon::Curl.should_receive(:easy_perform)
49
+ expect(Ethon::Curl).to receive(:easy_perform)
50
50
  easy.perform
51
51
  end
52
52
 
53
53
  it "logs" do
54
- Ethon.logger.should_receive(:debug)
54
+ expect(Ethon.logger).to receive(:debug)
55
55
  easy.perform
56
56
  end
57
57
 
58
58
  it "doesn't log after completing because completing could reset" do
59
- easy.on_complete{ Ethon.logger.should_receive(:debug).never }
59
+ easy.on_complete{ expect(Ethon.logger).to receive(:debug).never }
60
60
  easy.perform
61
61
  end
62
62
 
@@ -20,10 +20,8 @@ describe Ethon::Easy::Options do
20
20
  end
21
21
 
22
22
  it "sets option" do
23
- Ethon::Easy.any_instance.should_receive(:set_callbacks)
24
- Ethon::Curl.should_receive(:set_option).with do |option, _, _|
25
- expect(option).to be(name)
26
- end
23
+ expect_any_instance_of(Ethon::Easy).to receive(:set_callbacks)
24
+ expect(Ethon::Curl).to receive(:set_option).with(name, anything, anything)
27
25
  value = case name
28
26
  when :http_version
29
27
  :httpv1_0
@@ -197,7 +197,7 @@ describe Ethon::Easy::Queryable do
197
197
  describe "#empty?" do
198
198
  context "when params empty" do
199
199
  it "returns true" do
200
- expect(params.empty?).to be_true
200
+ expect(params.empty?).to be_truthy
201
201
  end
202
202
  end
203
203
 
@@ -205,7 +205,7 @@ describe Ethon::Easy::Queryable do
205
205
  let(:hash) { {:a => 1} }
206
206
 
207
207
  it "returns false" do
208
- expect(params.empty?).to be_false
208
+ expect(params.empty?).to be_falsey
209
209
  end
210
210
  end
211
211
  end
@@ -18,7 +18,7 @@ describe Ethon::Easy::ResponseCallbacks do
18
18
  context "when block given" do
19
19
  it "stores" do
20
20
  easy.send(callback_type) { p 1 }
21
- expect(easy.instance_variable_get("@#{callback_type}")).to have(1).items
21
+ expect(easy.instance_variable_get("@#{callback_type}").size).to eq(1)
22
22
  end
23
23
  end
24
24
 
@@ -26,7 +26,7 @@ describe Ethon::Easy::ResponseCallbacks do
26
26
  it "stores" do
27
27
  easy.send(callback_type) { p 1 }
28
28
  easy.send(callback_type) { p 2 }
29
- expect(easy.instance_variable_get("@#{callback_type}")).to have(2).items
29
+ expect(easy.instance_variable_get("@#{callback_type}").size).to eq(2)
30
30
  end
31
31
  end
32
32
  end
@@ -38,14 +38,14 @@ describe Ethon::Easy::ResponseCallbacks do
38
38
  end
39
39
 
40
40
  it "executes blocks and passes self" do
41
- String.should_receive(:new).with(easy.url)
41
+ expect(String).to receive(:new).with(easy.url)
42
42
  easy.complete
43
43
  end
44
44
 
45
45
  context "when @on_complete nil" do
46
46
  it "doesn't raise" do
47
47
  easy.instance_variable_set(:@on_complete, nil)
48
- expect{ easy.complete }.to_not raise_error(NoMethodError)
48
+ expect{ easy.complete }.to_not raise_error
49
49
  end
50
50
  end
51
51
  end
@@ -56,14 +56,14 @@ describe Ethon::Easy::ResponseCallbacks do
56
56
  end
57
57
 
58
58
  it "executes blocks and passes self" do
59
- String.should_receive(:new).with(easy.url)
59
+ expect(String).to receive(:new).with(easy.url)
60
60
  easy.headers
61
61
  end
62
62
 
63
63
  context "when @on_headers nil" do
64
64
  it "doesn't raise" do
65
65
  easy.instance_variable_set(:@on_headers, nil)
66
- expect{ easy.headers }.to_not raise_error(NoMethodError)
66
+ expect{ easy.headers }.to_not raise_error
67
67
  end
68
68
  end
69
69
  end
@@ -88,7 +88,7 @@ describe Ethon::Easy::ResponseCallbacks do
88
88
  context "when @on_body nil" do
89
89
  it "doesn't raise" do
90
90
  easy.instance_variable_set(:@on_body, nil)
91
- expect{ easy.body("the chunk") }.to_not raise_error(NoMethodError)
91
+ expect{ easy.body("the chunk") }.to_not raise_error
92
92
  end
93
93
  end
94
94
  end
@@ -5,14 +5,14 @@ describe Ethon::Easy do
5
5
 
6
6
  describe ".new" do
7
7
  it "inits curl" do
8
- Ethon::Curl.should_receive(:init)
8
+ expect(Ethon::Curl).to receive(:init)
9
9
  easy
10
10
  end
11
11
 
12
12
  context "when options are empty" do
13
13
  it "sets only callbacks" do
14
- Ethon::Easy.any_instance.should_receive(:set_callbacks)
15
- Ethon::Easy.should_receive(:set_option).never
14
+ expect_any_instance_of(Ethon::Easy).to receive(:set_callbacks)
15
+ expect(Ethon::Easy).to receive(:set_option).never
16
16
  easy
17
17
  end
18
18
  end
@@ -23,11 +23,8 @@ describe Ethon::Easy do
23
23
  let(:easy) { Ethon::Easy.new(options) }
24
24
 
25
25
  it "sets followlocation" do
26
- Ethon::Easy.any_instance.should_receive(:set_callbacks)
27
- Ethon::Curl.should_receive(:set_option).with do |option, value, _|
28
- expect(option).to be(:followlocation)
29
- expect(value).to be(true)
30
- end
26
+ expect_any_instance_of(Ethon::Easy).to receive(:set_callbacks)
27
+ expect(Ethon::Curl).to receive(:set_option).with(:followlocation, true, anything)
31
28
  easy
32
29
  end
33
30
  end
@@ -37,8 +34,8 @@ describe Ethon::Easy do
37
34
  describe "#set_attributes" do
38
35
  context "when options are empty" do
39
36
  it "sets only callbacks" do
40
- Ethon::Easy.any_instance.should_receive(:set_callbacks)
41
- Ethon::Easy.should_receive(:set_option).never
37
+ expect_any_instance_of(Ethon::Easy).to receive(:set_callbacks)
38
+ expect(Ethon::Easy).to receive(:set_option).never
42
39
  easy
43
40
  end
44
41
  end
@@ -46,7 +43,7 @@ describe Ethon::Easy do
46
43
  context "when options aren't empty" do
47
44
  context "when valid key" do
48
45
  it "sets" do
49
- easy.should_receive(:verbose=).with(true)
46
+ expect(easy).to receive(:verbose=).with(true)
50
47
  easy.set_attributes({:verbose => true})
51
48
  end
52
49
  end
@@ -73,7 +70,7 @@ describe Ethon::Easy do
73
70
  end
74
71
 
75
72
  it "resets easy handle" do
76
- Ethon::Curl.should_receive(:easy_reset)
73
+ expect(Ethon::Curl).to receive(:easy_reset)
77
74
  easy.reset
78
75
  end
79
76
 
@@ -102,7 +99,7 @@ describe Ethon::Easy do
102
99
  end
103
100
 
104
101
  it "builds from easy" do
105
- Ethon::Easy::Mirror.should_receive(:from_easy).with(easy)
102
+ expect(Ethon::Easy::Mirror).to receive(:from_easy).with(easy)
106
103
  easy.mirror
107
104
  end
108
105
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ethon::Libc do
4
- describe "#getdtablesize" do
4
+ describe "#getdtablesize", :if => !Ethon::Curl.windows? do
5
5
  it "returns an integer" do
6
6
  expect(Ethon::Libc.getdtablesize).to be_a(Integer)
7
7
  end
8
8
 
9
- it "returns bigger zero" do
9
+ it "returns bigger zero", :if => !Ethon::Curl.windows? do
10
10
  expect(Ethon::Libc.getdtablesize).to_not be_zero
11
11
  end
12
12
  end
@@ -52,7 +52,7 @@ describe Ethon::Multi::Operations do
52
52
  let(:timeout) { 1 }
53
53
 
54
54
  before do
55
- Ethon::Curl.should_receive(:multi_timeout).and_return(:ok)
55
+ expect(Ethon::Curl).to receive(:multi_timeout).and_return(:ok)
56
56
  multi.instance_variable_set(:@timeout, double(:read_long => timeout))
57
57
  end
58
58
 
@@ -78,7 +78,7 @@ describe Ethon::Multi::Operations do
78
78
  end
79
79
 
80
80
  context "when code not ok" do
81
- before { Ethon::Curl.should_receive(:multi_timeout).and_return(:not_ok) }
81
+ before { expect(Ethon::Curl).to receive(:multi_timeout).and_return(:not_ok) }
82
82
 
83
83
  it "raises MultiTimeout error" do
84
84
  expect{ multi.send(:get_timeout) }.to raise_error(Ethon::Errors::MultiTimeout)
@@ -91,10 +91,10 @@ describe Ethon::Multi::Operations do
91
91
  let(:max_fd) { 1 }
92
92
 
93
93
  context "when code ok" do
94
- before { Ethon::Curl.should_receive(:multi_fdset).and_return(:ok) }
94
+ before { expect(Ethon::Curl).to receive(:multi_fdset).and_return(:ok) }
95
95
 
96
96
  it "doesn't raise" do
97
- expect{ multi.method(:set_fds).call(timeout) }.to_not raise_error(Ethon::Errors::MultiFdset)
97
+ expect{ multi.method(:set_fds).call(timeout) }.to_not raise_error
98
98
  end
99
99
 
100
100
  context "when max_fd -1" do
@@ -102,7 +102,7 @@ describe Ethon::Multi::Operations do
102
102
 
103
103
  before do
104
104
  multi.instance_variable_set(:@max_fd, double(:read_int => max_fd))
105
- multi.should_receive(:sleep).with(0.001)
105
+ expect(multi).to receive(:sleep).with(0.001)
106
106
  end
107
107
 
108
108
  it "waits 100ms" do
@@ -112,7 +112,7 @@ describe Ethon::Multi::Operations do
112
112
 
113
113
  context "when max_fd not -1" do
114
114
  context "when code smaller zero" do
115
- before { Ethon::Curl.should_receive(:select).and_return(-1) }
115
+ before { expect(Ethon::Curl).to receive(:select).and_return(-1) }
116
116
 
117
117
  it "raises Select error" do
118
118
  expect{ multi.method(:set_fds).call(timeout) }.to raise_error(Ethon::Errors::Select)
@@ -120,17 +120,17 @@ describe Ethon::Multi::Operations do
120
120
  end
121
121
 
122
122
  context "when code bigger or equal zero" do
123
- before { Ethon::Curl.should_receive(:select).and_return(0) }
123
+ before { expect(Ethon::Curl).to receive(:select).and_return(0) }
124
124
 
125
125
  it "doesn't raise" do
126
- expect{ multi.method(:set_fds).call(timeout) }.to_not raise_error(Ethon::Errors::Select)
126
+ expect{ multi.method(:set_fds).call(timeout) }.to_not raise_error
127
127
  end
128
128
  end
129
129
  end
130
130
  end
131
131
 
132
132
  context "when code not ok" do
133
- before { Ethon::Curl.should_receive(:multi_fdset).and_return(:not_ok) }
133
+ before { expect(Ethon::Curl).to receive(:multi_fdset).and_return(:not_ok) }
134
134
 
135
135
  it "raises MultiFdset error" do
136
136
  expect{ multi.method(:set_fds).call(timeout) }.to raise_error(Ethon::Errors::MultiFdset)
@@ -145,7 +145,7 @@ describe Ethon::Multi::Operations do
145
145
  end
146
146
 
147
147
  it "logs" do
148
- Ethon.logger.should_receive(:debug).twice
148
+ expect(Ethon.logger).to receive(:debug).twice
149
149
  multi.perform
150
150
  end
151
151
  end
@@ -182,7 +182,7 @@ describe Ethon::Multi::Operations do
182
182
  end
183
183
 
184
184
  it "sets response codes" do
185
- expect(easies.all?{ |e| e.response_code == 200 }).to be_true
185
+ expect(easies.all?{ |e| e.response_code == 200 }).to be_truthy
186
186
  end
187
187
  end
188
188
  end
@@ -195,7 +195,7 @@ describe Ethon::Multi::Operations do
195
195
  before { multi.instance_variable_set(:@running_count, 0) }
196
196
 
197
197
  it "returns true" do
198
- expect(multi.method(:ongoing?).call).to be_true
198
+ expect(multi.method(:ongoing?).call).to be_truthy
199
199
  end
200
200
  end
201
201
 
@@ -203,7 +203,7 @@ describe Ethon::Multi::Operations do
203
203
  before { multi.instance_variable_set(:@running_count, 1) }
204
204
 
205
205
  it "returns true" do
206
- expect(multi.method(:ongoing?).call).to be_true
206
+ expect(multi.method(:ongoing?).call).to be_truthy
207
207
  end
208
208
  end
209
209
  end
@@ -213,7 +213,7 @@ describe Ethon::Multi::Operations do
213
213
  before { multi.instance_variable_set(:@running_count, 0) }
214
214
 
215
215
  it "returns false" do
216
- expect(multi.method(:ongoing?).call).to be_false
216
+ expect(multi.method(:ongoing?).call).to be_falsey
217
217
  end
218
218
  end
219
219
 
@@ -221,7 +221,7 @@ describe Ethon::Multi::Operations do
221
221
  before { multi.instance_variable_set(:@running_count, 1) }
222
222
 
223
223
  it "returns true" do
224
- expect(multi.method(:ongoing?).call).to be_true
224
+ expect(multi.method(:ongoing?).call).to be_truthy
225
225
  end
226
226
  end
227
227
  end
@@ -257,29 +257,29 @@ describe Ethon::Multi::Operations do
257
257
  after { multi.method(:reset_fds).call }
258
258
 
259
259
  it "resets @fd_read" do
260
- multi.instance_variable_get(:@fd_read).should_receive(:clear)
260
+ expect(multi.instance_variable_get(:@fd_read)).to receive(:clear)
261
261
  end
262
262
 
263
263
  it "resets @fd_write" do
264
- multi.instance_variable_get(:@fd_write).should_receive(:clear)
264
+ expect(multi.instance_variable_get(:@fd_write)).to receive(:clear)
265
265
  end
266
266
 
267
267
  it "resets @fd_excep" do
268
- multi.instance_variable_get(:@fd_excep).should_receive(:clear)
268
+ expect(multi.instance_variable_get(:@fd_excep)).to receive(:clear)
269
269
  end
270
270
  end
271
271
 
272
272
  describe "#check" do
273
- it { pending("untested") }
273
+ it { skip("untested") }
274
274
  end
275
275
 
276
276
  describe "#run" do
277
- it { pending("untested") }
277
+ it { skip("untested") }
278
278
  end
279
279
 
280
280
  describe "#trigger" do
281
281
  it "calls multi perform" do
282
- Ethon::Curl.should_receive(:multi_perform)
282
+ expect(Ethon::Curl).to receive(:multi_perform)
283
283
  multi.send(:trigger, pointer)
284
284
  end
285
285
 
@@ -290,7 +290,7 @@ describe Ethon::Multi::Operations do
290
290
  end
291
291
 
292
292
  it "returns multi perform code" do
293
- Ethon::Curl.should_receive(:multi_perform).and_return(:ok)
293
+ expect(Ethon::Curl).to receive(:multi_perform).and_return(:ok)
294
294
  expect(multi.send(:trigger, pointer)).to eq(:ok)
295
295
  end
296
296
  end
@@ -13,9 +13,7 @@ describe Ethon::Multi::Options do
13
13
  end
14
14
 
15
15
  it "sets option" do
16
- Ethon::Curl.should_receive(:set_option).with do |option, _, _|
17
- expect(option).to be(name)
18
- end
16
+ expect(Ethon::Curl).to receive(:set_option).with(name, anything, anything, anything)
19
17
  multi.method("#{name}=").call(1)
20
18
  end
21
19
  end
@@ -15,7 +15,7 @@ describe Ethon::Multi::Stack do
15
15
 
16
16
  context "when easy new" do
17
17
  it "adds easy to multi" do
18
- Ethon::Curl.should_receive(:multi_add_handle).and_return(:ok)
18
+ expect(Ethon::Curl).to receive(:multi_add_handle).and_return(:ok)
19
19
  multi.add(easy)
20
20
  end
21
21
 
@@ -27,7 +27,7 @@ describe Ethon::Multi::Stack do
27
27
 
28
28
  context "when multi_add_handle fails" do
29
29
  it "raises multi add error" do
30
- Ethon::Curl.should_receive(:multi_add_handle).and_return(:bad_easy_handle)
30
+ expect(Ethon::Curl).to receive(:multi_add_handle).and_return(:bad_easy_handle)
31
31
  expect{ multi.add(easy) }.to raise_error(Ethon::Errors::MultiAdd)
32
32
  end
33
33
  end
@@ -45,7 +45,7 @@ describe Ethon::Multi::Stack do
45
45
  before { multi.add(easy) }
46
46
 
47
47
  it "deletes easy from multi" do
48
- Ethon::Curl.should_receive(:multi_remove_handle).and_return(:ok)
48
+ expect(Ethon::Curl).to receive(:multi_remove_handle).and_return(:ok)
49
49
  multi.delete(easy)
50
50
  end
51
51
 
@@ -57,7 +57,7 @@ describe Ethon::Multi::Stack do
57
57
 
58
58
  context "when easy is not in easy_handles" do
59
59
  it "does nothing" do
60
- Ethon::Curl.should_receive(:multi_add_handle).and_return(:ok)
60
+ expect(Ethon::Curl).to receive(:multi_add_handle).and_return(:ok)
61
61
  multi.add(easy)
62
62
  end
63
63
 
@@ -71,7 +71,7 @@ describe Ethon::Multi::Stack do
71
71
  before { multi.add(easy) }
72
72
 
73
73
  it "raises multi remove error" do
74
- Ethon::Curl.should_receive(:multi_remove_handle).and_return(:bad_easy_handle)
74
+ expect(Ethon::Curl).to receive(:multi_remove_handle).and_return(:bad_easy_handle)
75
75
  expect{ multi.delete(easy) }.to raise_error(Ethon::Errors::MultiRemove)
76
76
  end
77
77
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Ethon::Multi do
4
4
  describe ".new" do
5
5
  it "inits curl" do
6
- Ethon::Curl.should_receive(:init)
6
+ expect(Ethon::Curl).to receive(:init)
7
7
  Ethon::Multi.new
8
8
  end
9
9
 
@@ -12,7 +12,7 @@ describe Ethon::Multi do
12
12
  let(:options) { { :pipelining => true } }
13
13
 
14
14
  it "sets pipelining" do
15
- Ethon::Multi.any_instance.should_receive(:pipelining=).with(true)
15
+ expect_any_instance_of(Ethon::Multi).to receive(:pipelining=).with(true)
16
16
  Ethon::Multi.new(options)
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
5
- prerelease:
4
+ version: 0.7.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Hans Hasselberg
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-03-19 00:00:00.000000000 Z
11
+ date: 2014-07-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ffi
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -137,30 +134,26 @@ files:
137
134
  homepage: https://github.com/typhoeus/ethon
138
135
  licenses:
139
136
  - MIT
137
+ metadata: {}
140
138
  post_install_message:
141
139
  rdoc_options: []
142
140
  require_paths:
143
141
  - lib
144
142
  required_ruby_version: !ruby/object:Gem::Requirement
145
- none: false
146
143
  requirements:
147
144
  - - ! '>='
148
145
  - !ruby/object:Gem::Version
149
146
  version: '0'
150
- segments:
151
- - 0
152
- hash: -1989061620893792868
153
147
  required_rubygems_version: !ruby/object:Gem::Requirement
154
- none: false
155
148
  requirements:
156
149
  - - ! '>='
157
150
  - !ruby/object:Gem::Version
158
151
  version: 1.3.6
159
152
  requirements: []
160
153
  rubyforge_project:
161
- rubygems_version: 1.8.23
154
+ rubygems_version: 2.2.2
162
155
  signing_key:
163
- specification_version: 3
156
+ specification_version: 4
164
157
  summary: Libcurl wrapper.
165
158
  test_files:
166
159
  - spec/ethon/curl_spec.rb