httparty 0.13.3 → 0.13.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of httparty might be problematic. Click here for more details.

Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +92 -0
  4. data/.rubocop_todo.yml +124 -0
  5. data/.simplecov +1 -0
  6. data/Gemfile +8 -3
  7. data/Guardfile +1 -1
  8. data/README.md +1 -0
  9. data/Rakefile +4 -5
  10. data/bin/httparty +9 -10
  11. data/examples/README.md +3 -0
  12. data/examples/aaws.rb +2 -2
  13. data/examples/crack.rb +1 -1
  14. data/examples/custom_parsers.rb +1 -4
  15. data/examples/delicious.rb +3 -3
  16. data/examples/google.rb +2 -2
  17. data/examples/logging.rb +5 -7
  18. data/examples/nokogiri_html_parser.rb +0 -3
  19. data/examples/rescue_json.rb +17 -0
  20. data/examples/rubyurl.rb +3 -3
  21. data/examples/twitter.rb +2 -2
  22. data/examples/whoismyrep.rb +1 -1
  23. data/features/command_line.feature +85 -2
  24. data/features/steps/env.rb +16 -11
  25. data/features/steps/httparty_response_steps.rb +13 -13
  26. data/features/steps/mongrel_helper.rb +2 -2
  27. data/features/steps/remote_service_steps.rb +18 -6
  28. data/httparty.gemspec +4 -4
  29. data/lib/httparty.rb +37 -56
  30. data/lib/httparty/connection_adapter.rb +3 -4
  31. data/lib/httparty/cookie_hash.rb +2 -3
  32. data/lib/httparty/hash_conversions.rb +3 -5
  33. data/lib/httparty/logger/apache_logger.rb +1 -1
  34. data/lib/httparty/logger/logger.rb +1 -1
  35. data/lib/httparty/module_inheritable_attributes.rb +1 -1
  36. data/lib/httparty/net_digest_auth.rb +46 -16
  37. data/lib/httparty/request.rb +16 -16
  38. data/lib/httparty/response.rb +9 -4
  39. data/lib/httparty/version.rb +1 -1
  40. data/spec/httparty/connection_adapter_spec.rb +184 -100
  41. data/spec/httparty/cookie_hash_spec.rb +21 -21
  42. data/spec/httparty/exception_spec.rb +22 -7
  43. data/spec/httparty/hash_conversions_spec.rb +41 -0
  44. data/spec/httparty/logger/apache_logger_spec.rb +3 -3
  45. data/spec/httparty/logger/curl_logger_spec.rb +2 -2
  46. data/spec/httparty/logger/logger_spec.rb +7 -7
  47. data/spec/httparty/net_digest_auth_spec.rb +60 -32
  48. data/spec/httparty/parser_spec.rb +37 -35
  49. data/spec/httparty/request_spec.rb +249 -193
  50. data/spec/httparty/response_spec.rb +37 -29
  51. data/spec/httparty/ssl_spec.rb +21 -21
  52. data/spec/httparty_spec.rb +153 -164
  53. data/spec/spec_helper.rb +34 -12
  54. data/spec/support/ssl_test_helper.rb +2 -2
  55. data/spec/support/ssl_test_server.rb +21 -21
  56. data/spec/support/stub_response.rb +10 -10
  57. metadata +9 -4
  58. data/lib/httparty/core_extensions.rb +0 -32
@@ -1,17 +1,16 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ require "simplecov"
2
+ SimpleCov.start
2
3
 
3
4
  require "httparty"
4
-
5
- require 'spec/autorun'
6
- require 'fakeweb'
5
+ require "fakeweb"
7
6
 
8
7
  def file_fixture(filename)
9
- open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
8
+ open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename}")).read
10
9
  end
11
10
 
12
- Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
11
+ Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each {|f| require f}
13
12
 
14
- Spec::Runner.configure do |config|
13
+ RSpec.configure do |config|
15
14
  config.include HTTParty::StubResponse
16
15
  config.include HTTParty::SSLTestHelper
17
16
 
@@ -22,15 +21,38 @@ Spec::Runner.configure do |config|
22
21
  config.after(:suite) do
23
22
  FakeWeb.allow_net_connect = true
24
23
  end
25
- end
26
24
 
27
- Spec::Matchers.define :use_ssl do
28
- match do |connection|
29
- connection.use_ssl?
25
+ config.expect_with :rspec do |expectations|
26
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
27
+ end
28
+
29
+ config.mock_with :rspec do |mocks|
30
+ mocks.verify_partial_doubles = false
30
31
  end
32
+
33
+ config.filter_run :focus
34
+ config.run_all_when_everything_filtered = true
35
+
36
+ config.disable_monkey_patching!
37
+
38
+ config.warnings = true
39
+
40
+ if config.files_to_run.one?
41
+ config.default_formatter = 'doc'
42
+ end
43
+
44
+ config.profile_examples = 10
45
+
46
+ config.order = :random
47
+
48
+ Kernel.srand config.seed
49
+ end
50
+
51
+ RSpec::Matchers.define :use_ssl do
52
+ match(&:use_ssl?)
31
53
  end
