Skip to content

Commit

Permalink
Merge branch 'add-stub-socket-close'
Browse files Browse the repository at this point in the history
* add-stub-socket-close:
  Change stub socket for Ruby 2.4 compat
  Rename test class

References #57.
  • Loading branch information
chrisk committed Jun 26, 2017
2 parents eab4632 + eed5056 commit 9fde35b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/fake_web/stub_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ def initialize(*args)
end

def closed?
@closed ||= true
@closed ||= false
@closed
end

def close
@closed = true
end

def readuntil(*args)
Expand Down
20 changes: 19 additions & 1 deletion test/test_timeouts.rb → test/test_stub_socket_compatibility.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class TestTimeouts < Test::Unit::TestCase
class TestStubSocketCompatibility < Test::Unit::TestCase
def test_sending_timeout_accessors_after_starting_session
# this tests an HTTPS request because #ssl_timeout= raises otherwise
FakeWeb.register_uri(:get, "https://example.com", :status => [200, "OK"])
Expand Down Expand Up @@ -30,4 +30,22 @@ def test_stub_socket_only_responds_to_continue_timeout_under_193_or_later
socket = http.instance_variable_get(:@socket)
assert_equal RUBY_VERSION >= "1.9.3", socket.respond_to?(:continue_timeout=)
end

def test_stub_socket_responds_to_close_and_always_returns_true
FakeWeb.register_uri(:get, "http://example.com", :status => [200, "OK"])
http = Net::HTTP.new("example.com", 80)
http.get("/")
socket = http.instance_variable_get(:@socket)
assert_equal socket.close, true
end

def test_stub_socket_tracks_closed_state
FakeWeb.register_uri(:get, "http://example.com", :status => [200, "OK"])
http = Net::HTTP.new("example.com", 80)
http.get("/")
socket = http.instance_variable_get(:@socket)
assert !socket.closed?
socket.close
assert socket.closed?
end
end

0 comments on commit 9fde35b

Please sign in to comment.