Skip to content

Commit

Permalink
fix pinger result comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
mordaroso committed Nov 29, 2010
1 parent 9f5a5a1 commit e2c0f7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/guard/passenger/pinger.rb
Expand Up @@ -4,7 +4,7 @@ module Guard
class Passenger
module Pinger
class << self

# try to ping given url (e.g. http://localhost:3000/) and display a message to inform of the result
# failure == response status is 5xx
# otherwise, it's a success
Expand All @@ -15,7 +15,7 @@ def ping(host, port, path = '/')
response = Net::HTTP.start(host, port) do |http|
http.head(path)
end
if response =~ Net::HTTPServerError
if response.is_a? Net::HTTPServerError
Notifier.notify("Passenger is not running!", :title => "Passenger", :image => :failed)
else
Notifier.notify("Passenger is running.", :title => "Passenger", :image => :success)
Expand All @@ -25,7 +25,7 @@ def ping(host, port, path = '/')
end
}
end

end
end
end
Expand Down
32 changes: 16 additions & 16 deletions spec/guard/passenger/pinger_spec.rb
@@ -1,72 +1,72 @@
require 'spec_helper'

describe Guard::Passenger::Pinger do

describe '.ping' do
before(:each) do
Net::HTTP.should_receive(:start).with('localhost', 3000).and_yield(@http_object = mock('request'))
end
after(:each) do
wait_for_thread_end
end

describe "default" do
before(:each) do
@http_object.should_receive(:head).with('/').and_return(@http_response = mock('response'))
end

it "should ping '/'" do
@http_response.should_receive(:=~).with(Net::HTTPServerError).and_return(false)
@http_response.should_receive(:is_a?).with(Net::HTTPServerError).and_return(false)
subject.ping('localhost', 3000)
end

context "successful ping" do
it 'should notify the problem' do
@http_response.should_receive(:=~).with(Net::HTTPServerError).and_return(false)
@http_response.should_receive(:is_a?).with(Net::HTTPServerError).and_return(false)
Guard::Notifier.should_receive(:notify).with('Passenger is running.', :title => "Passenger", :image => :success)
subject.ping('localhost', 3000)
end
end

context "failing ping" do
it 'should notify that it is ok' do
@http_response.should_receive(:=~).with(Net::HTTPServerError).and_return(true)
@http_response.should_receive(:is_a?).with(Net::HTTPServerError).and_return(true)
Guard::Notifier.should_receive(:notify).with('Passenger is not running!', :title => "Passenger", :image => :failed)
subject.ping('localhost', 3000)
end
end
end

describe "custom path" do
context "not beginning with '/'" do
before(:each) do
@http_object.should_receive(:head).with('/foo').and_return(@http_response = mock('response'))
@http_response.should_receive(:=~).with(Net::HTTPServerError)
@http_response.should_receive(:is_a?).with(Net::HTTPServerError)
end

context "successful ping" do
it 'should display an info message' do
subject.ping('localhost', 3000, 'foo')
end
end
end

context "not beginning with '/'" do
before(:each) do
@http_object.should_receive(:head).with('/foo').and_return(@http_response = mock('response'))
@http_response.should_receive(:=~).with(Net::HTTPServerError)
@http_response.should_receive(:is_a?).with(Net::HTTPServerError)
end

context "successful ping" do
it 'should display an info message' do
subject.ping('localhost', 3000, '/foo')
end
end
end
end

end

end

def wait_for_thread_end
Expand Down

0 comments on commit e2c0f7f

Please sign in to comment.