File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -12,12 +12,17 @@ module Body
1212 # Represents a body suitable for HEAD requests, in other words, a body that is empty and has a known length.
1313 class Head < Readable
1414 # Create a head body for the given body, capturing its length and then closing it.
15+ #
16+ # @parameter body [Readable | Nil] the body to create a head for.
17+ # @returns [Head | Nil] the head body, or nil if the body is nil.
1518 def self . for ( body )
16- head = self . new ( body . length )
17-
18- body . close
19+ if body
20+ head = self . new ( body . length )
21+ body . close
22+ return head
23+ end
1924
20- return head
25+ return nil
2126 end
2227
2328 # Initialize the head body with the given length.
Original file line number Diff line number Diff line change 5656 body . close
5757 end
5858 end
59+
60+ with ".for with nil body" do
61+ it "returns nil when body is nil" do
62+ body = subject . for ( nil )
63+ expect ( body ) . to be_nil
64+ end
65+ end
5966end
You can’t perform that action at this time.
0 commit comments