Skip to content

Instantly share code, notes, and snippets.

@joemiller
Created November 28, 2011 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemiller/1401633 to your computer and use it in GitHub Desktop.
Save joemiller/1401633 to your computer and use it in GitHub Desktop.
infrastructure smoketest example (rspec)
require 'open-uri'
# simple wrapper around open-uri's open() that will
# fetch an HTTP or HTTPS resource including follow redirects.
# Returns a hash with 2 members:
#
# response[:meta] = the original open-uri response object. Use this to
# access metadata such as status code. See
# http://ruby-doc.org/stdlib-1.9.2/libdoc/open-uri/rdoc/OpenURI/Meta.html
# for a list of attributes and methods available.
# response[:body] = the response content as string
#
def get(url)
r = {}
resp = open(url)
r[:meta] = resp
r[:body] = resp.read
return r
end
def count_processes_matching_regex( regex )
cnt = 0
`ps auxw`.split("\n").each do |l|
cnt += 1 if l.match regex
end
return cnt
end
require File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'spec_helper'))
describe "role: sms_gateway smoketests" do
it "should have a 1 process running with the words 'java' and 'sms-gateway'" do
count_processes_matching_regex( /java.+sms-gateway/ ).should == 1
end
it "should be listening via http on port 5555" do
r = get( "http://localhost:5555/sms-gateway/" )
r[:body].should include 'pageok'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment