Fingertips-headless-squirrel 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/lib/headless_squirrel/test_case.rb +9 -8
- data/test/fixtures/syntax_error.html +27 -0
- data/test/fixtures/syntax_error.js +5 -0
- data/test/fixtures/type_error.html +27 -0
- data/test/fixtures/type_error.js +1 -0
- data/test/unit/runner_test.rb +1 -1
- data/test/unit/test_case_test.rb +53 -14
- metadata +8 -3
data/Rakefile
CHANGED
data/VERSION.yml
CHANGED
@@ -46,7 +46,6 @@ module HeadlessSquirrel
|
|
46
46
|
webView.mainFrame.DOMDocument
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
49
|
def log
|
51
50
|
document.getElementsByClassName('logsummary').item(0) || document.getElementById('logsummary')
|
52
51
|
end
|
@@ -78,13 +77,10 @@ module HeadlessSquirrel
|
|
78
77
|
# @delegate.test_case_finished(self)
|
79
78
|
# end
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# def webView_addMessageToConsole(_, msg)
|
86
|
-
# p msg
|
87
|
-
# end
|
80
|
+
def webView_addMessageToConsole(_, info)
|
81
|
+
puts format_js_log(info)
|
82
|
+
OSX::NSApplication.sharedApplication.terminate(self) if info['message'].to_s =~ /^[A-Z]\w+Error/
|
83
|
+
end
|
88
84
|
|
89
85
|
def handleEvent(event)
|
90
86
|
element = event.target
|
@@ -115,9 +111,14 @@ module HeadlessSquirrel
|
|
115
111
|
webView = self.class.sharedWebView
|
116
112
|
webView.mainFrame.loadRequest(req)
|
117
113
|
webView.frameLoadDelegate = self
|
114
|
+
webView.setUIDelegate(self)
|
118
115
|
webView
|
119
116
|
end
|
120
117
|
|
118
|
+
def format_js_log(info)
|
119
|
+
"#{info['sourceURL'][7..-1]}:#{info['lineNumber']}: #{info['message']}"
|
120
|
+
end
|
121
|
+
|
121
122
|
def finalize_test(result)
|
122
123
|
last_line = loglines.children.item(loglines.children.length-1)
|
123
124
|
log_row = self.class.parse_log_row(last_line)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<title>A HeadlessSquirrel Unit Test HTML File With Syntax Error</title>
|
6
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
7
|
+
|
8
|
+
<script type="text/javascript" charset="utf-8">
|
9
|
+
var eventResults = {};
|
10
|
+
var originalElement = window.Element;
|
11
|
+
</script>
|
12
|
+
|
13
|
+
<script src="../regression/prototype/unit/assets/prototype.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../regression/prototype/unit/assets/unittest.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
<script src="syntax_error.js" type="text/javascript" charset="utf-8"></script>
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
|
19
|
+
<div id="testlog"></div>
|
20
|
+
|
21
|
+
<div id="content"></div>
|
22
|
+
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
<script type="text/javascript" charset="utf-8">
|
26
|
+
eventResults.endOfDocument = true;
|
27
|
+
</script>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<title>A HeadlessSquirrel Unit Test HTML File With Type Error</title>
|
6
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
7
|
+
|
8
|
+
<script type="text/javascript" charset="utf-8">
|
9
|
+
var eventResults = {};
|
10
|
+
var originalElement = window.Element;
|
11
|
+
</script>
|
12
|
+
|
13
|
+
<script src="../regression/prototype/unit/assets/prototype.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../regression/prototype/unit/assets/unittest.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
<script src="type_error.js" type="text/javascript" charset="utf-8"></script>
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
|
19
|
+
<div id="testlog"></div>
|
20
|
+
|
21
|
+
<div id="content"></div>
|
22
|
+
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
<script type="text/javascript" charset="utf-8">
|
26
|
+
eventResults.endOfDocument = true;
|
27
|
+
</script>
|
@@ -0,0 +1 @@
|
|
1
|
+
this.doesNotExist();
|
data/test/unit/runner_test.rb
CHANGED
@@ -142,7 +142,7 @@ describe "HeadlessSquirrel::Runner, when finalizing" do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should print the time it took to run the tests" do
|
145
|
-
@runner.expects(:puts).with("
|
145
|
+
@runner.expects(:puts).with("Finished in 2.3 seconds.")
|
146
146
|
@runner.send(:finalize)
|
147
147
|
end
|
148
148
|
|
data/test/unit/test_case_test.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
|
3
|
+
module TestCaseHelper
|
4
|
+
def run_test_case!
|
5
|
+
@test_case.run
|
6
|
+
sleep 0.25 while not @test_case.finished?
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
3
10
|
describe "HeadlessSquirrel::TestCase, class methods" do
|
4
11
|
it "should return a shared WebView instance" do
|
5
12
|
HeadlessSquirrel::TestCase.sharedWebView.should.be.instance_of OSX::WebView
|
@@ -47,6 +54,8 @@ describe "HeadlessSquirrel::TestCase" do
|
|
47
54
|
end
|
48
55
|
|
49
56
|
describe "HeadlessSquirrel::TestCase, when running" do
|
57
|
+
include TestCaseHelper
|
58
|
+
|
50
59
|
before do
|
51
60
|
@delegate = stub_everything('delegate')
|
52
61
|
@test_case = HeadlessSquirrel::TestCase.alloc.initWithHTMLFile_delegate(fixture('a_unit_test.html'), @delegate)
|
@@ -78,13 +87,6 @@ describe "HeadlessSquirrel::TestCase, when running" do
|
|
78
87
|
@test_case.webView_didFinishLoadForFrame(nil, nil)
|
79
88
|
end
|
80
89
|
|
81
|
-
it "should not have finished yet if the inner html of the `log' element is `running...'" do
|
82
|
-
@test_case.instance_variable_set(:@finished, nil)
|
83
|
-
@test_case.log.stubs(:innerText).returns('running...')
|
84
|
-
@test_case.handleEvent(stubbed_log_event)
|
85
|
-
@test_case.should.not.be.finished
|
86
|
-
end
|
87
|
-
|
88
90
|
it "should have finished once the inner html of the `log' element is not longer `running...'" do
|
89
91
|
@test_case.instance_variable_set(:@finished, nil)
|
90
92
|
@test_case.handleEvent(stubbed_log_event)
|
@@ -120,8 +122,7 @@ describe "HeadlessSquirrel::TestCase, when running" do
|
|
120
122
|
@test_case.handleEvent(stubbed_loglines_event('failed'))
|
121
123
|
end
|
122
124
|
|
123
|
-
|
124
|
-
it "should let its delegate know a test ran if the targets class is one of passed, failed, or error" do
|
125
|
+
xit "should let its delegate know a test ran if the targets class is one of passed, failed, or error" do
|
125
126
|
@test_case = HeadlessSquirrel::TestCase.alloc.initWithHTMLFile_delegate(fixture('a_unit_test.html'), @delegate)
|
126
127
|
|
127
128
|
@delegate.expects(:test_ran).times(3).with do |test|
|
@@ -151,11 +152,6 @@ describe "HeadlessSquirrel::TestCase, when running" do
|
|
151
152
|
|
152
153
|
private
|
153
154
|
|
154
|
-
def run_test_case!
|
155
|
-
@test_case.run
|
156
|
-
sleep 0.25 while not @test_case.finished?
|
157
|
-
end
|
158
|
-
|
159
155
|
def stubbed_log_event
|
160
156
|
stub('Event', :target => @test_case.log.firstChild)
|
161
157
|
end
|
@@ -165,4 +161,47 @@ describe "HeadlessSquirrel::TestCase, when running" do
|
|
165
161
|
element.stubs(:parentNode).returns(@test_case.loglines.getElementsByClassName(klass).item(0))
|
166
162
|
stub('Event', :target => element)
|
167
163
|
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "HeadlessSquirrel::TestCase, when running a file with problems" do
|
167
|
+
include TestCaseHelper
|
168
|
+
|
169
|
+
before do
|
170
|
+
@delegate = stub_everything('delegate')
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should warn and terminate if a syntax error was encountered in the JavaScript" do
|
174
|
+
OSX::NSApplication.sharedApplication.expects(:terminate)
|
175
|
+
message = message_printed_while_running('syntax_error.html')
|
176
|
+
message.should == "#{fixture('syntax_error.js')}:4: SyntaxError: Parse error"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should warn and terminate if a type error was raised from the JavaScript runtime" do
|
180
|
+
OSX::NSApplication.sharedApplication.expects(:terminate)
|
181
|
+
message = message_printed_while_running('type_error.html')
|
182
|
+
message.should == "#{fixture('type_error.js')}:1: TypeError: Result of expression 'this.doesNotExist' [undefined] is not a function."
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should only warn if a message was logged which does not match the error regexp" do
|
186
|
+
@test_case = HeadlessSquirrel::TestCase.alloc.initWithHTMLFile_delegate(fixture('a_unit_test.html'), @delegate)
|
187
|
+
info = { 'message' => 'some other message', 'sourceURL' => 'file:///some/file.js', 'lineNumber' => '1' }
|
188
|
+
|
189
|
+
OSX::NSApplication.sharedApplication.expects(:terminate).never
|
190
|
+
@test_case.expects(:puts).with("/some/file.js:1: some other message")
|
191
|
+
@test_case.webView_addMessageToConsole(@test_case.webView, info)
|
192
|
+
end
|
193
|
+
|
194
|
+
private
|
195
|
+
|
196
|
+
def message_printed_while_running(fixture)
|
197
|
+
@test_case = HeadlessSquirrel::TestCase.alloc.initWithHTMLFile_delegate(fixture(fixture), @delegate)
|
198
|
+
|
199
|
+
def @test_case.puts(message)
|
200
|
+
@printed_message = message
|
201
|
+
@finished = true
|
202
|
+
end
|
203
|
+
|
204
|
+
run_test_case!
|
205
|
+
@test_case.instance_variable_get(:@printed_message)
|
206
|
+
end
|
168
207
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Fingertips-headless-squirrel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eloy Duran
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-21 00:00:00 -07:00
|
13
13
|
default_executable: jstest
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -33,6 +33,10 @@ files:
|
|
33
33
|
- lib/headless_squirrel/test_case.rb
|
34
34
|
- test/fixtures/a_unit_test.html
|
35
35
|
- test/fixtures/a_unit_test.js
|
36
|
+
- test/fixtures/syntax_error.html
|
37
|
+
- test/fixtures/syntax_error.js
|
38
|
+
- test/fixtures/type_error.html
|
39
|
+
- test/fixtures/type_error.js
|
36
40
|
- test/regression/prototype/unit/ajax_test.html
|
37
41
|
- test/regression/prototype/unit/array_test.html
|
38
42
|
- test/regression/prototype/unit/assets/prototype.js
|
@@ -150,6 +154,7 @@ files:
|
|
150
154
|
- test/unit/test_test.rb
|
151
155
|
has_rdoc: true
|
152
156
|
homepage: http://github.com/Fingertips/headless-squirrel/tree/master
|
157
|
+
licenses:
|
153
158
|
post_install_message:
|
154
159
|
rdoc_options:
|
155
160
|
- --charset=UTF-8
|
@@ -170,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
175
|
requirements: []
|
171
176
|
|
172
177
|
rubyforge_project:
|
173
|
-
rubygems_version: 1.
|
178
|
+
rubygems_version: 1.3.5
|
174
179
|
signing_key:
|
175
180
|
specification_version: 2
|
176
181
|
summary: A command-line JavaScript test runner for the Mac.
|