httparty 0.10.0 → 0.14.0

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 (79) hide show
  1. checksums.yaml +7 -0
  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/.travis.yml +5 -4
  7. data/CONTRIBUTING.md +23 -0
  8. data/Gemfile +9 -5
  9. data/Guardfile +3 -3
  10. data/History +109 -8
  11. data/README.md +21 -21
  12. data/Rakefile +5 -10
  13. data/bin/httparty +21 -14
  14. data/docs/README.md +100 -0
  15. data/examples/README.md +67 -0
  16. data/examples/aaws.rb +9 -9
  17. data/examples/basic.rb +6 -10
  18. data/examples/crack.rb +3 -3
  19. data/examples/custom_parsers.rb +1 -4
  20. data/examples/delicious.rb +12 -12
  21. data/examples/google.rb +2 -2
  22. data/examples/headers_and_user_agents.rb +2 -2
  23. data/examples/logging.rb +36 -0
  24. data/examples/nokogiri_html_parser.rb +0 -3
  25. data/examples/rescue_json.rb +17 -0
  26. data/examples/rubyurl.rb +3 -3
  27. data/examples/stackexchange.rb +24 -0
  28. data/examples/tripit_sign_in.rb +20 -9
  29. data/examples/twitter.rb +11 -11
  30. data/examples/whoismyrep.rb +2 -2
  31. data/features/command_line.feature +90 -2
  32. data/features/digest_authentication.feature +10 -0
  33. data/features/handles_compressed_responses.feature +8 -0
  34. data/features/handles_multiple_formats.feature +23 -0
  35. data/features/steps/env.rb +16 -11
  36. data/features/steps/httparty_response_steps.rb +40 -10
  37. data/features/steps/httparty_steps.rb +19 -3
  38. data/features/steps/mongrel_helper.rb +35 -2
  39. data/features/steps/remote_service_steps.rb +31 -8
  40. data/features/supports_read_timeout_option.feature +13 -0
  41. data/httparty.gemspec +9 -6
  42. data/lib/httparty/connection_adapter.rb +76 -11
  43. data/lib/httparty/cookie_hash.rb +3 -4
  44. data/lib/httparty/exceptions.rb +10 -4
  45. data/lib/httparty/hash_conversions.rb +19 -17
  46. data/lib/httparty/logger/apache_formatter.rb +22 -0
  47. data/lib/httparty/logger/curl_formatter.rb +91 -0
  48. data/lib/httparty/logger/logger.rb +26 -0
  49. data/lib/httparty/module_inheritable_attributes.rb +1 -1
  50. data/lib/httparty/net_digest_auth.rb +69 -18
  51. data/lib/httparty/parser.rb +15 -11
  52. data/lib/httparty/request.rb +186 -47
  53. data/lib/httparty/response/headers.rb +2 -2
  54. data/lib/httparty/response.rb +44 -9
  55. data/lib/httparty/version.rb +1 -1
  56. data/lib/httparty.rb +187 -65
  57. data/script/release +42 -0
  58. data/spec/fixtures/twitter.csv +2 -0
  59. data/spec/httparty/connection_adapter_spec.rb +334 -62
  60. data/spec/httparty/cookie_hash_spec.rb +53 -23
  61. data/spec/httparty/exception_spec.rb +45 -0
  62. data/spec/httparty/hash_conversions_spec.rb +49 -0
  63. data/spec/httparty/logger/apache_formatter_spec.rb +41 -0
  64. data/spec/httparty/logger/curl_formatter_spec.rb +119 -0
  65. data/spec/httparty/logger/logger_spec.rb +38 -0
  66. data/spec/httparty/net_digest_auth_spec.rb +148 -23
  67. data/spec/httparty/parser_spec.rb +48 -41
  68. data/spec/httparty/request_spec.rb +845 -151
  69. data/spec/httparty/response_spec.rb +147 -70
  70. data/spec/httparty/ssl_spec.rb +33 -21
  71. data/spec/httparty_spec.rb +337 -186
  72. data/spec/spec_helper.rb +38 -9
  73. data/spec/support/ssl_test_helper.rb +10 -10
  74. data/spec/support/ssl_test_server.rb +21 -21
  75. data/spec/support/stub_response.rb +20 -14
  76. data/website/index.html +3 -3
  77. metadata +46 -37
  78. data/lib/httparty/core_extensions.rb +0 -32
  79. data/spec/spec.opts +0 -2
