spec/em-whois_spec.rb in em-whois-0.3.0 vs spec/em-whois_spec.rb in em-whois-0.4.0
- old
+ new
@@ -1,19 +1,33 @@
require "spec/helper/all"
+require 'whois-parser'
+def throttle
+ sleep 5
+ yield
+end
+
+def properties_for(whois_record)
+ hash = {}
+ Whois::Parser::PROPERTIES.each do |p|
+ hash[p] = whois_record.parser.send(p)
+ end
+ hash
+end
+
describe "Asynchronous WHOIS" do
it "should not use synchronous socket methods" do
-
+
EM.synchrony do
- Whois::Server::Adapters::Base.any_instance.should_not_receive(:orig_ask_the_socket)
+ expect_any_instance_of(Whois::Server::SocketHandler).to_not receive(:orig_call)
- whois = Whois.whois("google.com")
- whois.should_not be_available # Sanity check
+ whois = throttle { Whois.whois("google.com") }
+ expect(whois.parser).to_not be_available # Sanity check
- whois = Whois.whois("#{rand(Time.now.to_i)}-alskdjflkasjd.com")
- whois.should be_available # Sanity check
+ whois = throttle { Whois.whois("#{rand(Time.now.to_i)}-alskdjflkasjd.com") }
+ expect(whois.parser).to be_available # Sanity check
EM.stop
end
end
@@ -21,29 +35,29 @@
it "should match synchronous WHOIS results" do
async_whois = nil
sync_whois = nil
EM.synchrony do
- async_whois = Whois.whois("github.com")
+ async_whois = throttle { Whois.whois("github.com") }
EM.stop
end
- sync_whois = Whois.whois("github.com")
+ sync_whois = throttle { Whois.whois("github.com") }
- async_whois.properties.should == sync_whois.properties
+ expect(properties_for(async_whois)).to eq(properties_for(sync_whois))
end
end
describe "Synchronous WHOIS" do
it "should not use asynchronous socket methods" do
- Whois::Server::Adapters::Base.any_instance.should_not_receive(:em_ask_the_socket)
+ expect_any_instance_of(Whois::Server::SocketHandler).to_not receive(:em_call)
- whois = Whois.whois("google.com")
- whois.should_not be_available # Sanity check
+ whois = throttle { Whois.whois("google.com") }
+ expect(whois.parser).to_not be_available # Sanity check
- whois = Whois.whois("#{rand(Time.now.to_i)}-alskdjflkasjd.com")
- whois.should be_available # Sanity check
+ whois = throttle { Whois.whois("#{rand(Time.now.to_i)}-alskdjflkasjd.com") }
+ expect(whois.parser).to be_available # Sanity check
end
end