Skip to content

Commit d268387

Browse files
committed
Add foul to class level
1 parent 891a4a8 commit d268387

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/httparty.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ def self.included(base)
6262
# * :+ssl_ca_path+: see HTTParty::ClassMethods.ssl_ca_path.
6363

6464
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+
6575
# Turns on logging
6676
#
6777
# class Foo

spec/httparty_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,36 @@ def self.inherited(subclass)
993993
end
994994
end
995995

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+
9961026
it "does not wrap errors when foul option is disabled" do
9971027
stub_request(:get, uri).to_raise(Errno::ECONNREFUSED)
9981028

0 commit comments

Comments
 (0)