@@ -1,64 +1,64 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
2
 
3
- describe HTTParty::Parser do
3
+ RSpec.describe HTTParty::Parser do
4
4
  describe ".SupportedFormats" do
5
5
  it "returns a hash" do
6
- HTTParty::Parser::SupportedFormats.should be_instance_of(Hash)
6
+ expect(HTTParty::Parser::SupportedFormats).to be_instance_of(Hash)
7
7
  end
8
8
  end
9
9
 
10
10
  describe ".call" do
11
11
  it "generates an HTTParty::Parser instance with the given body and format" do
12
- HTTParty::Parser.should_receive(:new).with('body', :plain).and_return(stub(:parse => nil))
12
+ expect(HTTParty::Parser).to receive(:new).with('body', :plain).and_return(double(parse: nil))
13
13
  HTTParty::Parser.call('body', :plain)
14
14
  end
15
15
 
16
16
  it "calls #parse on the parser" do
17
- parser = mock('Parser')
18
- parser.should_receive(:parse)
19
- HTTParty::Parser.stub(:new => parser)
17
+ parser = double('Parser')
18
+ expect(parser).to receive(:parse)
19
+ allow(HTTParty::Parser).to receive_messages(new: parser)
20
20
  parser = HTTParty::Parser.call('body', :plain)
21
21
  end
22
22
  end
23
23
 
24
24
  describe ".formats" do
25
25
  it "returns the SupportedFormats constant" do
26
- HTTParty::Parser.formats.should == HTTParty::Parser::SupportedFormats
26
+ expect(HTTParty::Parser.formats).to eq(HTTParty::Parser::SupportedFormats)
27
27
  end
28
28
 
29
29
  it "returns the SupportedFormats constant for subclasses" do
30
30
  class MyParser < HTTParty::Parser
31
31
  SupportedFormats = {"application/atom+xml" => :atom}
32
32
  end
33
- MyParser.formats.should == {"application/atom+xml" => :atom}
33
+ expect(MyParser.formats).to eq({"application/atom+xml" => :atom})
34
34
  end
35
35
  end
36
36
 
37
37
  describe ".format_from_mimetype" do
38
38
  it "returns a symbol representing the format mimetype" do
39
- HTTParty::Parser.format_from_mimetype("text/plain").should == :plain
39
+ expect(HTTParty::Parser.format_from_mimetype("text/plain")).to eq(:plain)
40
40
  end
41
41
 
42
42
  it "returns nil when the mimetype is not supported" do
43
- HTTParty::Parser.format_from_mimetype("application/atom+xml").should be_nil
43
+ expect(HTTParty::Parser.format_from_mimetype("application/atom+xml")).to be_nil
44
44
  end
45
45
  end
46
46
 
47
47
  describe ".supported_formats" do
48
48
  it "returns a unique set of supported formats represented by symbols" do
49
- HTTParty::Parser.supported_formats.should == HTTParty::Parser::SupportedFormats.values.uniq
49
+ expect(HTTParty::Parser.supported_formats).to eq(HTTParty::Parser::SupportedFormats.values.uniq)
50
50
  end
51
51
  end
52
52
 
53
53
  describe ".supports_format?" do
54
54
  it "returns true for a supported format" do
55
- HTTParty::Parser.stub(:supported_formats => [:json])
56
- HTTParty::Parser.supports_format?(:json).should be_true
55
+ allow(HTTParty::Parser).to receive_messages(supported_formats: [:json])
56
+ expect(HTTParty::Parser.supports_format?(:json)).to be_truthy
57
57
  end
58
58
 
59
59
  it "returns false for an unsupported format" do
60
- HTTParty::Parser.stub(:supported_formats => [])
61
- HTTParty::Parser.supports_format?(:json).should be_false
60
+ allow(HTTParty::Parser).to receive_messages(supported_formats: [])
61
+ expect(HTTParty::Parser.supports_format?(:json)).to be_falsey
62
62
  end
63
63
  end
64
64
 
@@ -68,40 +68,46 @@ describe HTTParty::Parser do
68
68
  end
69
69
 
70
70
  it "attempts to parse supported formats" do
71
- @parser.stub(:supports_format? => true)
72
- @parser.should_receive(:parse_supported_format)
71
+ allow(@parser).to receive_messages(supports_format?: true)
72
+ expect(@parser).to receive(:parse_supported_format)
73
73
  @parser.parse
74
74
  end
75
75
 
76
76
  it "returns the unparsed body when the format is unsupported" do
