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
|
# File 'lib/jspec_runner.rb', line 48
def jspec(options={})
opts = {
:execs => []
}.merge(options)
scripts = Nokogiri::HTML.parse(@response.body).css('script').map(&:to_s)
exec_commands = opts[:execs].map {|spec| ".exec('#{spec}')"}
run_suites = " <script>\n function runSuites() {\n JSpec\n \#{exec_commands.join(\"\\n\")}\n .run({ fixturePath: 'fixtures' })\n .report()\n }\n </script>\n HTML\n \n html = jspec_dom.gsub(/<userscripts\\/>/, scripts.join(\"\\n\")).gsub(/<runSuites\\/>/, run_suites)\n \n # TODO: consider making this gem use Harmony and not depend on HolyGrail -- too much duplication here\n XhrProxy.context = self\n @__page = Harmony::Page.new(rewrite_script_paths(html))\n Harmony::Page::Window::BASE_RUNTIME.wait\n \n result = {:passed => true}\n js_dom = HTML::Document.new(@__page.to_html, false, true).root\n HTML::Selector.new(\".has-failures\").select(js_dom).each do |wrapper|\n output = HTML::Selector.new(\"tr\").select(wrapper).map do |row|\n if row.attributes[\"class\"] == \"description\"\n \"\\n\" + text_only(row)\n elsif HTML::Selector.new(\".pass\").select(row).any?\n \"\\e[32mPassed\\e[0m: \" + text_only(row)\n elsif HTML::Selector.new(\".failed\").select(row).any?\n \"\\e[31mFailed\\e[0m: \" + text_only(row)\n else\n text_only(row)\n end\n end\n output = output.join(\"\\n\") + \"\\n\\nJSpec: \\e[32m\#{select_text(wrapper, \".heading .passes em\")} passes\\e[0m, \\e[31m\#{select_text(wrapper, \".heading .failures em\")} failures\\e[0m\\n\"\n # puts js_dom\n \n result = {:passed => false, :output => output}\n end\n return result\nend\n"
|