32
54
 
33
- Spec::Matchers.define :use_cert_store do |cert_store|
55
+ RSpec::Matchers.define :use_cert_store do |cert_store|
34
56
  match do |connection|
35
57
  connection.cert_store == cert_store
36
58
  end
@@ -5,7 +5,7 @@ module HTTParty
5
5
  def ssl_verify_test(mode, ca_basename, server_cert_filename, options = {})
6
6
  options = {
7
7
  format: :json,
8
- timeout: 30,
8
+ timeout: 30
9
9
  }.merge(options)
10
10
 
11
11
  if mode
@@ -34,7 +34,7 @@ module HTTParty
34
34
 
35
35
  test_server = SSLTestServer.new({
36
36
  rsa_key: path.join('server.key').read,
37
- cert: path.join(server_cert_filename).read,
37
+ cert: path.join(server_cert_filename).read
38
38
  })
39
39
 
40
40
  test_server.start
@@ -9,7 +9,7 @@ class SSLTestServer
9
9
  attr_accessor :ctx # SSLContext object
10
10
  attr_reader :port
11
11
 
12
- def initialize(options={})
12
+ def initialize(options = {})
13
13
  @ctx = OpenSSL::SSL::SSLContext.new
14
14
  @ctx.cert = OpenSSL::X509::Certificate.new(options[:cert])
15
15
  @ctx.key = OpenSSL::PKey::RSA.new(options[:rsa_key])
@@ -24,21 +24,21 @@ class SSLTestServer
24
24
  @raw_server = TCPServer.new(@port)
25
25
 
26
26
  if @port == 0
27
- @port = Socket::getnameinfo(@raw_server.getsockname, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)[1].to_i
27
+ @port = Socket.getnameinfo(@raw_server.getsockname, Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)[1].to_i
28
28
  end
29
29
 
30
30
  @ssl_server = OpenSSL::SSL::SSLServer.new(@raw_server, @ctx)
31
31
 