77
- @parser.stub(:supports_format? => false)
78
- @parser.parse.should == @parser.body
77
+ allow(@parser).to receive_messages(supports_format?: false)
78
+ expect(@parser.parse).to eq(@parser.body)
79
79
  end
80
80
 
81
81
  it "returns nil for an empty body" do
82
- @parser.stub(:body => '')
83
- @parser.parse.should be_nil
82
+ allow(@parser).to receive_messages(body: '')
83
+ expect(@parser.parse).to be_nil
84
84
  end
85
85
 
86
86
  it "returns nil for a nil body" do
87
- @parser.stub(:body => nil)
88
- @parser.parse.should be_nil
87
+ allow(@parser).to receive_messages(body: nil)
88
+ expect(@parser.parse).to be_nil
89
89
  end
90
90
 
91
91
  it "returns nil for a 'null' body" do
92
- @parser.stub(:body => "null")
93
- @parser.parse.should be_nil
92
+ allow(@parser).to receive_messages(body: "null")
93
+ expect(@parser.parse).to be_nil
94
94
  end
95
95
 
96
96
  it "returns nil for a body with spaces only" do
97
- @parser.stub(:body => " ")
98
- @parser.parse.should be_nil
97
+ allow(@parser).to receive_messages(body: " ")
98
+ expect(@parser.parse).to be_nil
99
+ end
100
+
101
+ it "does not raise exceptions for bodies with invalid encodings" do
102
+ allow(@parser).to receive_messages(body: "\x80")
103
+ allow(@parser).to receive_messages(supports_format?: false)
104
+ expect(@parser.parse).to_not be_nil
99
105
  end
100
106
  end
101
107
 
102
108
  describe "#supports_format?" do
103
109
  it "utilizes the class method to determine if the format is supported" do
104
- HTTParty::Parser.should_receive(:supports_format?).with(:json)
110
+ expect(HTTParty::Parser).to receive(:supports_format?).with(:json)
105
111
  parser = HTTParty::Parser.new('body', :json)
106
112
  parser.send(:supports_format?)
107
113
  end
@@ -110,7 +116,7 @@ describe HTTParty::Parser do
110
116
  describe "#parse_supported_format" do
111
117
  it "calls the parser for the given format" do
112
118
  parser = HTTParty::Parser.new('body', :json)
113
- parser.should_receive(:json)
119
+ expect(parser).to receive(:json)
114
120
  parser.send(:parse_supported_format)
115
121
  end
116
122
 
@@ -124,7 +130,9 @@ describe HTTParty::Parser do
124
130
 
125
131
  it "raises a useful exception message for subclasses" do
126
132
  atom_parser = Class.new(HTTParty::Parser) do
127
- def self.name; 'AtomParser'; end
133
+ def self.name
134
+ 'AtomParser'
135
+ end
128
136
  end
129
137
  parser = atom_parser.new 'body', :atom
130
138
  expect do
@@ -140,27 +148,26 @@ describe HTTParty::Parser do
140
148
  end
141
149
 
142
150
  it "parses xml with MultiXml" do
143
- MultiXml.should_receive(:parse).with('body')
151
+ expect(MultiXml).to receive(:parse).with('body')
144
152
  subject.send(:xml)
145
153
  end
146
154
 
147
- it "parses json with MultiJson" do
148
- MultiJson.should_receive(:load).with('body')
149
- subject.send(:json)
150
- end
151
-
152
- it "uses MultiJson.decode if MultiJson does not respond to adapter" do
153
- MultiJson.should_receive(:respond_to?).with(:adapter).and_return(false)
154
- MultiJson.should_receive(:decode).with('body')
155
+ it "parses json with JSON" do
156
+ expect(JSON).to receive(:parse).with('body', :quirks_mode => true, :allow_nan => true)
155
157
  subject.send(:json)
156
158
  end
157
159
 
158
160
  it "parses html by simply returning the body" do
159
- subject.send(:html).should == 'body'
161
+ expect(subject.send(:html)).to eq('body')
160
162
  end
161
163
 
162
164
  it "parses plain text by simply returning the body" do
163
- subject.send(:plain).should == 'body'
165
+ expect(subject.send(:plain)).to eq('body')
166
+ end
167
+
168
+ it "parses csv with CSV" do
169
+ expect(CSV).to receive(:parse).with('body')
170
+ subject.send(:csv)
164
171
  end
165
172
  end
166
173
  end