vaguerent/test/unit/vagrant/util/is_port_open_test.rb
Fabio Rehm 54656151cf Convert specs to RSpec 2.14.8 syntax with Transpec
This conversion is done by Transpec 1.10.2 with the following command:
    transpec test/unit/

* 507 conversions
    from: obj.should
      to: expect(obj).to

* 394 conversions
    from: == expected
      to: eq(expected)

* 260 conversions
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)

* 85 conversions
    from: obj.stub(:message)
      to: allow(obj).to receive(:message)

* 25 conversions
    from: its(:attr) { }
      to: describe '#attr' do subject { super().attr }; it { } end

* 19 conversions
    from: obj.should_not
      to: expect(obj).not_to

* 7 conversions
    from: obj.should_not_receive(:message)
      to: expect(obj).not_to receive(:message)

* 3 conversions
    from: Klass.any_instance.should_receive(:message)
      to: expect_any_instance_of(Klass).to receive(:message)
2014-03-14 12:02:07 -03:00

54 lines
1.2 KiB
Ruby

require File.expand_path("../../../base", __FILE__)
require "socket"
require "vagrant/util/is_port_open"
describe Vagrant::Util::IsPortOpen do
let(:klass) do
Class.new do
extend Vagrant::Util::IsPortOpen
end
end
let(:open_port) { 52811 }
let(:closed_port) { 52811 }
it "should report open ports" do
# Start a thread which listens on a port
thr = Thread.new do
server = TCPServer.new(open_port)
Thread.current[:running] = true
# Wait until we're told to die
Thread.current[:die] = false
while !Thread.current[:die]
Thread.pass
end
# Die!
server.close
end
# Wait until the server is running
while !thr[:running]
Thread.pass
end
# Verify that we report the port is open
expect(klass.is_port_open?("localhost", open_port)).to be
# Kill the thread
thr[:die] = true
thr.join
end
it "should report closed ports" do
# This CAN fail, since port 52811 might actually be in use, but I'm
# not sure what to do except choose some random port and hope for the
# best, really.
expect(klass.is_port_open?("localhost", closed_port)).not_to be
end
end