alloy-js-test-san 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +83 -0
- data/Rakefile +27 -0
- data/VERSION.yml +4 -0
- data/bin/jstest +10 -0
- data/lib/js_test_san/runner.rb +70 -0
- data/lib/js_test_san/test.rb +17 -0
- data/lib/js_test_san/test_case.rb +103 -0
- data/lib/js_test_san.rb +2 -0
- data/test/fixtures/a_unit_test.html +27 -0
- data/test/fixtures/a_unit_test.js +22 -0
- data/test/regression/prototype/unit/ajax_test.html +29 -0
- data/test/regression/prototype/unit/array_test.html +28 -0
- data/test/regression/prototype/unit/assets/prototype.js +4900 -0
- data/test/regression/prototype/unit/assets/unittest.css +50 -0
- data/test/regression/prototype/unit/assets/unittest.js +615 -0
- data/test/regression/prototype/unit/assets/unittest_transport.js +1 -0
- data/test/regression/prototype/unit/base_test.html +27 -0
- data/test/regression/prototype/unit/class_test.html +27 -0
- data/test/regression/prototype/unit/date_test.html +27 -0
- data/test/regression/prototype/unit/dom_test.html +304 -0
- data/test/regression/prototype/unit/element_mixins_test.html +30 -0
- data/test/regression/prototype/unit/enumerable_test.html +35 -0
- data/test/regression/prototype/unit/event_test.html +31 -0
- data/test/regression/prototype/unit/fixtures/ajax.html +2 -0
- data/test/regression/prototype/unit/fixtures/ajax.js +42 -0
- data/test/regression/prototype/unit/fixtures/array.html +1 -0
- data/test/regression/prototype/unit/fixtures/class.js +83 -0
- data/test/regression/prototype/unit/fixtures/content.html +1 -0
- data/test/regression/prototype/unit/fixtures/data.json +1 -0
- data/test/regression/prototype/unit/fixtures/dom.css +84 -0
- data/test/regression/prototype/unit/fixtures/dom.html +278 -0
- data/test/regression/prototype/unit/fixtures/dom.js +17 -0
- data/test/regression/prototype/unit/fixtures/element_mixins.html +4 -0
- data/test/regression/prototype/unit/fixtures/element_mixins.js +2 -0
- data/test/regression/prototype/unit/fixtures/empty.html +0 -0
- data/test/regression/prototype/unit/fixtures/empty.js +1 -0
- data/test/regression/prototype/unit/fixtures/enumerable.html +8 -0
- data/test/regression/prototype/unit/fixtures/enumerable.js +23 -0
- data/test/regression/prototype/unit/fixtures/event.html +4 -0
- data/test/regression/prototype/unit/fixtures/form.html +108 -0
- data/test/regression/prototype/unit/fixtures/function.js +13 -0
- data/test/regression/prototype/unit/fixtures/hash.js +25 -0
- data/test/regression/prototype/unit/fixtures/hello.js +1 -0
- data/test/regression/prototype/unit/fixtures/logo.gif +0 -0
- data/test/regression/prototype/unit/fixtures/object.html +6 -0
- data/test/regression/prototype/unit/fixtures/object.js +7 -0
- data/test/regression/prototype/unit/fixtures/position.html +9 -0
- data/test/regression/prototype/unit/fixtures/selector.html +71 -0
- data/test/regression/prototype/unit/fixtures/string.js +8 -0
- data/test/regression/prototype/unit/fixtures/unittest.html +18 -0
- data/test/regression/prototype/unit/form_test.html +135 -0
- data/test/regression/prototype/unit/function_test.html +27 -0
- data/test/regression/prototype/unit/hash_test.html +27 -0
- data/test/regression/prototype/unit/number_test.html +27 -0
- data/test/regression/prototype/unit/object_test.html +32 -0
- data/test/regression/prototype/unit/periodical_executer_test.html +27 -0
- data/test/regression/prototype/unit/position_test.html +36 -0
- data/test/regression/prototype/unit/prototype_test.html +27 -0
- data/test/regression/prototype/unit/range_test.html +27 -0
- data/test/regression/prototype/unit/regexp_test.html +27 -0
- data/test/regression/prototype/unit/selector_test.html +98 -0
- data/test/regression/prototype/unit/string_test.html +27 -0
- data/test/regression/prototype/unit/tests/ajax_test.js +379 -0
- data/test/regression/prototype/unit/tests/array_test.js +186 -0
- data/test/regression/prototype/unit/tests/base_test.js +43 -0
- data/test/regression/prototype/unit/tests/class_test.js +136 -0
- data/test/regression/prototype/unit/tests/date_test.js +5 -0
- data/test/regression/prototype/unit/tests/dom_test.js +1493 -0
- data/test/regression/prototype/unit/tests/element_mixins_test.js +32 -0
- data/test/regression/prototype/unit/tests/enumerable_test.js +271 -0
- data/test/regression/prototype/unit/tests/event_test.js +235 -0
- data/test/regression/prototype/unit/tests/form_test.js +382 -0
- data/test/regression/prototype/unit/tests/function_test.js +133 -0
- data/test/regression/prototype/unit/tests/hash_test.js +178 -0
- data/test/regression/prototype/unit/tests/number_test.js +44 -0
- data/test/regression/prototype/unit/tests/object_test.js +180 -0
- data/test/regression/prototype/unit/tests/periodical_executer_test.js +15 -0
- data/test/regression/prototype/unit/tests/position_test.js +44 -0
- data/test/regression/prototype/unit/tests/prototype_test.js +43 -0
- data/test/regression/prototype/unit/tests/range_test.js +58 -0
- data/test/regression/prototype/unit/tests/regexp_test.js +42 -0
- data/test/regression/prototype/unit/tests/selector_test.js +408 -0
- data/test/regression/prototype/unit/tests/string_test.js +548 -0
- data/test/regression/prototype/unit/tests/unittest_test.js +148 -0
- data/test/regression/prototype/unit/unittest_test.html +45 -0
- data/test/regression/prototype/upstream +1 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/runner_test.rb +165 -0
- data/test/unit/test_case_test.rb +167 -0
- data/test/unit/test_test.rb +24 -0
- metadata +145 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
var testObj = {
|
2
|
+
isNice: function() {
|
3
|
+
return true;
|
4
|
+
},
|
5
|
+
isBroken: function() {
|
6
|
+
return false;
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
new Test.Unit.Runner({
|
11
|
+
|
12
|
+
testIsRunningFromRake: function() {
|
13
|
+
if (window.location.toString().startsWith('http')) {
|
14
|
+
this.assert(this.isRunningFromRake);
|
15
|
+
this.info('These tests are running from rake.')
|
16
|
+
} else {
|
17
|
+
this.assert(!this.isRunningFromRake);
|
18
|
+
this.info('These tests are *not* running from rake.')
|
19
|
+
}
|
20
|
+
},
|
21
|
+
|
22
|
+
testBuildMessage: function() {
|
23
|
+
this.assertEqual("'foo' 'bar'", this.buildMessage('', '? ?', 'foo', 'bar'))
|
24
|
+
},
|
25
|
+
|
26
|
+
testAssertEqual: function() {
|
27
|
+
this.assertEqual(0, 0);
|
28
|
+
this.assertEqual(0, 0, "test");
|
29
|
+
|
30
|
+
this.assertEqual(0,'0');
|
31
|
+
this.assertEqual(65.0, 65);
|
32
|
+
|
33
|
+
this.assertEqual("a", "a");
|
34
|
+
this.assertEqual("a", "a", "test");
|
35
|
+
|
36
|
+
this.assertNotEqual(0, 1);
|
37
|
+
this.assertNotEqual("a","b");
|
38
|
+
this.assertNotEqual({},{});
|
39
|
+
this.assertNotEqual([],[]);
|
40
|
+
this.assertNotEqual([],{});
|
41
|
+
},
|
42
|
+
|
43
|
+
testAssertEnumEqual: function() {
|
44
|
+
this.assertEnumEqual([], []);
|
45
|
+
this.assertEnumEqual(['a', 'b'], ['a', 'b']);
|
46
|
+
this.assertEnumEqual(['1', '2'], [1, 2]);
|
47
|
+
this.assertEnumNotEqual(['1', '2'], [1, 2, 3]);
|
48
|
+
},
|
49
|
+
|
50
|
+
testAssertHashEqual: function() {
|
51
|
+
this.assertHashEqual({}, {});
|
52
|
+
this.assertHashEqual({a:'b'}, {a:'b'});
|
53
|
+
this.assertHashEqual({a:'b', c:'d'}, {c:'d', a:'b'});
|
54
|
+
this.assertHashNotEqual({a:'b', c:'d'}, {c:'d', a:'boo!'});
|
55
|
+
},
|
56
|
+
|
57
|
+
testAssertRespondsTo: function() {
|
58
|
+
this.assertRespondsTo('isNice', testObj);
|
59
|
+
this.assertRespondsTo('isBroken', testObj);
|
60
|
+
},
|
61
|
+
|
62
|
+
testAssertIdentical: function() {
|
63
|
+
this.assertIdentical(0, 0);
|
64
|
+
this.assertIdentical(0, 0, "test");
|
65
|
+
this.assertIdentical(1, 1);
|
66
|
+
this.assertIdentical('a', 'a');
|
67
|
+
this.assertIdentical('a', 'a', "test");
|
68
|
+
this.assertIdentical('', '');
|
69
|
+
this.assertIdentical(undefined, undefined);
|
70
|
+
this.assertIdentical(null, null);
|
71
|
+
this.assertIdentical(true, true);
|
72
|
+
this.assertIdentical(false, false);
|
73
|
+
|
74
|
+
var obj = {a:'b'};
|
75
|
+
this.assertIdentical(obj, obj);
|
76
|
+
|
77
|
+
this.assertNotIdentical({1:2,3:4},{1:2,3:4});
|
78
|
+
|
79
|
+
this.assertIdentical(1, 1.0); // both are typeof == 'number'
|
80
|
+
|
81
|
+
this.assertNotIdentical(1, '1');
|
82
|
+
this.assertNotIdentical(1, '1.0');
|
83
|
+
},
|
84
|
+
|
85
|
+
testAssertNullAndAssertUndefined: function() {
|
86
|
+
this.assertNull(null);
|
87
|
+
this.assertNotNull(undefined);
|
88
|
+
this.assertNotNull(0);
|
89
|
+
this.assertNotNull('');
|
90
|
+
this.assertNotUndefined(null);
|
91
|
+
this.assertUndefined(undefined);
|
92
|
+
this.assertNotUndefined(0);
|
93
|
+
this.assertNotUndefined('');
|
94
|
+
this.assertNullOrUndefined(null);
|
95
|
+
this.assertNullOrUndefined(undefined);
|
96
|
+
this.assertNotNullOrUndefined(0);
|
97
|
+
this.assertNotNullOrUndefined('');
|
98
|
+
},
|
99
|
+
|
100
|
+
testAssertMatch: function() {
|
101
|
+
this.assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
|
102
|
+
this.assertMatch(/Fuc/, 'Thomas Fuchs');
|
103
|
+
this.assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
|
104
|
+
this.assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
|
105
|
+
this.assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
|
106
|
+
this.assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
|
107
|
+
this.assertNoMatch(/zubar/, 'foo bar');
|
108
|
+
},
|
109
|
+
|
110
|
+
testAssertInstanceOf: function() {
|
111
|
+
this.assertInstanceOf(String, new String);
|
112
|
+
this.assertInstanceOf(RegExp, /foo/);
|
113
|
+
this.assertNotInstanceOf(String, {});
|
114
|
+
},
|
115
|
+
|
116
|
+
testAssertVisible: function() {
|
117
|
+
this.assertVisible('testcss1');
|
118
|
+
this.assertNotVisible('testcss1_span');
|
119
|
+
//this.assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
|
120
|
+
|
121
|
+
Element.hide('testcss1');
|
122
|
+
this.assertNotVisible('testcss1');
|
123
|
+
this.assertNotVisible('testcss1_span');
|
124
|
+
Element.show('testcss1');
|
125
|
+
this.assertVisible('testcss1');
|
126
|
+
this.assertNotVisible('testcss1_span');
|
127
|
+
|
128
|
+
Element.show('testcss1_span');
|
129
|
+
this.assertVisible('testcss1_span');
|
130
|
+
Element.hide('testcss1');
|
131
|
+
this.assertNotVisible('testcss1_span'); // hidden by parent
|
132
|
+
},
|
133
|
+
|
134
|
+
testAssertElementsMatch: function() {
|
135
|
+
this.assertElementsMatch($$('#tlist'), '#tlist');
|
136
|
+
this.assertElementMatches($('tlist'), '#tlist');
|
137
|
+
}
|
138
|
+
});
|
139
|
+
|
140
|
+
new Test.Unit.Runner({
|
141
|
+
testDummy: function() {
|
142
|
+
this.assert(true);
|
143
|
+
},
|
144
|
+
|
145
|
+
testMultipleTestRunner: function() {
|
146
|
+
this.assertEqual('passed', $('testlog_2').down('td', 1).innerHTML);
|
147
|
+
}
|
148
|
+
}, {testLog: 'testlog_2'});
|
@@ -0,0 +1,45 @@
|
|
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>Unit test file | Unittest | default template | 2009-04-11 15:28</title>
|
6
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
7
|
+
<script type="text/javascript" charset="utf-8">
|
8
|
+
var eventResults = {};
|
9
|
+
var originalElement = window.Element;
|
10
|
+
</script>
|
11
|
+
<script src="assets/prototype.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="assets/unittest.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<link rel="stylesheet" href="assets/unittest.css" type="text/css" />
|
14
|
+
|
15
|
+
|
16
|
+
<script src="tests/unittest_test.js" type="text/javascript" charset="utf-8"></script>
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
|
20
|
+
<div id="testlog"></div>
|
21
|
+
|
22
|
+
<div id="testlog_2"> </div>
|
23
|
+
|
24
|
+
<!-- Test elements follow -->
|
25
|
+
<div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
|
26
|
+
|
27
|
+
<div id="test_2"> <span> </span>
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
<div><div></div> </div><span> </span>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<ul id="tlist"><li id="tlist_1">x1</li><li id="tlist_2">x2</li></ul>
|
35
|
+
<ul id="tlist2"><li class="a" id="tlist2_1">x1</li><li id="tlist2_2">x2</li></ul>
|
36
|
+
|
37
|
+
<div id="testmoveby" style="background-color:#333;width:100px;">XXXX</div>
|
38
|
+
|
39
|
+
<div id="testcss1">testcss1<span id="testcss1_span" style="display:none;">blah</span></div><div id="testcss2">testcss1</div>
|
40
|
+
|
41
|
+
</body>
|
42
|
+
</html>
|
43
|
+
<script type="text/javascript" charset="utf-8">
|
44
|
+
eventResults.endOfDocument = true;
|
45
|
+
</script>
|
@@ -0,0 +1 @@
|
|
1
|
+
37bdd117a0a57c3d39075bd2d972de8dde71520f
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/spec'
|
3
|
+
require 'mocha'
|
4
|
+
|
5
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
6
|
+
require 'js_test_san'
|
7
|
+
|
8
|
+
FIXTURES = File.expand_path('../fixtures', __FILE__)
|
9
|
+
|
10
|
+
module TestHelper
|
11
|
+
def fixture(name)
|
12
|
+
File.join(FIXTURES, name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Test::Unit::TestCase.send(:include, TestHelper)
|
17
|
+
|
18
|
+
Thread.new do
|
19
|
+
OSX::NSApplication.sharedApplication.run
|
20
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module RunnerTestHelper
|
4
|
+
def setup
|
5
|
+
files = [fixture('a_unit_test.html'), fixture('a_unit_test.html')]
|
6
|
+
@runner = JSTestSan::Runner.alloc.initWithHTMLFiles(files)
|
7
|
+
|
8
|
+
@runner.stubs(:puts)
|
9
|
+
@runner.stubs(:print)
|
10
|
+
@runner.test_cases.first.stubs(:run)
|
11
|
+
@runner.test_cases.last.stubs(:run)
|
12
|
+
|
13
|
+
OSX::NSApplication.sharedApplication.stubs(:run)
|
14
|
+
OSX::NSApplication.sharedApplication.stubs(:terminate)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def test_stub(name)
|
20
|
+
test_case = JSTestSan::TestCase.alloc.initWithHTMLFile_delegate(fixture('a_unit_test.html'), stub_everything)
|
21
|
+
test_case.stubs(:title).returns("A test case with #{name}")
|
22
|
+
JSTestSan::TestCase::Test.new(test_case, name.to_s, name.to_sym, name.to_s)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "JSTestSan::Runner" do
|
27
|
+
include RunnerTestHelper
|
28
|
+
|
29
|
+
it "should have instantiated a JSTestSan::TestCase for each html file" do
|
30
|
+
@runner.test_cases.length.should == 2
|
31
|
+
@runner.test_cases.each do |test_case|
|
32
|
+
test_case.html_file.should == fixture('a_unit_test.html')
|
33
|
+
test_case.delegate.should == @runner
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not have finished yet" do
|
38
|
+
@runner.should.not.be.finished
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the total amount of tests" do
|
42
|
+
@runner.test_cases.each { |tc| tc.stubs(:tests).returns(3) }
|
43
|
+
@runner.tests.should == 6
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return the total amount of assertions" do
|
47
|
+
@runner.test_cases.each { |tc| tc.stubs(:assertions).returns(2) }
|
48
|
+
@runner.assertions.should == 4
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return the total amount of failures" do
|
52
|
+
@runner.test_cases.each { |tc| tc.stubs(:failures).returns(1) }
|
53
|
+
@runner.failures.should == 2
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return the total amount of errors" do
|
57
|
+
@runner.test_cases.each { |tc| tc.stubs(:errors).returns(1) }
|
58
|
+
@runner.errors.should == 2
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should run the tests cases and start a runloop" do
|
62
|
+
@runner.test_cases.first.expects(:run)
|
63
|
+
@runner.run
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should start a runloop when running the tests" do
|
67
|
+
OSX::NSApplication.sharedApplication.expects(:run)
|
68
|
+
@runner.run
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should store the start time" do
|
72
|
+
time = Time.now
|
73
|
+
Time.stubs(:now).returns(time)
|
74
|
+
|
75
|
+
@runner.run
|
76
|
+
@runner.instance_variable_get(:@start_time).should == time
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should keep a `queued' stack which contains all test cases that are running" do
|
80
|
+
@runner.run
|
81
|
+
@runner.queued.should == @runner.test_cases
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should remove a finished test case from the `queued' stack" do
|
85
|
+
@runner.run
|
86
|
+
@runner.test_case_finished(@runner.test_cases.first)
|
87
|
+
@runner.queued.should == [@runner.test_cases.last]
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should have finished once the `queued' stack is empty" do
|
91
|
+
@runner.run
|
92
|
+
@runner.test_case_finished(@runner.test_cases.first)
|
93
|
+
@runner.test_case_finished(@runner.test_cases.last)
|
94
|
+
@runner.should.be.finished
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return tests that have ran but didn't pass" do
|
98
|
+
test_case = stub(:title => 'A test case')
|
99
|
+
|
100
|
+
@runner.test_ran(test_stub(:passed))
|
101
|
+
@runner.test_ran(test_stub(:failed))
|
102
|
+
@runner.test_ran(test_stub(:error))
|
103
|
+
|
104
|
+
@runner.did_not_pass.first.name.should == 'failed'
|
105
|
+
@runner.did_not_pass.last.name.should == 'error'
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should print a dot when a test ran and passed" do
|
109
|
+
@runner.expects(:print).with('.')
|
110
|
+
@runner.test_ran(test_stub(:passed))
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should print a F when a test ran and failed" do
|
114
|
+
@runner.expects(:print).with('F')
|
115
|
+
@runner.test_ran(test_stub(:failed))
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should print an E when a test ran and an error occured" do
|
119
|
+
@runner.expects(:print).with('E')
|
120
|
+
@runner.test_ran(test_stub(:error))
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "JSTestSan::Runner, when finalizing" do
|
125
|
+
include RunnerTestHelper
|
126
|
+
|
127
|
+
def setup
|
128
|
+
super
|
129
|
+
time = Time.now
|
130
|
+
@runner.instance_variable_set(:@start_time, time)
|
131
|
+
Time.stubs(:now).returns(time + 2.3)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should print the tests that did not pass" do
|
135
|
+
test1, test2 = test_stub(:failed), test_stub(:error)
|
136
|
+
@runner.test_ran(test1)
|
137
|
+
@runner.test_ran(test2)
|
138
|
+
|
139
|
+
@runner.expects(:puts).with("\n 1) #{test1}")
|
140
|
+
@runner.expects(:puts).with("\n 2) #{test2}")
|
141
|
+
@runner.send(:finalize)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should print the time it took to run the tests" do
|
145
|
+
@runner.expects(:puts).with("\nFinished in 2.3 seconds.")
|
146
|
+
@runner.send(:finalize)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should print the total amount of tests, assertions, failures, and errors that have been ran" do
|
150
|
+
@runner.test_cases.each do |tc|
|
151
|
+
tc.stubs(:tests).returns(3)
|
152
|
+
tc.stubs(:assertions).returns(2)
|
153
|
+
tc.stubs(:failures).returns(1)
|
154
|
+
tc.stubs(:errors).returns(1)
|
155
|
+
end
|
156
|
+
|
157
|
+
@runner.expects(:puts).with("\n6 tests, 4 assertions, 2 failures, 2 errors")
|
158
|
+
@runner.send(:finalize)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should terminate the application" do
|
162
|
+
OSX::NSApplication.sharedApplication.expects(:terminate).with(@runner)
|
163
|
+
@runner.send(:finalize)
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "JSTestSan::TestCase, class methods" do
|
4
|
+
it "should return a shared WebView instance" do
|
5
|
+
JSTestSan::TestCase.sharedWebView.should.be.instance_of OSX::WebView
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "JSTestSan::TestCase" do
|
10
|
+
before do
|
11
|
+
@delegate = stub_everything('delegate')
|
12
|
+
@test_case = JSTestSan::TestCase.alloc.initWithHTMLFile_delegate(fixture('a_unit_test.html'), @delegate)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should initialize with a html file and delegate" do
|
16
|
+
@test_case.html_file.should == fixture('a_unit_test.html')
|
17
|
+
@test_case.delegate.should == @delegate
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise a FileDoesNotExistError if the given html file does not exist" do
|
21
|
+
lambda {
|
22
|
+
JSTestSan::TestCase.alloc.initWithHTMLFile_delegate('/does/not/exist/test.html', @delegate)
|
23
|
+
}.should.raise JSTestSan::TestCase::FileDoesNotExistError
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should instantiate a WebView with the html file and set itself as the frameLoadDelegate" do
|
27
|
+
@test_case.webView.should == JSTestSan::TestCase.sharedWebView
|
28
|
+
@test_case.webView.mainFrameURL.should == "file://#{fixture('a_unit_test.html')}"
|
29
|
+
@test_case.webView.frameLoadDelegate.should == @test_case
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not have finished yet" do
|
33
|
+
@test_case.should.not.be.finished
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have set tests, assertions, failures, and errors to zero" do
|
37
|
+
@test_case.tests.should == 0
|
38
|
+
@test_case.assertions.should == 0
|
39
|
+
@test_case.failures.should == 0
|
40
|
+
@test_case.errors.should == 0
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should run the tests" do
|
44
|
+
@test_case.expects(:webView)
|
45
|
+
@test_case.run
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "JSTestSan::TestCase, when running" do
|
50
|
+
before do
|
51
|
+
@delegate = stub_everything('delegate')
|
52
|
+
@test_case = JSTestSan::TestCase.alloc.initWithHTMLFile_delegate(fixture('a_unit_test.html'), @delegate)
|
53
|
+
run_test_case!
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return the DOM document" do
|
57
|
+
@test_case.document.should.be.instance_of OSX::DOMHTMLDocument
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have stored the document title" do
|
61
|
+
@test_case.title.should == 'A JSTestSan Unit Test HTML File'
|
62
|
+
@test_case.instance_variable_get(:@title).should == 'A JSTestSan Unit Test HTML File'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return the `log' element" do
|
66
|
+
@test_case.log.should.be.instance_of OSX::DOMHTMLDivElement
|
67
|
+
@test_case.log.className.should == 'logsummary'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return the `loglines' element" do
|
71
|
+
@test_case.loglines.should.be.instance_of OSX::DOMHTMLTableSectionElement
|
72
|
+
@test_case.loglines.className.should == 'loglines'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should register itself as an event handler for DOMSubtreeModified events on the `log' and `loglines' element" do
|
76
|
+
@test_case.log.expects(:addEventListener___).with('DOMSubtreeModified', @test_case, true)
|
77
|
+
@test_case.loglines.expects(:addEventListener___).with('DOMSubtreeModified', @test_case, true)
|
78
|
+
@test_case.webView_didFinishLoadForFrame(nil, nil)
|
79
|
+
end
|
80
|
+
|
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
|
+
it "should have finished once the inner html of the `log' element is not longer `running...'" do
|
89
|
+
@test_case.instance_variable_set(:@finished, nil)
|
90
|
+
@test_case.handleEvent(stubbed_log_event)
|
91
|
+
@test_case.should.be.finished
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return the number of tests, assertions, failures, and errors" do
|
95
|
+
@test_case.tests.should == 3
|
96
|
+
@test_case.assertions.should == 2
|
97
|
+
@test_case.failures.should == 1
|
98
|
+
@test_case.errors.should == 1
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should let its delegate know its finished running" do
|
102
|
+
@delegate.expects(:test_case_finished).with(@test_case)
|
103
|
+
@test_case.handleEvent(stubbed_log_event)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should not let its delegate know a test ran if the targets class is not one of passed, failed, or error" do
|
107
|
+
@delegate.expects(:test_ran).never
|
108
|
+
event = stubbed_loglines_event('passed')
|
109
|
+
|
110
|
+
event.target.parentNode.stubs(:className).returns('')
|
111
|
+
@test_case.handleEvent(event)
|
112
|
+
|
113
|
+
event.target.parentNode.stubs(:className).returns('foo')
|
114
|
+
@test_case.handleEvent(event)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not let its delegate know a test ran if the output is still empty" do
|
118
|
+
@delegate.expects(:test_ran).never
|
119
|
+
String.any_instance.stubs(:sub).returns('')
|
120
|
+
@test_case.handleEvent(stubbed_loglines_event('failed'))
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should let its delegate know a test ran if the targets class is one of passed, failed, or error" do
|
124
|
+
@test_case = JSTestSan::TestCase.alloc.initWithHTMLFile_delegate(fixture('a_unit_test.html'), @delegate)
|
125
|
+
|
126
|
+
@delegate.expects(:test_ran).times(3).with do |test|
|
127
|
+
test.name.should == case test.state
|
128
|
+
when :passed
|
129
|
+
'testHelloWorldSuccess'
|
130
|
+
when :failed
|
131
|
+
'testHelloWorldFailure'
|
132
|
+
when :error
|
133
|
+
'testHelloWorldError'
|
134
|
+
end
|
135
|
+
|
136
|
+
test.output.should == case test.state
|
137
|
+
when :passed
|
138
|
+
""
|
139
|
+
when :failed
|
140
|
+
"Failure: assertEqual\nexpected: <'Hello world!'>, actual: <''>"
|
141
|
+
when :error
|
142
|
+
"TypeError: Value undefined (result of expression this.content.foo) is not object., error=(TypeError: Value undefined (result of expression this.content.foo) is not object.)"
|
143
|
+
end
|
144
|
+
|
145
|
+
true # for mocha
|
146
|
+
end
|
147
|
+
|
148
|
+
run_test_case!
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
def run_test_case!
|
154
|
+
@test_case.run
|
155
|
+
sleep 0.25 while not @test_case.finished?
|
156
|
+
end
|
157
|
+
|
158
|
+
def stubbed_log_event
|
159
|
+
stub('Event', :target => @test_case.log.firstChild)
|
160
|
+
end
|
161
|
+
|
162
|
+
def stubbed_loglines_event(klass)
|
163
|
+
element = @test_case.loglines.getElementsByClassName(klass).item(0).children.item(3)
|
164
|
+
element.stubs(:parentNode).returns(@test_case.loglines.getElementsByClassName(klass).item(0))
|
165
|
+
stub('Event', :target => element)
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "JSTestSan::TestCase::Test" do
|
4
|
+
before do
|
5
|
+
@delegate = stub_everything('delegate')
|
6
|
+
@test_case = JSTestSan::TestCase.alloc.initWithHTMLFile_delegate(fixture('a_unit_test.html'), @delegate)
|
7
|
+
@test_case.instance_variable_set(:@title, 'A test case')
|
8
|
+
|
9
|
+
@test = JSTestSan::TestCase::Test.new(@test_case, 'testHelloWorld', :failed, 'did not meet expectation')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should initialize with a TestCase, name, state and output" do
|
13
|
+
@test.test_case.should == @test_case
|
14
|
+
@test.name.should == 'testHelloWorld'
|
15
|
+
@test.state.should == :failed
|
16
|
+
@test.output.should == 'did not meet expectation'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return a formatted string" do
|
20
|
+
@test.to_s.should == %{Failed:
|
21
|
+
testHelloWorld (A test case) [#{fixture('a_unit_test.html')}]:
|
22
|
+
did not meet expectation}
|
23
|
+
end
|
24
|
+
end
|