httping 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # HTTPing.rb
2
+
3
+ HTTPing.rb is a utility to measure web service response time. This is a Ruby port of HTTPing (http://www.vanheusden.com/httping/).
4
+
5
+ ## Bugs, Features, Feedback
6
+
7
+ Tickets can be submitted by via GitHub issues.
8
+
9
+ ## Example Usage
10
+
11
+ jpignata@populuxe:~$ httping --count 10 --user-agent "HTTPinger" http://www.google.com
12
+ 5 kb from http://www.google.com/: code=200 msg=OK time=51 msecs
13
+ 5 kb from http://www.google.com/: code=200 msg=OK time=61 msecs
14
+ 5 kb from http://www.google.com/: code=200 msg=OK time=74 msecs
15
+ 5 kb from http://www.google.com/: code=200 msg=OK time=48 msecs
16
+ 5 kb from http://www.google.com/: code=200 msg=OK time=106 msecs
17
+ 5 kb from http://www.google.com/: code=200 msg=OK time=51 msecs
18
+ 5 kb from http://www.google.com/: code=200 msg=OK time=52 msecs
19
+ 5 kb from http://www.google.com/: code=200 msg=OK time=50 msecs
20
+ 5 kb from http://www.google.com/: code=200 msg=OK time=59 msecs
21
+ 5 kb from http://www.google.com/: code=200 msg=OK time=60 msecs
22
+
23
+ --- http://www.google.com/ httping.rb statistics ---
24
+ 10 GETs transmitted
25
+ round-trip min/avg/max = 48 msecs/61 msecs/106 msecs
26
+
27
+
28
+ ## Command-line Options
29
+
30
+ Usage: httping [options] uri
31
+ -c, --count NUM Number of times to ping host
32
+ -d, --delay SECS Delay in seconds between pings (default: 1)
33
+ -f, --flood Flood ping (no delay)
34
+ -j, --json Return JSON results
35
+ -q, --quick Ping once and return OK if up
36
+ -a, --audible Beep on each ping
37
+ -u, --user-agent STR User agent string to send in headers
38
+ -r, --referrer STR Referrer string to send in headers
39
+ -h, --help Display this screen
40
+
41
+ ## Installation
42
+
43
+ jp@populuxe:~$ gem install httping
44
+
45
+ ## Requirements
46
+
47
+ - FakeWeb (in order to run the specs)
48
+
49
+ ## LICENSE:
50
+
51
+ (The MIT License)
52
+
53
+ Copyright (c) 2009 Jay Pignata
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining
56
+ a copy of this software and associated documentation files (the
57
+ 'Software'), to deal in the Software without restriction, including
58
+ without limitation the rights to use, copy, modify, merge, publish,
59
+ distribute, sublicense, and/or sell copies of the Software, and to
60
+ permit persons to whom the Software is furnished to do so, subject to
61
+ the following conditions:
62
+
63
+ The above copyright notice and this permission notice shall be
64
+ included in all copies or substantial portions of the Software.
65
+
66
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
67
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
68
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
69
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
70
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
71
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
72
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -8,14 +8,20 @@ Spec::Rake::SpecTask.new(:spec) do |spec|
8
8
  spec.spec_opts = ['--options', 'spec/spec.opts']
9
9
  end
10
10
 
11
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
12
+ spec.libs << 'lib' << 'spec'
13
+ spec.pattern = 'spec/**/*_spec.rb'
14
+ spec.rcov = true
15
+ spec.rcov_opts = ['--exclude', 'Library,spec']
16
+ end
17
+
11
18
  begin
12
19
  require 'jeweler'
13
20
  Jeweler::Tasks.new do |gem|
14
21
  gem.name = "httping"
15
- gem.date = %q{2009-09-15}
16
22
  gem.default_executable = %q{httping}
17
- gem.summary = "Measures web site response time"
18
- gem.description = "Measures web site response time"
23
+ gem.summary = "Command-line utility for measuring web site response time"
24
+ gem.homepage = "http://github.com/jpignata/httping"
19
25
  gem.email = "john.pignata@gmail.com"
20
26
  gem.authors = ["John Pignata"]
21
27
  gem.add_development_dependency "rspec", "1.2.9"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/lib/httping/ping.rb CHANGED
@@ -9,11 +9,14 @@ class Ping
9
9
 
10
10
  def run
11
11
  trap("INT") { results }
12
+
12
13
  loop do
13
14
  ping
14
- results if count_reached?
15
+ break if count_reached?
15
16
  sleep @delay unless @flood
16
17
  end
18
+
19
+ results
17
20
  end
18
21
 
19
22
  def ping
@@ -59,12 +62,7 @@ class Ping
59
62
  end
60
63
 
61
64
  def results
62
- if @format.nil?
63
- interactive_results
64
- else
65
- send("#{@format}_results")
66
- end
67
-
65
+ send("#{@format}_results")
68
66
  exit
69
67
  end
70
68
 
data/spec/ping_spec.rb CHANGED
@@ -12,10 +12,36 @@ describe "Ping" do
12
12
  Output.clear
13
13
  end
14
14
 
15
- context ".ping" do
16
- it "pings the configured url and outputs statistics" do
17
- @httping.ping
18
- Output.to_s.should match(/10 bytes from http:\/\/www.example.com\/: code=200 msg=OK time=[0-9] msecs/)
15
+ describe ".ping" do
16
+ context "a HTTP URI" do
17
+ it "pings the configured url and outputs statistics" do
18
+ @httping.ping
19
+ Output.to_s.should match(/10 bytes from http:\/\/www.example.com\/: code=200 msg=OK time=[0-9] msecs/)
20
+ end
21
+ end
22
+
23
+ context "a HTTPS URI" do
24
+ it "pings the configured url and outputs statistics" do
25
+ @httping.uri = URI.parse("https://www.example.com/")
26
+ @httping.ping
27
+ Output.to_s.should match(/10 bytes from https:\/\/www.example.com\/: code=200 msg=OK time=[0-9] msecs/)
28
+ end
29
+ end
30
+
31
+ context "a URI with a query string" do
32
+ it "pings the configured url and outputs statistics" do
33
+ @httping.uri = URI.parse("http://www.example.com/search?q=test")
34
+ @httping.ping
35
+ Output.to_s.should match(/10 bytes from http:\/\/www.example.com\/search\?q=test: code=200 msg=OK time=[0-9] msecs/)
36
+ end
37
+ end
38
+
39
+ context "audible ping" do
40
+ it "outputs a console beep if audible is sold" do
41
+ @httping.audible = true
42
+ @httping.ping
43
+ Output.to_s.should match(/\007/)
44
+ end
19
45
  end
20
46
  end
21
47
 
@@ -40,5 +66,52 @@ describe "Ping" do
40
66
  @httping.results
41
67
  Output.to_s.should match(/-- http:\/\/www.example.com\/ httping.rb statistics ---\n5 GETs transmitted\n/)
42
68
  end
43
- end
69
+ end
70
+
71
+ context ".json_results" do
72
+ before do
73
+ @httping.format = :json
74
+ 2.times { @httping.ping }
75
+ end
76
+
77
+ it "outputs a summary of the pings in JSON format" do
78
+ @httping.results
79
+ Output.to_s.should match(/\{\"results\": \{\"max\": [0-9\.]*, \"avg\": [0-9\.]*, \"min\": [0-9\.]*\}, \"sent\": 2, \"uri\": \"http:\/\/www.example.com\/\"\}/)
80
+ end
81
+ end
82
+
83
+ context ".quick_results" do
84
+ before do
85
+ @httping.format = :quick
86
+ @httping.ping
87
+ end
88
+
89
+ it "outputs OK if host responds to HTTP GET" do
90
+ @httping.results
91
+ Output.to_s.should match(/OK/)
92
+ end
93
+ end
94
+
95
+ context ".run" do
96
+ before do
97
+ @httping = Ping.new
98
+ @httping.uri = URI.parse("http://www.example.com/")
99
+ @httping.format = :interactive
100
+ @httping.count = 5
101
+ end
102
+
103
+ it "pings until a count is reached" do
104
+ @httping.flood = true
105
+ @httping.run
106
+ Output.to_s.should match(/5 GETs transmitted/)
107
+ end
108
+
109
+ it "adds a delay between each ping if a delay is provided" do
110
+ @httping.flood = false
111
+ @httping.delay = 0.25
112
+ start_time = Time.now
113
+ @httping.run
114
+ (Time.now - start_time).should > 0.5
115
+ end
116
+ end
44
117
  end
data/spec/runner_spec.rb CHANGED
@@ -13,13 +13,44 @@ describe "Runner" do
13
13
  context ".parse_arguments" do
14
14
  it "parses command-line arguments into an options hash" do
15
15
  ARGV << "http://www.example.com"
16
- ARGV << "--count"
17
- ARGV << "3"
16
+ ARGV << "--count" << "3"
17
+ ARGV << "--delay" << "2"
18
+ ARGV << "--audible"
19
+ ARGV << "--user-agent" << "Mozilla"
20
+ ARGV << "--referrer" << "http://www.example.com/about-us"
21
+ ARGV << "--flood"
18
22
 
19
23
  options = @runner.parse_arguments
20
24
  options[:count].should == 3
25
+ options[:delay].should == 2
26
+ options[:audible].should be
27
+ options[:flood].should be
28
+ options[:user_agent].to_s.should == "Mozilla"
29
+ options[:referrer].to_s.should == "http://www.example.com/about-us"
21
30
  options[:uri].to_s.should == "http://www.example.com/"
22
31
  end
32
+
33
+ it "defaults count to 5 if JSON format is flag passed" do
34
+ ARGV << "http://www.example.com"
35
+ ARGV << "--json"
36
+
37
+ options = @runner.parse_arguments
38
+ options[:count].should == 5
39
+ end
40
+
41
+ it "sets count to 1 if quick format is flag passed" do
42
+ ARGV << "http://www.example.com"
43
+ ARGV << "--quick"
44
+
45
+ options = @runner.parse_arguments
46
+ options[:count].should == 1
47
+ end
48
+
49
+ it "outputs a help screen if help flag passed" do
50
+ ARGV << "--help"
51
+ @runner.parse_arguments
52
+ Output.to_s.should match(/-j, --json *Return JSON results/)
53
+ end
23
54
  end
24
55
 
25
56
  context ".run" do
@@ -33,25 +64,30 @@ describe "Runner" do
33
64
  @runner.run
34
65
  Output.to_s.should == "invalid option: -z\nUsage: httping [options] uri"
35
66
  end
67
+
68
+ it "creates a ping object based upon passed in parameters" do
69
+ ARGV << "http://www.example.com"
70
+ ARGV << "--count" << "5"
71
+ ARGV << "--flood"
72
+ @runner.run
73
+ Output.to_s.should match(/5 GETs transmitted/)
74
+ end
36
75
  end
37
76
 
38
77
  context "parse_uri" do
39
78
  it "outputs an error and exists if not given an HTTP(S) URI" do
40
- ARGV.clear
41
79
  ARGV << "ftp://www.example.com"
42
80
  @runner.parse_uri
43
81
  Output.to_s.should == "ERROR: Invalid URI ftp://www.example.com"
44
82
  end
45
83
 
46
84
  it "accepts HTTP URIs" do
47
- ARGV.clear
48
85
  ARGV << "http://www.example.com"
49
86
  @runner.parse_uri
50
87
  Output.to_s.should_not match(/ERROR/)
51
88
  end
52
89
 
53
90
  it "accepts HTTPS URIs" do
54
- ARGV.clear
55
91
  ARGV << "https://www.example.com"
56
92
  @runner.parse_uri
57
93
  Output.to_s.should_not match(/ERROR/)
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,8 @@ require File.join(File.dirname(__FILE__), '../lib/httping')
5
5
  require 'fakeweb'
6
6
  FakeWeb.allow_net_connect = false
7
7
  FakeWeb.register_uri(:any, "http://www.example.com", :body => "hey there.")
8
+ FakeWeb.register_uri(:any, "https://www.example.com", :body => "hey there.")
9
+ FakeWeb.register_uri(:any, "http://www.example.com/search?q=test", :body => "hey there.")
8
10
 
9
11
  class Object
10
12
  def exit(status_code = nil)
@@ -14,6 +16,8 @@ class Object
14
16
  def puts(output_string = "\n")
15
17
  Output.puts(output_string)
16
18
  end
19
+
20
+ alias print puts
17
21
  end
18
22
 
19
23
  class Output
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httping
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Pignata
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-15 00:00:00 -04:00
12
+ date: 2009-10-31 00:00:00 -04:00
13
13
  default_executable: httping
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,15 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.2.6
34
34
  version:
35
- description: Measures web site response time
35
+ description:
36
36
  email: john.pignata@gmail.com
37
37
  executables:
38
38
  - httping
39
39
  extensions: []
40
40
 
41
- extra_rdoc_files: []
42
-
41
+ extra_rdoc_files:
42
+ - README.md
43
43
  files:
44
+ - README.md
44
45
  - Rakefile
45
46
  - VERSION
46
47
  - bin/httping
@@ -56,7 +57,7 @@ files:
56
57
  - spec/spec.opts
57
58
  - spec/spec_helper.rb
58
59
  has_rdoc: true
59
- homepage:
60
+ homepage: http://github.com/jpignata/httping
60
61
  licenses: []
61
62
 
62
63
  post_install_message:
@@ -82,7 +83,7 @@ rubyforge_project:
82
83
  rubygems_version: 1.3.5
83
84
  signing_key:
84
85
  specification_version: 3
85
- summary: Measures web site response time
86
+ summary: Command-line utility for measuring web site response time
86
87
  test_files:
87
88
  - spec/extensions_spec.rb
88
89
  - spec/ping_spec.rb