From ca40c4a22935b4e159e00eb095115d8df8932198 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Date: Fri, 7 Dec 2012 16:37:23 -0200 Subject: [PATCH] Host class that represents machine monitored. --- lib/nsca/client/host.rb | 17 +++++++++++++++++ spec/nsca/client/host_spec.rb | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lib/nsca/client/host.rb create mode 100644 spec/nsca/client/host_spec.rb diff --git a/lib/nsca/client/host.rb b/lib/nsca/client/host.rb new file mode 100644 index 0000000..a95382f --- /dev/null +++ b/lib/nsca/client/host.rb @@ -0,0 +1,17 @@ +require 'socket' + +module NSCA + module Client + class Host + attr_reader :hostname + + def initialize(options) + @hostname = options[:hostname] + end + + def self.current + Host.new(:hostname => Socket.gethostname) + end + end + end +end diff --git a/spec/nsca/client/host_spec.rb b/spec/nsca/client/host_spec.rb new file mode 100644 index 0000000..c3696f5 --- /dev/null +++ b/spec/nsca/client/host_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe NSCA::Client::Host do + subject { described_class.new(:hostname => 'dummy') } + its(:hostname) { should eq 'dummy' } + + context "current machine" do + before { Socket.stub(:gethostname).and_return('dummy-client-machine') } + subject { described_class.current } + its(:hostname) { should eq 'dummy-client-machine' } + end +end