Skip to content
Browse files

Fixed a bug which prevents a client to be created with nil timeout.

  • Loading branch information...
1 parent fa858ae commit 17ecc4182dce0b890a4868b7a41551cf44e498fb @weppos committed Dec 20, 2010
Showing with 29 additions and 10 deletions.
  1. +2 −0 CHANGELOG.rdoc
  2. +15 −8 lib/whois/client.rb
  3. +12 −2 spec/whois/client_spec.rb
View
2 CHANGELOG.rdoc
@@ -22,6 +22,8 @@
* FIXED: Fixed a bug with the whois.crsnic.net where the name server contains "no nameserver" instead of a valid host.
+* FIXED: Fixed a bug which prevents a client to be created with nil timeout.
+
== Release 1.6.6
View
23 lib/whois/client.rb
@@ -30,25 +30,32 @@ class Client
attr_accessor :timeout
- # Initializes a new <tt>Whois::Client</tt> with <tt>options</tt>.
+ # Initializes a new <tt>Whois::Client</tt> with <tt>settings</tt>.
#
# If <tt>block</tt> is given, yields <tt>self</tt>.
#
# @param [Hash] options Hash of options.
- # @option options [Fixnum, nil] :timeout (DEFAULT_TIMEOUT)
+ # @option settings [Fixnum, nil] :timeout (DEFAULT_TIMEOUT)
# The script timeout, expressed in seconds.
#
# @yield [self]
#
- # @example
+ # @example Creating a new client
+ # client = Whois::Client.new
+ # client.query("google.com")
#
- # client = Whois::Client.new do |c|
- # c.timeout = nil
- # end
+ # @example Creating a new client with custom settings
+ # client = Whois::Client.new(:timeout => nil)
# client.query("google.com")
#
- def initialize(options = {}, &block)
- self.timeout = options[:timeout] || DEFAULT_TIMEOUT
+ # @example Creating a new client an yielding the instance
+ # Whois::Client.new do |c|
+ # c.query("google.com")
+ # end
+ #
+ def initialize(settings = {}, &block)
+ settings = settings.dup
+ self.timeout = settings.key?(:timeout) ? settings.delete(:timeout) : DEFAULT_TIMEOUT
yield(self) if block_given?
end
View
14 spec/whois/client_spec.rb
@@ -3,16 +3,26 @@
describe Whois::Client do
context ".new" do
- it "initializes the instance" do
+ it "creates a new instance" do
client = klass.new
client.should be_instance_of(klass)
end
- it "accepts a timeout option" do
+ it "accepts a timeout option with a value in seconds" do
client = klass.new(:timeout => 100)
client.timeout.should == 100
end
+ it "accepts a timeout option with a nil value" do
+ client = klass.new(:timeout => nil)
+ client.timeout.should be_nil
+ end
+
+ it "defaults timeout option to DEFAULT_TIMEOUT" do
+ client = klass.new
+ client.timeout.should == klass::DEFAULT_TIMEOUT
+ end
+
it "accepts a block" do
klass.new do |client|
client.should be_instance_of(klass)

0 comments on commit 17ecc41

Please sign in to comment.
Something went wrong with that request. Please try again.