rectory 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/rectory +59 -0
- data/lib/rectory.rb +27 -0
- data/lib/rectory/csv_outputter.rb +23 -0
- data/lib/rectory/expectation.rb +54 -0
- data/lib/rectory/request.rb +29 -0
- data/lib/rectory/version.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eeb044a2397315d50b450cf868ee22f490667817
|
4
|
+
data.tar.gz: 033316b7d880efc48a0bce2e409ea0772eef38b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed757b2604cfea37bf92b8d83927725f3d4f6af55d0e4a9ffa5f3c6809b956e906a5bc20381ed6c140c1fcc1678da1eb1789d20e6dc6c39f2cd5b4bba53158bc
|
7
|
+
data.tar.gz: 9b99ea1f52bc566024dd99278047137f7bdc0c6d49ba912e9f8ab38a4a612deeb90a75a72654a0f0329795dba8864427b8ea3495fb8358481d46e411d0305738
|
data/bin/rectory
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rectory'
|
4
|
+
require 'csv'
|
5
|
+
require 'yaml'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
Celluloid.logger = nil
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
opt_parser = OptionParser.new do |opt|
|
13
|
+
opt.banner = "Rectory"
|
14
|
+
opt.separator ""
|
15
|
+
opt.separator "rectory new [OPTIONS] --- Build a template CSV for testing redirects"
|
16
|
+
opt.separator "rectory test [CSV FILE] [OPTIONS] --- Test redirects from a CSV spreadsheet"
|
17
|
+
opt.separator ""
|
18
|
+
opt.separator "Options"
|
19
|
+
|
20
|
+
opt.on("-o","--output OUTPUT","where do you want the results/scaffold to be written?") do |o|
|
21
|
+
options[:output] = o
|
22
|
+
end
|
23
|
+
|
24
|
+
opt.on("-h","--help","help")
|
25
|
+
end
|
26
|
+
|
27
|
+
opt_parser.parse!
|
28
|
+
|
29
|
+
case ARGV[0]
|
30
|
+
|
31
|
+
when "new"
|
32
|
+
output = "new_rectory_redirects.csv"
|
33
|
+
output = options[:output] unless options[:output].nil?
|
34
|
+
puts "\nGenerating new redirects spreadsheet..."
|
35
|
+
CSV.open(output, "wb") do |csv|
|
36
|
+
csv << ["url","location","code"]
|
37
|
+
csv << ["http://google.com","http://www.google.com",301]
|
38
|
+
csv << ["http://www.google.com",nil,200]
|
39
|
+
end
|
40
|
+
puts "\nFinished: #{output}\n"
|
41
|
+
|
42
|
+
when "test"
|
43
|
+
output = "results_#{ARGV[1]}"
|
44
|
+
output = options[:output] unless options[:output].nil?
|
45
|
+
expectations = []
|
46
|
+
CSV.foreach(ARGV[1]) do |row|
|
47
|
+
expectations << Rectory::Expectation.new(row[0], :location => row[1], :code => row[2].to_i)
|
48
|
+
end
|
49
|
+
expectations.shift
|
50
|
+
puts "\nTesting #{expectations.count.to_s} expectations in #{ARGV[1]}..."
|
51
|
+
results = Rectory.perform expectations
|
52
|
+
Rectory::CsvOutputter.write results, output
|
53
|
+
puts "\nFinished! Report written to #{output}\n"
|
54
|
+
|
55
|
+
when "help", nil
|
56
|
+
puts opt_parser
|
57
|
+
|
58
|
+
end
|
59
|
+
|
data/lib/rectory.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rectory/version'
|
2
|
+
require 'rectory/request'
|
3
|
+
require 'rectory/csv_outputter'
|
4
|
+
require 'rectory/expectation'
|
5
|
+
|
6
|
+
Celluloid.logger = nil
|
7
|
+
|
8
|
+
module Rectory
|
9
|
+
|
10
|
+
DEFAULT_CELLULOID_OPTIONS = {
|
11
|
+
:pool => 10
|
12
|
+
}
|
13
|
+
|
14
|
+
# Test the expectated results of an some HTTP requests
|
15
|
+
#
|
16
|
+
# Utilizes celluloid pooling futures for speed.
|
17
|
+
#
|
18
|
+
# @param expectations [Array] a `Rectory::Expectation` set you're testing
|
19
|
+
# @param options [Hash] Celluloid `pool()` options
|
20
|
+
# @return [Array] the same set of expectations with result attibutes updated
|
21
|
+
def self.perform(expectations, options = {})
|
22
|
+
options = DEFAULT_CELLULOID_OPTIONS.merge options
|
23
|
+
pool = Rectory::Request.pool(options)
|
24
|
+
futures = expectations.map { |e| pool.future(:perform, e) }
|
25
|
+
results = futures.map(&:value)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Rectory
|
4
|
+
# Write the results of a test to a simple CSV file
|
5
|
+
class CsvOutputter
|
6
|
+
# @param results [Array] Rectory::Expectation set (with Rectory::Results)
|
7
|
+
# @param output [String] path to the desired output CSV
|
8
|
+
# @param options [Hash] options for CSV.open()
|
9
|
+
# @return [nil]
|
10
|
+
def self.write(results, output, options = {})
|
11
|
+
|
12
|
+
CSV.open(output, "wb", options) do |csv|
|
13
|
+
csv << ["url","location","code","result_location","result_code","pass"]
|
14
|
+
|
15
|
+
results.each do |r|
|
16
|
+
csv << [r.url, r.location, r.code, r.result[:location], r.result[:code], r.pass?]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Rectory
|
2
|
+
|
3
|
+
# The expectations for an HTTP request.
|
4
|
+
#
|
5
|
+
# @attr code The expected HTTP status code. (200, 302, 304, 404, 400, etc)
|
6
|
+
# @attr location The expected HTTP `Location` header, or the end location of a redirect. Should be `nil` if the expectation is not a redirect (200, 304, 404, etc)
|
7
|
+
# @attr url The URL to test
|
8
|
+
# @attr result A Rectory::Result instance which contains HTTP repsonse details
|
9
|
+
class Expectation
|
10
|
+
|
11
|
+
attr_accessor :url, :location, :code, :result
|
12
|
+
|
13
|
+
# @param url [String] The URL against which to test an HTTP reponse
|
14
|
+
# @param args [Hash] A hash of HTTP response expectations (`:code`, `:location`)
|
15
|
+
def initialize(url, args = {})
|
16
|
+
raise ArgumentError, "You must provide a URL to test!" if url.nil?
|
17
|
+
|
18
|
+
defaults = {
|
19
|
+
:code => 200,
|
20
|
+
:result => {}
|
21
|
+
}
|
22
|
+
|
23
|
+
args = defaults.merge args
|
24
|
+
self.url = url
|
25
|
+
self.code = args[:code].to_i
|
26
|
+
self.result = args[:result]
|
27
|
+
self.location = args[:location]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Determines whether the HTTP result satifies the expectations
|
31
|
+
#
|
32
|
+
# Verifies that both status code and location match
|
33
|
+
#
|
34
|
+
# @return [Boolean]
|
35
|
+
def pass?
|
36
|
+
perform if result.empty?
|
37
|
+
truths = []
|
38
|
+
truths << (result[:location].to_s.gsub(/\/$/, "") == location.to_s.gsub(/\/$/, ""))
|
39
|
+
truths << (result[:code] == code.to_i) unless code.nil?
|
40
|
+
truths.all?
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Run self through Rectory::Verfier#perform
|
46
|
+
#
|
47
|
+
# Updates the `result` attribute
|
48
|
+
def perform
|
49
|
+
v = Rectory::Request.new
|
50
|
+
r = v.perform self
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'celluloid'
|
4
|
+
|
5
|
+
module Rectory
|
6
|
+
|
7
|
+
# Test the expectated results of an HTTP request
|
8
|
+
class Request
|
9
|
+
include Celluloid
|
10
|
+
|
11
|
+
# Test the expectated results of an HTTP request
|
12
|
+
#
|
13
|
+
# @param expectation [Rectory::Expectation] the expectation you're testing
|
14
|
+
# @return [Rectory::Expectation] the same expectation with result attributes updated
|
15
|
+
def perform(expectation)
|
16
|
+
uri = URI expectation.url
|
17
|
+
req = Net::HTTP::Get.new uri.request_uri
|
18
|
+
|
19
|
+
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
20
|
+
http.request req
|
21
|
+
end
|
22
|
+
|
23
|
+
expectation.result[:location] = res['location']
|
24
|
+
expectation.result[:code] = res.code.to_i
|
25
|
+
|
26
|
+
return expectation
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rectory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Truscott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: celluloid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rb-fsevent
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: redcarpet
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Quickly test HTTP redirects and status codes.
|
112
|
+
email:
|
113
|
+
- keighl@keighl.com
|
114
|
+
executables:
|
115
|
+
- rectory
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- lib/rectory.rb
|
120
|
+
- lib/rectory/request.rb
|
121
|
+
- lib/rectory/csv_outputter.rb
|
122
|
+
- lib/rectory/expectation.rb
|
123
|
+
- lib/rectory/version.rb
|
124
|
+
- bin/rectory
|
125
|
+
homepage: https://github.com/keighl/rectory
|
126
|
+
licenses: []
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.0.2
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: 'HHave a ton of HTTP redirects, and need to verify they''re working? Use
|
148
|
+
this. Give rectory a list of live HTTP expectations, and it''ll tell you what happens:
|
149
|
+
status code, location, and whether it behaved as expected (i.e pass/fail).'
|
150
|
+
test_files: []
|
151
|
+
has_rdoc:
|