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
|
# File 'lib/autogen_rspec.rb', line 4
def log_test
begin
puts "in log file"
f = File.open('tmp/request/test.rb','a')
temp = ''
str = "it 'should ' do \n"
str = str + "\n# cookies #{cookies.inspect} \n" if cookies
if request.env['REQUEST_METHOD'] == 'GET' or request.env['REQUEST_METHOD'] == 'DELETE'
str = str + "#{request.env['REQUEST_METHOD'].downcase} '#{request.env['REQUEST_URI']}',{'HTTP_ACCEPT' => '#{request.env['HTTP_ACCEPT']}'} \n"
else
temp = ap(CGI.unescape(request.raw_post)) rescue ''
str = str + "\n# req = " + temp.to_s + "\n\n"
temp = ap(JSON.parse(CGI.unescape(request.raw_post))) rescue ''
str = str + "\n# " + temp.to_s + "\n\n"
str = str + "#{request.env['REQUEST_METHOD'].downcase} '#{request.env['REQUEST_URI']}',CGI.escape(req),{'HTTP_ACCEPT' => '#{request.env['HTTP_ACCEPT']}'} \n"
end
str = str + "assert_equal #{status},status,@response.body \n"
str = str + "assert_equal '#{response.content_type}', @response.content_type \n"
if response.content_type == 'application/json'
resp_hash = JSON.parse(response.body)
keys = ap resp_hash.keys, {:index => false}
str = str + 'resp_hash = JSON.parse(response.body)' + "\n"
str = str + keys.inspect + '.each {|x| assert_equal true,resp_hash.has_key?(x),"Did not find key \#{x} in json"}' + "\n"
else
end
str = str + "end\n"
rescue Exception => e
str = "Logging test error ... #{e}, #{e.backtrace}"
end
f.write("\n\n#{str}")
f.fsync
end
|