-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_logger_spec.rb
71 lines (54 loc) · 2.12 KB
/
response_logger_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "ResponseLogger" do
before do
@path = File.join(RAILS_ROOT, "log", Date.today.strftime("%Y/%m/%d"))
end
def logged_files
Dir["#{@path}/**/*"].select { |item| File.file?(item) }
end
def response_check(logged_files, response)
File.read(logged_files.first).should(eql(response.body), "The logged file does not contain the same text as response body")
end
describe "Logging" do
before do
logged_files.size.should eql(0)
end
describe "Net::HTTP" do
describe "#get" do
it "root requests" do
logged_files.size.should eql(0)
Net::HTTP.get(URI.parse("http://github.com/"))
logged_files.size.should eql(1)
logged_files.detect { |file| /github\.com\/.*?/.match(file) }.should_not be_nil
end
end
describe "#new" do
it "works with SSL" do
logged_files.size.should eql(0)
url = URI.parse('https://github.com/login')
http = Net::HTTP.new(url.host, 443)
req = Net::HTTP::Get.new(url.path)
http.use_ssl = true
text = "Log in - GitHub"
response = http.request(req)
response.class.should eql(Net::HTTPOK)
logged_files.size.should eql(1)
logged_files.detect { |file| /login\/\d+/.match(file) }.should_not be_nil
response_check(logged_files, response)
end
it "works without SSL" do
logged_files.size.should eql(0)
url = URI.parse('https://github.com/')
http = Net::HTTP.new(url.host, 80)
req = Net::HTTP::Get.new(url.path)
text = "Secure source code hosting and collaborative development - GitHub"
response = http.request(req)
response.class.should eql(Net::HTTPOK)
logged_files.size.should eql(1)
logged_files.detect { |file| /github\.com\/\d+/.match(file) }.should_not be_nil
response_check(logged_files, response)
end
end
end
end
end