Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate options Hash in .timeout call #577

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/http/chainable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def build_request(*args)
def timeout(options)
klass, options = case options
when Numeric then [HTTP::Timeout::Global, {:global => options}]
when Hash then [HTTP::Timeout::PerOperation, options]
when Hash then [HTTP::Timeout::PerOperation, options.dup]
when :null then [HTTP::Timeout::Null, {}]
else raise ArgumentError, "Use `.timeout(global_timeout_in_seconds)` or `.timeout(connect: x, write: y, read: z)`."

Expand Down
9 changes: 9 additions & 0 deletions spec/lib/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@
end
end

context "specifying per operation timeouts as frozen hash" do
let(:frozen_options) { {:read => 123}.freeze }
subject(:client) { HTTP.timeout(frozen_options) }

it "does not raise an error" do
expect { client }.not_to raise_error
end
end

context "specifying a global timeout" do
subject(:client) { HTTP.timeout 123 }

Expand Down