Sha256: 4f831cd2e4d63005660e67da6ffa4fea713763fbe3985e21871ee6b2e2316c6f

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

describe LitmusPaper::Dependency::TCP do
  run_in_reactor

  describe "#available?" do
    around(:each) do |spec|
      begin
        @server = EM.start_server('127.0.0.1', 3333)
        spec.run
      ensure
        EM.stop_server @server if @server
      end
    end

    it "is true when it's able to reach the ip and port" do
      check = LitmusPaper::Dependency::TCP.new("127.0.0.1", 3333)
      check.should be_available
    end

    it "cancels the timer when successful" do
      SpecHelper.ensure_no_outstanding_timers do
        check = LitmusPaper::Dependency::TCP.new("127.0.0.1", 3333)
        check.should be_available
      end
    end

    it "is false when the ip is not available" do
      check = LitmusPaper::Dependency::TCP.new("127.1.1.15", 3333, :timeout => 0.3)
      check.should_not be_available
    end

    it "is false when the port is not available" do
      check = LitmusPaper::Dependency::TCP.new("127.0.0.1", 3334, :timeout => 0.3)
      check.should_not be_available
    end
  end

  describe "to_s" do
    it "is the name of the class and the ip and port" do
      check = LitmusPaper::Dependency::TCP.new("127.0.0.1", 3333)
      check.to_s.should == "Dependency::TCP(tcp://127.0.0.1:3333)"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
litmus_paper-0.2.2 spec/litmus_paper/dependency/tcp_spec.rb