forked from CityGrid/citygrid_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.rb
110 lines (90 loc) · 2.48 KB
/
dashboard.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require 'rubygems'
require 'sinatra'
require "awesome_print"
require "riot"
require "haml"
require 'stringio'
IN_DASHBOARD = true
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib', "dashboard"))
require "stored_reporter"
require "sinatra_partial"
require "test_result"
helpers Sinatra::Partials
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require "citygrid_api"
CityGrid.publisher = "test"
CityGrid.load_config File.join(File.dirname(__FILE__), 'citygrid_api.yml.sample'), "qa"
def run_with_rescue
# don't do anything here, we'll catch
yield
end
module Riot
class Context
def run(reporter)
reporter.describe_context(self)
local_run(reporter, situation_class.new)
run_sub_contexts(reporter)
reporter
end
end
end
# hack to trap all HTTParty::Requests so we can inspect them
class RequestTrap
def self.trap
@@trap ||= []
end
end
module HTTParty
class Request
alias_method :old_perform, :perform
def perform
RequestTrap.trap << self
old_perform
end
end
end
# render stylesheets
get '/stylesheets/:name.css' do
content_type 'text/css', :charset => 'utf-8'
scss :"stylesheets/#{params[:name]}"
end
get '/' do
# we want to run tests ourselves
Riot.alone!
# test_paths = Dir.glob "test/**/test_*.rb"
test_paths = Dir.glob("test/**/test_*.rb").sort
# test_paths = ["test/api/ad_center/test_account.rb"]
@results = []
test_paths.each do |path|
eval(IO.read(path), binding, path)
# root_contexts << [path, Riot.root_contexts.clone]
result = TestResult.new path.gsub(/^test\//, "").gsub(/\.rb$/, "").split("/").map{|x| x.gsub("_", " ")}.join(" > ")
Riot.root_contexts.each do |context|
out = StringIO.new
reporter = StoredReporter.new out
begin
# $stdout = out
context.run reporter
rescue CityGrid::API::InvalidResponseFormat => ex
puts "CAUGHT AN ERROR!"
x = {"description" => ex.description, "server_msg" => ex.server_msg}
reporter.fail ex.description, ex.server_msg, "", ""
rescue => ex
puts "CAUGHT AN ERROR!"
reporter.fail ex.to_s, "", "", ""
ensure
# $stdout = STDOUT
end
reporter.context_finished
result.results += reporter.context_results
end
@results << result
Riot.root_contexts.clear
end
haml :test
end
get '/evented' do
stream(:keep_open) do |out|
EventMachine::PeriodicTimer.new(1) { out << "#{Time.now}\n" }
end
end