2013-02-06 03:16:51 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
describe ErrorLog do
|
|
|
|
|
|
|
|
def boom
|
|
|
|
raise "boom"
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
def exception
|
|
|
|
begin
|
2013-02-06 03:16:51 +08:00
|
|
|
boom
|
|
|
|
rescue => e
|
|
|
|
return e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def controller
|
|
|
|
DraftController.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def request
|
2013-03-23 23:02:59 +08:00
|
|
|
ActionController::TestRequest.new(host: 'test')
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "add_row!" do
|
|
|
|
it "creates a non empty file on first call" do
|
|
|
|
ErrorLog.clear_all!
|
|
|
|
ErrorLog.add_row!(hello: "world")
|
2014-09-25 23:44:48 +08:00
|
|
|
File.exists?(ErrorLog.filename).should == true
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
describe "logging data" do
|
2013-02-06 03:16:51 +08:00
|
|
|
it "is able to read the data it writes" do
|
|
|
|
ErrorLog.clear_all!
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
i = 0
|
2013-02-26 00:42:20 +08:00
|
|
|
ErrorLog.each do |h|
|
2013-02-06 03:16:51 +08:00
|
|
|
i += 1
|
2013-02-26 00:42:20 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
i.should == 2
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it "is able to skip rows" do
|
2013-02-06 03:16:51 +08:00
|
|
|
ErrorLog.clear_all!
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
ErrorLog.report!(exception, controller, request, nil)
|
|
|
|
i = 0
|
2013-02-26 00:42:20 +08:00
|
|
|
ErrorLog.skip(3) do |h|
|
2013-02-06 03:16:51 +08:00
|
|
|
i += 1
|
|
|
|
end
|
|
|
|
i.should == 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
end
|