File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,16 @@ def self.included(base)
62
62
# * :+ssl_ca_path+: see HTTParty::ClassMethods.ssl_ca_path.
63
63
64
64
module ClassMethods
65
+ # Turns on or off the foul option.
66
+ #
67
+ # class Foo
68
+ # include HTTParty
69
+ # foul true
70
+ # end
71
+ def foul ( bool )
72
+ default_options [ :foul ] = bool
73
+ end
74
+
65
75
# Turns on logging
66
76
#
67
77
# class Foo
Original file line number Diff line number Diff line change @@ -993,6 +993,36 @@ def self.inherited(subclass)
993
993
end
994
994
end
995
995
996
+ it "works via inclusion of httparty when foul option is enabled" do
997
+ error = Errno ::ECONNREFUSED . new ( "connection refused" )
998
+ stub_request ( :get , uri ) . to_raise ( error )
999
+
1000
+ klass = Class . new do
1001
+ include HTTParty
1002
+ foul true
1003
+ end
1004
+
1005
+ expect do
1006
+ klass . get ( uri )
1007
+ end . to raise_error ( HTTParty ::Foul ) do |error |
1008
+ expect ( error . cause ) . to be_a ( Errno ::ECONNREFUSED )
1009
+ end
1010
+ end
1011
+
1012
+ it "skips via inclusion of httparty when foul option is disabled" do
1013
+ error = Errno ::ECONNREFUSED . new ( "connection refused" )
1014
+ stub_request ( :get , uri ) . to_raise ( error )
1015
+
1016
+ klass = Class . new do
1017
+ include HTTParty
1018
+ foul false
1019
+ end
1020
+
1021
+ expect do
1022
+ klass . get ( uri )
1023
+ end . to raise_error ( Errno ::ECONNREFUSED )
1024
+ end
1025
+
996
1026
it "does not wrap errors when foul option is disabled" do
997
1027
stub_request ( :get , uri ) . to_raise ( Errno ::ECONNREFUSED )
998
1028
You can’t perform that action at this time.
0 commit comments