check_http 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A simple interface to gather curl stats on a given HTTP interface.
4
4
 
5
+ [![Build Status](https://secure.travis-ci.org/gorsuch/check_http.png)](http://travis-ci.org/gorsuch/check_http)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -18,4 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
  gem.add_dependency('ethon')
20
20
  gem.add_dependency('kv', '0.0.4')
21
+ gem.add_development_dependency('rake')
22
+ gem.add_development_dependency('rspec')
21
23
  end
@@ -1,15 +1,29 @@
1
1
  module CheckHTTP
2
2
  class Checker
3
- def blacklist
3
+ attr_accessor :blacklist
4
+
5
+ def initialize
6
+ self.blacklist = default_blacklist
7
+ end
8
+
9
+ def default_blacklist
4
10
  [:response_header, :response_body, :httpauth_avail, :starttransfer_time, :appconnect_time, :pretransfer_time]
5
11
  end
6
12
 
7
13
  def check(url)
14
+ clean(sample(url)).merge(:url => url)
15
+ end
16
+
17
+ def clean(result)
18
+ result.reject { |k,v| blacklist.include?(k) }
19
+ end
20
+
21
+ def sample(url)
8
22
  ethon = Ethon::Easy.new
9
23
  ethon.url = url
10
24
  ethon.prepare
11
25
  ethon.perform
12
- ethon.to_hash.reject { |k,v| blacklist.include?(k) }.merge(:url => url)
26
+ ethon.to_hash
13
27
  end
14
28
  end
15
29
  end
@@ -1,3 +1,3 @@
1
1
  module CheckHTTP
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe CheckHTTP::Checker do
4
+ let(:checker) { CheckHTTP::Checker.new }
5
+ let(:url) { 'http://example.com' }
6
+ let(:mock_result) { {:return_code=>:ok,
7
+ :total_time=>0.037439,
8
+ :connect_time=>0.009433,
9
+ :namelookup_time=>0.003042,
10
+ :effective_url=>"http://google.com",
11
+ :primary_ip=>"74.125.224.98",
12
+ :response_code=>301,
13
+ :redirect_count=>0} }
14
+
15
+ it 'should be able to sample a url' do
16
+ checker.should_receive(:sample).with(url) { {} }
17
+ checker.sample(url)
18
+ end
19
+
20
+ it 'should return sampled results with url merged in' do
21
+ checker.stub(:sample).with(url) { mock_result }
22
+ checker.check(url).should eq(mock_result.merge(:url => url))
23
+ end
24
+
25
+ it 'should clean sampled results before returning' do
26
+ checker.stub(:sample).with(url) { mock_result }
27
+ checker.should_receive(:clean).with(mock_result) { mock_result }
28
+ checker.check(url)
29
+ end
30
+
31
+ it 'should be able to remove blacklisted items' do
32
+ checker.blacklist = [:foo]
33
+ checker.clean({:foo => 1, :baz => 2}).should eq({:baz => 2})
34
+ end
35
+
36
+ it 'should set the default blacklist upon initialization' do
37
+ checker.blacklist.should eq(checker.default_blacklist)
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ require 'check_http'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-26 00:00:00.000000000 Z
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ethon
@@ -43,6 +43,38 @@ dependencies:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.0.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
46
78
  description: a simple interface to gather curl stats against an HTTP resource
47
79
  email:
48
80
  - michael.gorsuch@gmail.com
@@ -52,6 +84,7 @@ extensions: []
52
84
  extra_rdoc_files: []
53
85
  files:
54
86
  - .gitignore
87
+ - .rspec
55
88
  - Gemfile
56
89
  - LICENSE.txt
57
90
  - README.md
@@ -62,6 +95,8 @@ files:
62
95
  - lib/check_http/checker.rb
63
96
  - lib/check_http/cli.rb
64
97
  - lib/check_http/version.rb
98
+ - spec/check_http/checker_spec.rb
99
+ - spec/spec_helper.rb
65
100
  homepage: https://github.com/gorsuch/check_http
66
101
  licenses: []
67
102
  post_install_message:
@@ -86,4 +121,6 @@ rubygems_version: 1.8.23
86
121
  signing_key:
87
122
  specification_version: 3
88
123
  summary: a simple interface to gather curl stats against an HTTP resource
89
- test_files: []
124
+ test_files:
125
+ - spec/check_http/checker_spec.rb
126
+ - spec/spec_helper.rb