Sha256: 8d022db80819dd06a256ee77cb45610d64244b860fac2e7c0db35138f605d533

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'test_helper'

describe Outpost::Scouts::Ping do
  class PingStub
    def initialize(ping_successful, duration=nil)
      @ping_successful = ping_successful
      @duration        = duration
    end

    def ping(*args); @ping_successful; end
    def duration;    @duration;        end
  end

  it "should set the time of ping in milliseconds" do
    config  = config_stub(:pinger => PingStub.new(true, 0.225))
    subject = Outpost::Scouts::Ping.new "test", config
    subject.execute

    assert_equal 225, subject.response_time
  end

  it "should set the time to nil when it fails" do
    config  = config_stub(:pinger => PingStub.new(false))
    subject = Outpost::Scouts::Ping.new "test", config
    subject.execute

    refute subject.response_time
  end

  it "should report the response time" do
    config  = config_stub(:pinger => PingStub.new(true, 0.225))
    subject = Outpost::Scouts::Ping.new "test", config
    subject.run

    assert_equal 225, subject.report_data[:response_time]
  end

  private

  def config_stub(options={})
    options = {:host => 'localhost'}.merge options

    build_stub(:options => options)
  end

  def pinger_stub(should_respond, time=nil)
    build_stub(:ping => should_respond, :duration => time)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
outpost-0.2.5 test/outpost/scouts/ping_test.rb
outpost-0.2.4 test/outpost/scouts/ping_test.rb
outpost-0.2.3 test/outpost/scouts/ping_test.rb
outpost-0.2.2 test/outpost/scouts/ping_test.rb
outpost-0.2.1 test/outpost/scouts/ping_test.rb