32
- @stopping_mutex.synchronize{
32
+ @stopping_mutex.synchronize {
33
33
  return if @stopping
34
- @thread = Thread.new{ thread_main }
34
+ @thread = Thread.new { thread_main }
35
35
  }
36
36
 
37
37
  nil
38
38
  end
39
39
 
40
40
  def stop
41
- @stopping_mutex.synchronize{
41
+ @stopping_mutex.synchronize {
42
42
  return if @stopping
43
43
  @stopping = true
44
44
  }
@@ -47,22 +47,22 @@ class SSLTestServer
47
47
 
48
48
  private
49
49
 
50
- def thread_main
51
- until @stopping_mutex.synchronize{ @stopping }
52
- (rr,_,_) = select([@ssl_server.to_io], nil, nil, 0.1)
50
+ def thread_main
51
+ until @stopping_mutex.synchronize { @stopping }
52
+ (rr, _, _) = select([@ssl_server.to_io], nil, nil, 0.1)
53
53
 
54
- next unless rr && rr.include?(@ssl_server.to_io)
54
+ next unless rr && rr.include?(@ssl_server.to_io)
55
55
 
56
- socket = @ssl_server.accept
56
+ socket = @ssl_server.accept
57
57
 
58
- Thread.new{
59
- header = []
58
+ Thread.new {
59
+ header = []
60
60
 
61
- until (line = socket.readline).rstrip.empty?
62
- header << line
63
- end
61
+ until (line = socket.readline).rstrip.empty?
62
+ header << line
63
+ end
64
64
 
65
- response =<<EOF
65
+ response = <<EOF
66
66
  HTTP/1.1 200 OK
67
67
  Connection: close
68
68
  Content-Type: application/json; charset=UTF-8
@@ -70,11 +70,11 @@ Content-Type: application/json; charset=UTF-8
70
70
  {"success":true}
71
71
  EOF
72
72
 
73
- socket.write(response.gsub(/\r\n/n, "\n").gsub(/\n/n, "\r\n"))
74
- socket.close
73
+ socket.write(response.gsub(/\r\n/n, "\n").gsub(/\n/n, "\r\n"))
74
+ socket.close
75
75
  }
76
- end
77
-
78
- @ssl_server.close
79
76
  end
77
+
78
+ @ssl_server.close
79
+ end
80
80
  end
@@ -5,38 +5,38 @@ module HTTParty
5
5
  data = file_fixture(filename)
6
6
 
7
7
  response = Net::HTTPOK.new("1.1", 200, "Content for you")
8
- response.stub!(:body).and_return(data)
8
+ allow(response).to receive(:body).and_return(data)
9
9
 
10
10
  http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', format: format)
11
- http_request.stub_chain(:http, :request).and_return(response)
11
+ allow(http_request).to receive_message_chain(:http, :request).and_return(response)
12
12
 
13
- HTTParty::Request.should_receive(:new).and_return(http_request)
13
+ expect(HTTParty::Request).to receive(:new).and_return(http_request)
14
14
  end
15
15
 
16
- def stub_chunked_http_response_with(chunks, options={format: "html"})
16
+ def stub_chunked_http_response_with(chunks, options = {format: "html"})
17
17
  response = Net::HTTPResponse.new("1.1", 200, nil)
18
- response.stub(:chunked_data).and_return(chunks)
18
+ allow(response).to receive(:chunked_data).and_return(chunks)
19
19
  def response.read_body(&block)
20
20
  @body || chunked_data.each(&block)
21
21
  end
22
22
 
23
23
  http_request = HTTParty::Request.new(Net::HTTP::Get, 'http://localhost', options)
24
- http_request.stub_chain(:http, :request).and_yield(response).and_return(response)
24
+ allow(http_request).to receive_message_chain(:http, :request).and_yield(response).and_return(response)
25
25
 
26
- HTTParty::Request.should_receive(:new).and_return(http_request)
26
+ expect(HTTParty::Request).to receive(:new).and_return(http_request)
27
27
  end
28
28
 
29
29
  def stub_response(body, code = 200)
30
30
  @request.options[:base_uri] ||= 'http://localhost'
31
31
  unless defined?(@http) && @http
32
32
  @http = Net::HTTP.new('localhost', 80)
33
- @request.stub!(:http).and_return(@http)
33
+ allow(@request).to receive(:http).and_return(@http)
34
34
  end
35
35
 
36
36
  response = Net::HTTPResponse::CODE_TO_OBJ[code.to_s].new("1.1", code, body)
37
- response.stub!(:body).and_return(body)
37
+ allow(response).to receive(:body).and_return(body)
38
38
 
39
- @http.stub!(:request).and_return(response)
39
+ allow(@http).to receive(:request).and_return(response)
40
40
  response
41
41
  end
42
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-06 00:00:00.000000000 Z
12
+ date: 2015-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -48,6 +48,9 @@ extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
50
  - ".gitignore"
51
+ - ".rubocop.yml"
52
+ - ".rubocop_todo.yml"
53
+ - ".simplecov"
51
54
  - ".travis.yml"
52
55
  - Gemfile
53
56
  - Guardfile
@@ -67,6 +70,7 @@ files:
67
70
  - examples/headers_and_user_agents.rb
68
71
  - examples/logging.rb
69
72
  - examples/nokogiri_html_parser.rb
73
+ - examples/rescue_json.rb
70
74
  - examples/rubyurl.rb
71
75
  - examples/stackexchange.rb
72
76
  - examples/tripit_sign_in.rb
@@ -90,7 +94,6 @@ files:
90
94
  - lib/httparty.rb
91
95
  - lib/httparty/connection_adapter.rb
92
96
  - lib/httparty/cookie_hash.rb
93
- - lib/httparty/core_extensions.rb
94
97
  - lib/httparty/exceptions.rb
95
98
  - lib/httparty/hash_conversions.rb
96
99
  - lib/httparty/logger/apache_logger.rb
@@ -123,6 +126,7 @@ files:
123
126
  - spec/httparty/connection_adapter_spec.rb
124
127
  - spec/httparty/cookie_hash_spec.rb
125
128
  - spec/httparty/exception_spec.rb
129
+ - spec/httparty/hash_conversions_spec.rb
126
130
  - spec/httparty/logger/apache_logger_spec.rb
127
131
  - spec/httparty/logger/curl_logger_spec.rb
128
132
  - spec/httparty/logger/logger_spec.rb
@@ -158,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
162
  version: '0'
159
163
  requirements: []
160
164
  rubyforge_project:
161
- rubygems_version: 2.2.2
165
+ rubygems_version: 2.2.3
162
166
  signing_key:
163
167
  specification_version: 4
164
168
  summary: Makes http fun! Also, makes consuming restful web services dead easy.
@@ -196,6 +200,7 @@ test_files:
196
200
  - spec/httparty/connection_adapter_spec.rb
197
201
  - spec/httparty/cookie_hash_spec.rb
198
202
  - spec/httparty/exception_spec.rb
203
+ - spec/httparty/hash_conversions_spec.rb
199
204
  - spec/httparty/logger/apache_logger_spec.rb
200
205
  - spec/httparty/logger/curl_logger_spec.rb
201
206
  - spec/httparty/logger/logger_spec.rb
@@ -1,32 +0,0 @@
1
- module HTTParty
2
- if defined?(::BasicObject)
3
- BasicObject = ::BasicObject #:nodoc:
4
- else
5
- class BasicObject #:nodoc:
6
- instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval/ }
7
- end
8
- end
9
-
10
- unless defined?(Net::HTTP::Patch)
11
- class Net::HTTP
12
- def patch(path, data, initheader = nil, dest = nil, &block) #:nodoc:
13
- res = nil
14
- request(Patch.new(path, initheader), data) {|r|
15
- r.read_body dest, &block
16
- res = r
17
- }
18
- unless @newimpl
19
- res.value
20
- return res, res.body
21
- end
22
- res
23
- end
24
-
25
- class Patch < Net::HTTPRequest
26
- METHOD = 'PATCH'
27
- REQUEST_HAS_BODY = true
28
- RESPONSE_HAS_BODY = true
29
- end
30
- end
31
- end
32
- end