shuriken 0.1.2.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Rakefile +28 -0
- data/coffeescripts/shuriken/test/assertions.coffee +111 -0
- data/coffeescripts/shuriken/test/reporters.coffee +61 -0
- data/coffeescripts/shuriken/test.coffee +117 -0
- data/coffeescripts/shuriken.coffee +2 -2
- data/javascripts/shuriken/mixins/callbacks.js +45 -0
- data/javascripts/shuriken/mixins.js +58 -0
- data/javascripts/shuriken/test/assertions.js +117 -0
- data/javascripts/shuriken/test/reporters.js +84 -0
- data/javascripts/shuriken/test.js +165 -0
- data/javascripts/shuriken.js +195 -0
- data/lib/shuriken.rb +1 -1
- data/shuriken.gemspec +84 -4
- data/tests/basic_namespace_tests.coffee +114 -0
- data/tests/template.erb +26 -0
- data/tests.watchr +6 -0
- data/vendor/jasmine-0.10.0/MIT.LICENSE +20 -0
- data/vendor/jasmine-0.10.0/README.markdown +437 -0
- data/vendor/jasmine-0.10.0/doc/files.html +460 -0
- data/vendor/jasmine-0.10.0/doc/index.html +322 -0
- data/vendor/jasmine-0.10.0/doc/symbols/_global_.html +918 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Block.html +417 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Clock.html +678 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Env.html +1169 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.JsApiReporter.html +822 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Matchers.html +1461 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.MultiReporter.html +394 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.NestedResults.html +710 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Reporter.html +574 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Runner.html +710 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Spec.html +1259 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Spy.html +855 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Suite.html +705 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.html +1345 -0
- data/vendor/jasmine-0.10.0/doc/symbols/jasmine.util.html +535 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/lib_TrivialReporter.js.html +124 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Block.js.html +29 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Env.js.html +240 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_JsApiReporter.js.html +111 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Matchers.js.html +328 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_MultiReporter.js.html +36 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_NestedResults.js.html +88 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_PrettyPrinter.js.html +130 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Queue.js.html +102 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Reporter.js.html +35 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Reporters.js.html +51 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Runner.js.html +75 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Spec.js.html +211 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_Suite.js.html +77 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_WaitsBlock.js.html +21 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_base.js.html +555 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_mock-timeout.js.html +185 -0
- data/vendor/jasmine-0.10.0/doc/symbols/src/src_util.js.html +75 -0
- data/vendor/jasmine-0.10.0/example/example_runner.html +25 -0
- data/vendor/jasmine-0.10.0/example/spec/example_suite.js +11 -0
- data/vendor/jasmine-0.10.0/lib/TrivialReporter.js +117 -0
- data/vendor/jasmine-0.10.0/lib/consolex.js +28 -0
- data/vendor/jasmine-0.10.0/lib/jasmine-0.10.0.js +2261 -0
- data/vendor/jasmine-0.10.0/lib/jasmine.css +86 -0
- data/vendor/jasmine-0.10.0/spec/runner.html +63 -0
- data/vendor/jasmine-0.10.0/spec/suites/CustomMatchersSpec.js +112 -0
- data/vendor/jasmine-0.10.0/spec/suites/EnvSpec.js +71 -0
- data/vendor/jasmine-0.10.0/spec/suites/ExceptionsSpec.js +107 -0
- data/vendor/jasmine-0.10.0/spec/suites/JsApiReporterSpec.js +82 -0
- data/vendor/jasmine-0.10.0/spec/suites/MatchersSpec.js +589 -0
- data/vendor/jasmine-0.10.0/spec/suites/MockClockSpec.js +34 -0
- data/vendor/jasmine-0.10.0/spec/suites/MultiReporterSpec.js +30 -0
- data/vendor/jasmine-0.10.0/spec/suites/NestedResultsSpec.js +54 -0
- data/vendor/jasmine-0.10.0/spec/suites/PrettyPrintSpec.js +93 -0
- data/vendor/jasmine-0.10.0/spec/suites/QueueSpec.js +23 -0
- data/vendor/jasmine-0.10.0/spec/suites/ReporterSpec.js +60 -0
- data/vendor/jasmine-0.10.0/spec/suites/RunnerSpec.js +258 -0
- data/vendor/jasmine-0.10.0/spec/suites/SpecRunningSpec.js +1086 -0
- data/vendor/jasmine-0.10.0/spec/suites/SpecSpec.js +110 -0
- data/vendor/jasmine-0.10.0/spec/suites/SpySpec.js +187 -0
- data/vendor/jasmine-0.10.0/spec/suites/SuiteSpec.js +101 -0
- data/vendor/jasmine-0.10.0/spec/suites/TrivialReporterSpec.js +140 -0
- data/vendor/jasmine-0.10.0/spec/suites/UtilSpec.js +23 -0
- data/vendor/jquery.js +154 -0
- data/wip-coffeescripts/example_test.coffee +0 -0
- data/wip-coffeescripts/test/assertions.coffee +111 -0
- data/wip-coffeescripts/test/reporters.coffee +61 -0
- data/wip-coffeescripts/test.coffee +96 -15
- metadata +83 -4
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
test-output
|
data/Rakefile
CHANGED
|
@@ -18,3 +18,31 @@ begin
|
|
|
18
18
|
rescue LoadError
|
|
19
19
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
20
20
|
end
|
|
21
|
+
|
|
22
|
+
desc "Compiles the javascript from Coffeescript to Javascript"
|
|
23
|
+
task :compile_scripts do
|
|
24
|
+
Dir["coffeescripts/**/*.coffee"].each do |cs|
|
|
25
|
+
output = File.dirname(cs).gsub("coffeescripts", "javascripts")
|
|
26
|
+
system "coffee", "-c", "--no-wrap", cs, "-o", output
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
task :test => :compile_scripts do
|
|
31
|
+
require 'erb'
|
|
32
|
+
template = ERB.new(File.read("tests/template.erb"))
|
|
33
|
+
FileUtils.mkdir_p 'test-output'
|
|
34
|
+
FileUtils.rm_rf 'test-output/*'
|
|
35
|
+
Dir["tests/*.coffee"].each do |test|
|
|
36
|
+
test_name = File.basename(test, ".coffee")
|
|
37
|
+
$js_file = "#{test_name}.js"
|
|
38
|
+
File.open("test-output/#{test_name}.html", "w+") do |f|
|
|
39
|
+
f.write template.result
|
|
40
|
+
end
|
|
41
|
+
$js_file = nil
|
|
42
|
+
system "coffee", "-c", "--no-wrap", test, "-o", "test-output"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
task :watchr do
|
|
47
|
+
system "watchr tests.watchr"
|
|
48
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# General assertions.
|
|
2
|
+
Shuriken.Test.Assertions: ((ns) ->
|
|
3
|
+
|
|
4
|
+
ns.currentAssertionCatcher: null
|
|
5
|
+
|
|
6
|
+
class ns.AssertionCatcher
|
|
7
|
+
|
|
8
|
+
constructor: ->
|
|
9
|
+
@passedCount: 0
|
|
10
|
+
@passedMessages: []
|
|
11
|
+
@failedOn: null
|
|
12
|
+
|
|
13
|
+
failAssertion: (e) ->
|
|
14
|
+
@failedOn: e
|
|
15
|
+
|
|
16
|
+
passAssertion: (e) ->
|
|
17
|
+
@passedMessages.push e.message
|
|
18
|
+
@passedCount++
|
|
19
|
+
|
|
20
|
+
failedReason: ->
|
|
21
|
+
return "Not failed" if !@failedOn?
|
|
22
|
+
@failedOn.toString()
|
|
23
|
+
|
|
24
|
+
passed: -> not @failed()
|
|
25
|
+
|
|
26
|
+
failed: -> @failedOn?
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ns.AssertionFailed
|
|
30
|
+
|
|
31
|
+
constructor: (message) ->
|
|
32
|
+
@message: message
|
|
33
|
+
|
|
34
|
+
toString: ->
|
|
35
|
+
"Assertion Failed: $@message"
|
|
36
|
+
|
|
37
|
+
ns.assert: (condition, message) ->
|
|
38
|
+
if condition
|
|
39
|
+
# TODO: Track in some sort of test scope.
|
|
40
|
+
console.log "Assertion passed: $message"
|
|
41
|
+
else
|
|
42
|
+
throw new ns.AssertionFailed message
|
|
43
|
+
|
|
44
|
+
ns.assertEqual: (expected, actual, message) ->
|
|
45
|
+
message?= "Expected $actual, got $expected."
|
|
46
|
+
ns.assert actual is expected, message
|
|
47
|
+
|
|
48
|
+
ns.assertBlock: (message, block) ->
|
|
49
|
+
if typeof message is "function"
|
|
50
|
+
block: message
|
|
51
|
+
message: "expected block to return true"
|
|
52
|
+
ns.assert block(), message
|
|
53
|
+
|
|
54
|
+
ns.assertInDelta: (expected, actual, delta, message) ->
|
|
55
|
+
message?= "expected $actual and $expected to be within $delta of each other."
|
|
56
|
+
ns.assert Math.abs(expected - actual) <= delta, message
|
|
57
|
+
|
|
58
|
+
ns.assertTypeOf: (expected, object, message) ->
|
|
59
|
+
message?= "Expected the type of $object to be $expected"
|
|
60
|
+
ns.assert (typeof object is expected), message
|
|
61
|
+
|
|
62
|
+
ns.assertTypeOfIsnt: (expected, object, message) ->
|
|
63
|
+
message?= "Expected the type of $object to not be $expected"
|
|
64
|
+
ns.assert (typeof object isnt expected), message
|
|
65
|
+
|
|
66
|
+
ns.assertInstanceOf: (expected, object, message) ->
|
|
67
|
+
message?= "Expected $object to be an instance of $expected"
|
|
68
|
+
ns.assert (object instanceof expected), message
|
|
69
|
+
|
|
70
|
+
ns.assertUndefined: (object, message) ->
|
|
71
|
+
message?= "Expected $object to be undefined"
|
|
72
|
+
ns.assertTypeOf 'undefined', object, message
|
|
73
|
+
|
|
74
|
+
ns.assertDefined: (object, message) ->
|
|
75
|
+
message?= "Expected $object to be defined"
|
|
76
|
+
ns.assertTypeOfIsnt 'undefined', object, message
|
|
77
|
+
|
|
78
|
+
ns.assertNotEqual: (expected, object, message) ->
|
|
79
|
+
message?= "Expected $object not to equal $expected"
|
|
80
|
+
ns.assert object isnt expected, message
|
|
81
|
+
|
|
82
|
+
ns.assertNull: (object, message) ->
|
|
83
|
+
message?= "Expected $object to be null"
|
|
84
|
+
ns.assert object is null, message
|
|
85
|
+
|
|
86
|
+
ns.assertNotNull: (object, message) ->
|
|
87
|
+
message?= "Expected $object to not be null"
|
|
88
|
+
ns.assert object isnt null, message
|
|
89
|
+
|
|
90
|
+
ns.flunk: (message) ->
|
|
91
|
+
message?= "Flunking test for no reason"
|
|
92
|
+
ns.assert false, "Flunk: $message"
|
|
93
|
+
|
|
94
|
+
)({})
|
|
95
|
+
|
|
96
|
+
Shuriken.Test.withAssertions: (closure) ->
|
|
97
|
+
`with(Shuriken.Test.Assertions) { closure() }`
|
|
98
|
+
|
|
99
|
+
Shuriken.Test.catchingAssertions: (closure) ->
|
|
100
|
+
ac: Shuriken.Test.AssertionCatcher
|
|
101
|
+
catcher: new ac()
|
|
102
|
+
old: ac.currentAssertionCatcher
|
|
103
|
+
ac.currentAssertionCatcher: catcher
|
|
104
|
+
try
|
|
105
|
+
closure()
|
|
106
|
+
catch e
|
|
107
|
+
catcher.failAssertion e
|
|
108
|
+
finally
|
|
109
|
+
ac.currentAssertionCatcher: old
|
|
110
|
+
catcher
|
|
111
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Shuriken.Test.Reporters: {}
|
|
2
|
+
|
|
3
|
+
((reporters) ->
|
|
4
|
+
|
|
5
|
+
class reporters.Reporter
|
|
6
|
+
|
|
7
|
+
constructor: (results) ->
|
|
8
|
+
@results: results
|
|
9
|
+
|
|
10
|
+
showResults: () -> throw "Please us an implemented reporter."
|
|
11
|
+
|
|
12
|
+
class reporters.ConsoleReporter extends reporters.Reporter
|
|
13
|
+
|
|
14
|
+
showResults: (results, padding) ->
|
|
15
|
+
results?= @results
|
|
16
|
+
padding?= 0
|
|
17
|
+
if $.isArray @results
|
|
18
|
+
# A
|
|
19
|
+
else if @results instanceof Shuriken.Test.ContextResult
|
|
20
|
+
# B
|
|
21
|
+
else if @results instanceof Shuriken.Test.AssertionCatcher
|
|
22
|
+
# C
|
|
23
|
+
|
|
24
|
+
puts: (args...) -> console.log('[Shuriken.Test.Reporters.ConsoleReporter]', args...)
|
|
25
|
+
|
|
26
|
+
paddedPuts: (padding, args...) ->
|
|
27
|
+
padding
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
showContext: (cr, padding) ->
|
|
31
|
+
padding?= 0
|
|
32
|
+
context: cr.context
|
|
33
|
+
@paddedPuts padding, "Context: $context.name"
|
|
34
|
+
@showResults cr.results, padding + 2
|
|
35
|
+
|
|
36
|
+
showTest: (tr, padding) ->
|
|
37
|
+
padding?= 0
|
|
38
|
+
assertions: tr.assertions
|
|
39
|
+
if assertions.failed()
|
|
40
|
+
@paddedPuts padding, "[\u2718]", tr.test.name, "(${assertions.failedReason()})"
|
|
41
|
+
else if assertions.passed() and assertions.passedCount > 0
|
|
42
|
+
@paddedPuts padding, "[\u2714]", tr.test.name
|
|
43
|
+
else
|
|
44
|
+
@paddedPuts padding, "[\u203D]", tr.test.name, "(Pending)"
|
|
45
|
+
|
|
46
|
+
showArray: (array, padding) ->
|
|
47
|
+
padding?= 0
|
|
48
|
+
lastIndex: array.length - 1
|
|
49
|
+
for i in [0..lastIndex]
|
|
50
|
+
@showResults array[i], padding
|
|
51
|
+
@paddedPuts padding, "" unless i == lastIndex
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# Set the current reporter.
|
|
55
|
+
reporters.current: reporters.ConsoleReporter
|
|
56
|
+
|
|
57
|
+
Shuriken.Test.displayResults: (results) ->
|
|
58
|
+
reporter: new reporters.current results
|
|
59
|
+
reporter.showResults()
|
|
60
|
+
|
|
61
|
+
)(Shuriken.Test.Reporters)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Shuriken.Test = {
|
|
2
|
+
currentContext: []
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
Shuriken.withObject: (object, block) ->
|
|
6
|
+
`with(object) { block.apply(object); }`
|
|
7
|
+
|
|
8
|
+
((test) ->
|
|
9
|
+
|
|
10
|
+
class test.ContextResult
|
|
11
|
+
|
|
12
|
+
constructor: (context, results) ->
|
|
13
|
+
@context: context
|
|
14
|
+
@results: results
|
|
15
|
+
|
|
16
|
+
class test.TestResult
|
|
17
|
+
|
|
18
|
+
constructor: (test, assertions) ->
|
|
19
|
+
@test: test
|
|
20
|
+
@assertions: assertions
|
|
21
|
+
|
|
22
|
+
class test.Context
|
|
23
|
+
|
|
24
|
+
constructor: (name, context) ->
|
|
25
|
+
@name: name
|
|
26
|
+
@blocks: {}
|
|
27
|
+
@context: context
|
|
28
|
+
|
|
29
|
+
blocksFor: (name) ->
|
|
30
|
+
@blocks[name]?= []
|
|
31
|
+
|
|
32
|
+
addBlockFor: (name, block) ->
|
|
33
|
+
@blocksFor(name).push block
|
|
34
|
+
|
|
35
|
+
run: ->
|
|
36
|
+
scope: @toScope()
|
|
37
|
+
@context.invokeBlocksFor "setupAll", scope if @context?
|
|
38
|
+
@invokeBlocksFor "setupAll", scope
|
|
39
|
+
# Invoke all stuff.
|
|
40
|
+
results: []
|
|
41
|
+
Shuriken.withObject @, -> results: @invokeBlocksFor("inner", scope)
|
|
42
|
+
@invokeBlocksFor "teardownAll", scope
|
|
43
|
+
@context.invokeBlocksFor "teardownAll", scope if @context?
|
|
44
|
+
new test.ContextResult @, results
|
|
45
|
+
|
|
46
|
+
toScope: ->
|
|
47
|
+
return @scope if @scope?
|
|
48
|
+
scope: ->
|
|
49
|
+
scope.prototype: @context.toScope() if @context?
|
|
50
|
+
self: @
|
|
51
|
+
@scope: new scope()
|
|
52
|
+
@scope.setup: ->
|
|
53
|
+
superSetup: scope::setup
|
|
54
|
+
superSetup.apply(@) if superSetup?
|
|
55
|
+
self.invokeBlocksFor "setup", @
|
|
56
|
+
@scope.teardown: ->
|
|
57
|
+
superSetup: scope::teardown
|
|
58
|
+
superSetup.apply(@) if superTeardown?
|
|
59
|
+
self.invokeBlocksFor "teardown", @
|
|
60
|
+
|
|
61
|
+
invokeBlocksFor: (blockName, scope) ->
|
|
62
|
+
block.apply(scope) for block in @blocksFor(blockNmae)
|
|
63
|
+
|
|
64
|
+
setup: (c) -> @addBlockFor "setup", c
|
|
65
|
+
teardown: (c) -> @addBlockFor "teardown", c
|
|
66
|
+
setupAll: (c) -> @addBlockFor "setupAll", c
|
|
67
|
+
teardownAll: (c) -> @addBlockFor "teardownAll", c
|
|
68
|
+
|
|
69
|
+
context: (name, block) ->
|
|
70
|
+
context: new test.Context name, @
|
|
71
|
+
block.apply context
|
|
72
|
+
addBlockFor 'inner', -> context.run
|
|
73
|
+
|
|
74
|
+
should: (name, block) ->
|
|
75
|
+
test: new test.Test name, block, @
|
|
76
|
+
addBlockFor 'inner', -> test.run
|
|
77
|
+
|
|
78
|
+
class test.Test
|
|
79
|
+
|
|
80
|
+
constructor: (name, body, context) ->
|
|
81
|
+
@name: name
|
|
82
|
+
@body: body
|
|
83
|
+
@context: context
|
|
84
|
+
|
|
85
|
+
run: ->
|
|
86
|
+
scope = @toScope()
|
|
87
|
+
scope.setup()
|
|
88
|
+
result: Shuriken.Test.catchingAssertions -> @body.apply scope
|
|
89
|
+
scope.teardown()
|
|
90
|
+
new test.TestResult @, result
|
|
91
|
+
|
|
92
|
+
toScope: ->
|
|
93
|
+
scope: ->
|
|
94
|
+
scope.prototype: @context
|
|
95
|
+
scope: new scope()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
test.displayResults: (results) ->
|
|
99
|
+
# Do nothing at the moment...
|
|
100
|
+
|
|
101
|
+
test.testsFor: (name, block) ->
|
|
102
|
+
context: new test.Context name
|
|
103
|
+
test.tests[name]: context
|
|
104
|
+
Shuriken.withObject context, block
|
|
105
|
+
context.runSuite: ->
|
|
106
|
+
results: @run()
|
|
107
|
+
test.displayResults results
|
|
108
|
+
|
|
109
|
+
test.tests: {}
|
|
110
|
+
|
|
111
|
+
test.runAll: ->
|
|
112
|
+
results: test.run() for test in test.tests when test.runSuite?
|
|
113
|
+
test.displayResults results
|
|
114
|
+
|
|
115
|
+
test
|
|
116
|
+
|
|
117
|
+
)(Shuriken.Test)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __slice = Array.prototype.slice;
|
|
2
|
+
Shuriken.defineExtension(function(baseNS) {
|
|
3
|
+
return baseNS.defineMixin('Callbacks', function(mixin) {
|
|
4
|
+
mixin.callbacks = {};
|
|
5
|
+
mixin.defineCallback = function defineCallback(key) {
|
|
6
|
+
this[("on" + key)] = function(callback) {
|
|
7
|
+
return this.hasCallback(key, callback);
|
|
8
|
+
};
|
|
9
|
+
this[("invoke" + key)] = function() {
|
|
10
|
+
var args;
|
|
11
|
+
args = __slice.call(arguments, 0, arguments.length - 0);
|
|
12
|
+
return this.invokeCallbacks.apply(this, [key].concat(args));
|
|
13
|
+
};
|
|
14
|
+
return true;
|
|
15
|
+
};
|
|
16
|
+
mixin.hasCallback = function hasCallback(name, callback) {
|
|
17
|
+
var _a, callbacks;
|
|
18
|
+
callbacks = mixin.callbacks[name] = (typeof (_a = mixin.callbacks[name]) !== "undefined" && _a !== null) ? mixin.callbacks[name] : [];
|
|
19
|
+
callbacks.push(callback);
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
mixin.callbacksFor = function callbacksFor(name) {
|
|
23
|
+
var existing;
|
|
24
|
+
existing = mixin.callbacks[name];
|
|
25
|
+
if ((typeof existing !== "undefined" && existing !== null)) {
|
|
26
|
+
return existing;
|
|
27
|
+
} else {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
mixin.invokeCallbacks = function invokeCallbacks(name) {
|
|
32
|
+
var _a, _b, _c, args, callback;
|
|
33
|
+
args = __slice.call(arguments, 1, arguments.length - 0);
|
|
34
|
+
_b = mixin.callbacksFor(name);
|
|
35
|
+
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
|
36
|
+
callback = _b[_a];
|
|
37
|
+
if (callback.apply(this, args) === false) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
return mixin.invokeCallbacks;
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Shuriken.defineExtension(function(baseNS) {
|
|
2
|
+
return baseNS.withNS('Mixins', function(ns) {
|
|
3
|
+
var defineMixin, root;
|
|
4
|
+
root = this.getRootNS();
|
|
5
|
+
ns.mixins = {};
|
|
6
|
+
root.mixins = {};
|
|
7
|
+
root.withBase(function(base) {
|
|
8
|
+
base.mixin = function mixin(mixins) {
|
|
9
|
+
return ns.mixin(this, mixins);
|
|
10
|
+
};
|
|
11
|
+
return base.mixin;
|
|
12
|
+
});
|
|
13
|
+
defineMixin = function defineMixin(key, mixin) {
|
|
14
|
+
this.mixins[key] = mixin;
|
|
15
|
+
return this.mixins[key];
|
|
16
|
+
};
|
|
17
|
+
root.defineMixin = defineMixin;
|
|
18
|
+
ns.define = defineMixin;
|
|
19
|
+
ns.lookupMixin = function lookupMixin(mixin) {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
if ((_a = typeof mixin) === "string") {
|
|
22
|
+
if ((typeof (_b = ns.mixins[mixin]) !== "undefined" && _b !== null)) {
|
|
23
|
+
return ns.mixins[mixin];
|
|
24
|
+
} else if ((typeof (_c = root.mixins[mixin]) !== "undefined" && _c !== null)) {
|
|
25
|
+
return root.mixins[mixin];
|
|
26
|
+
} else {
|
|
27
|
+
return {};
|
|
28
|
+
// unknown mixin, return a blank object.
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
return mixin;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
ns.invokeMixin = function invokeMixin(scope, mixin) {
|
|
35
|
+
var _a;
|
|
36
|
+
if ((_a = typeof mixin) === "string") {
|
|
37
|
+
return ns.invokeMixin(scope, ns.lookupMixin(mixin));
|
|
38
|
+
} else if (_a === "function") {
|
|
39
|
+
return mixin.call(scope, scope);
|
|
40
|
+
} else if (_a === "object") {
|
|
41
|
+
return $.extend(scope, mixin);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
ns.mixin = function mixin(scope, mixins) {
|
|
45
|
+
var _a, _b, _c, mixin;
|
|
46
|
+
if (!($.isArray(mixins))) {
|
|
47
|
+
mixins = [mixins];
|
|
48
|
+
}
|
|
49
|
+
_b = mixins;
|
|
50
|
+
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
|
51
|
+
mixin = _b[_a];
|
|
52
|
+
ns.invokeMixin(scope, ns.lookupMixin(mixin));
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
};
|
|
56
|
+
return ns.mixin;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// General assertions.
|
|
2
|
+
Shuriken.Test.Assertions = (function(ns) {
|
|
3
|
+
ns.currentAssertionCatcher = null;
|
|
4
|
+
ns.AssertionCatcher = function AssertionCatcher() {
|
|
5
|
+
this.passedCount = 0;
|
|
6
|
+
this.passedMessages = [];
|
|
7
|
+
this.failedOn = null;
|
|
8
|
+
return this;
|
|
9
|
+
};
|
|
10
|
+
ns.AssertionCatcher.prototype.failAssertion = function failAssertion(e) {
|
|
11
|
+
this.failedOn = e;
|
|
12
|
+
return this.failedOn;
|
|
13
|
+
};
|
|
14
|
+
ns.AssertionCatcher.prototype.passAssertion = function passAssertion(e) {
|
|
15
|
+
this.passedMessages.push(e.message);
|
|
16
|
+
return this.passedCount++;
|
|
17
|
+
};
|
|
18
|
+
ns.AssertionCatcher.prototype.failedReason = function failedReason() {
|
|
19
|
+
var _a;
|
|
20
|
+
if (!(typeof (_a = this.failedOn) !== "undefined" && _a !== null)) {
|
|
21
|
+
return "Not failed";
|
|
22
|
+
}
|
|
23
|
+
return this.failedOn.toString();
|
|
24
|
+
};
|
|
25
|
+
ns.AssertionCatcher.prototype.passed = function passed() {
|
|
26
|
+
return !this.failed();
|
|
27
|
+
};
|
|
28
|
+
ns.AssertionCatcher.prototype.failed = function failed() {
|
|
29
|
+
var _a;
|
|
30
|
+
return (typeof (_a = this.failedOn) !== "undefined" && _a !== null);
|
|
31
|
+
};
|
|
32
|
+
ns.AssertionFailed = function AssertionFailed(message) {
|
|
33
|
+
this.message = message;
|
|
34
|
+
return this;
|
|
35
|
+
};
|
|
36
|
+
ns.AssertionFailed.prototype.toString = function toString() {
|
|
37
|
+
return "Assertion Failed: " + this.message;
|
|
38
|
+
};
|
|
39
|
+
ns.assert = function assert(condition, message) {
|
|
40
|
+
if (condition) {
|
|
41
|
+
// TODO: Track in some sort of test scope.
|
|
42
|
+
return console.log(("Assertion passed: " + message));
|
|
43
|
+
} else {
|
|
44
|
+
throw new ns.AssertionFailed(message);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
ns.assertEqual = function assertEqual(expected, actual, message) {
|
|
48
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected " + actual + ", got " + expected + ".");
|
|
49
|
+
return ns.assert(actual === expected, message);
|
|
50
|
+
};
|
|
51
|
+
ns.assertBlock = function assertBlock(message, block) {
|
|
52
|
+
if (typeof message === "function") {
|
|
53
|
+
block = message;
|
|
54
|
+
message = "expected block to return true";
|
|
55
|
+
}
|
|
56
|
+
return ns.assert(block(), message);
|
|
57
|
+
};
|
|
58
|
+
ns.assertInDelta = function assertInDelta(expected, actual, delta, message) {
|
|
59
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("expected " + actual + " and " + expected + " to be within " + delta + " of each other.");
|
|
60
|
+
return ns.assert(Math.abs(expected - actual) <= delta, message);
|
|
61
|
+
};
|
|
62
|
+
ns.assertTypeOf = function assertTypeOf(expected, object, message) {
|
|
63
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected the type of " + object + " to be " + expected);
|
|
64
|
+
return ns.assert((typeof object === expected), message);
|
|
65
|
+
};
|
|
66
|
+
ns.assertTypeOfIsnt = function assertTypeOfIsnt(expected, object, message) {
|
|
67
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected the type of " + object + " to not be " + expected);
|
|
68
|
+
return ns.assert((typeof object !== expected), message);
|
|
69
|
+
};
|
|
70
|
+
ns.assertInstanceOf = function assertInstanceOf(expected, object, message) {
|
|
71
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected " + object + " to be an instance of " + expected);
|
|
72
|
+
return ns.assert((object instanceof expected), message);
|
|
73
|
+
};
|
|
74
|
+
ns.assertUndefined = function assertUndefined(object, message) {
|
|
75
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected " + object + " to be undefined");
|
|
76
|
+
return ns.assertTypeOf('undefined', object, message);
|
|
77
|
+
};
|
|
78
|
+
ns.assertDefined = function assertDefined(object, message) {
|
|
79
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected " + object + " to be defined");
|
|
80
|
+
return ns.assertTypeOfIsnt('undefined', object, message);
|
|
81
|
+
};
|
|
82
|
+
ns.assertNotEqual = function assertNotEqual(expected, object, message) {
|
|
83
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected " + object + " not to equal " + expected);
|
|
84
|
+
return ns.assert(object !== expected, message);
|
|
85
|
+
};
|
|
86
|
+
ns.assertNull = function assertNull(object, message) {
|
|
87
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected " + object + " to be null");
|
|
88
|
+
return ns.assert(object === null, message);
|
|
89
|
+
};
|
|
90
|
+
ns.assertNotNull = function assertNotNull(object, message) {
|
|
91
|
+
message = (typeof message !== "undefined" && message !== null) ? message : ("Expected " + object + " to not be null");
|
|
92
|
+
return ns.assert(object !== null, message);
|
|
93
|
+
};
|
|
94
|
+
ns.flunk = function flunk(message) {
|
|
95
|
+
message = (typeof message !== "undefined" && message !== null) ? message : "Flunking test for no reason";
|
|
96
|
+
return ns.assert(false, ("Flunk: " + message));
|
|
97
|
+
};
|
|
98
|
+
return ns.flunk;
|
|
99
|
+
})({});
|
|
100
|
+
Shuriken.Test.withAssertions = function withAssertions(closure) {
|
|
101
|
+
return with(Shuriken.Test.Assertions) { closure() };
|
|
102
|
+
};
|
|
103
|
+
Shuriken.Test.catchingAssertions = function catchingAssertions(closure) {
|
|
104
|
+
var ac, catcher, old;
|
|
105
|
+
ac = Shuriken.Test.AssertionCatcher;
|
|
106
|
+
catcher = new ac();
|
|
107
|
+
old = ac.currentAssertionCatcher;
|
|
108
|
+
ac.currentAssertionCatcher = catcher;
|
|
109
|
+
try {
|
|
110
|
+
closure();
|
|
111
|
+
} catch (e) {
|
|
112
|
+
catcher.failAssertion(e);
|
|
113
|
+
} finally {
|
|
114
|
+
ac.currentAssertionCatcher = old;
|
|
115
|
+
}
|
|
116
|
+
return catcher;
|
|
117
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __slice = Array.prototype.slice, __extends = function(child, parent) {
|
|
2
|
+
var ctor = function(){ };
|
|
3
|
+
ctor.prototype = parent.prototype;
|
|
4
|
+
child.__superClass__ = parent.prototype;
|
|
5
|
+
child.prototype = new ctor();
|
|
6
|
+
child.prototype.constructor = child;
|
|
7
|
+
};
|
|
8
|
+
Shuriken.Test.Reporters = {};
|
|
9
|
+
(function(reporters) {
|
|
10
|
+
reporters.Reporter = function Reporter(results) {
|
|
11
|
+
this.results = results;
|
|
12
|
+
return this;
|
|
13
|
+
};
|
|
14
|
+
reporters.Reporter.prototype.showResults = function showResults() {
|
|
15
|
+
throw "Please us an implemented reporter.";
|
|
16
|
+
};
|
|
17
|
+
reporters.ConsoleReporter = function ConsoleReporter() {
|
|
18
|
+
return reporters.Reporter.apply(this, arguments);
|
|
19
|
+
};
|
|
20
|
+
__extends(reporters.ConsoleReporter, reporters.Reporter);
|
|
21
|
+
reporters.ConsoleReporter.prototype.showResults = function showResults(results, padding) {
|
|
22
|
+
results = (typeof results !== "undefined" && results !== null) ? results : this.results;
|
|
23
|
+
padding = (typeof padding !== "undefined" && padding !== null) ? padding : 0;
|
|
24
|
+
if ($.isArray(this.results)) {
|
|
25
|
+
// A
|
|
26
|
+
} else if (this.results instanceof Shuriken.Test.ContextResult) {
|
|
27
|
+
// B
|
|
28
|
+
} else if (this.results instanceof Shuriken.Test.AssertionCatcher) {
|
|
29
|
+
// C
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
reporters.ConsoleReporter.prototype.puts = function puts() {
|
|
33
|
+
var args;
|
|
34
|
+
args = __slice.call(arguments, 0, arguments.length - 0);
|
|
35
|
+
return console.log.apply(console, ['[Shuriken.Test.Reporters.ConsoleReporter]'].concat(args));
|
|
36
|
+
};
|
|
37
|
+
reporters.ConsoleReporter.prototype.paddedPuts = function paddedPuts(padding) {
|
|
38
|
+
var args;
|
|
39
|
+
args = __slice.call(arguments, 1, arguments.length - 0);
|
|
40
|
+
return padding;
|
|
41
|
+
};
|
|
42
|
+
reporters.ConsoleReporter.prototype.showContext = function showContext(cr, padding) {
|
|
43
|
+
var context;
|
|
44
|
+
padding = (typeof padding !== "undefined" && padding !== null) ? padding : 0;
|
|
45
|
+
context = cr.context;
|
|
46
|
+
this.paddedPuts(padding, ("Context: " + context.name));
|
|
47
|
+
return this.showResults(cr.results, padding + 2);
|
|
48
|
+
};
|
|
49
|
+
reporters.ConsoleReporter.prototype.showTest = function showTest(tr, padding) {
|
|
50
|
+
var assertions;
|
|
51
|
+
padding = (typeof padding !== "undefined" && padding !== null) ? padding : 0;
|
|
52
|
+
assertions = tr.assertions;
|
|
53
|
+
if (assertions.failed()) {
|
|
54
|
+
return this.paddedPuts(padding, "[\u2718]", tr.test.name, ("(" + (assertions.failedReason()) + ")"));
|
|
55
|
+
} else if (assertions.passed() && assertions.passedCount > 0) {
|
|
56
|
+
return this.paddedPuts(padding, "[\u2714]", tr.test.name);
|
|
57
|
+
} else {
|
|
58
|
+
return this.paddedPuts(padding, "[\u203D]", tr.test.name, "(Pending)");
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
reporters.ConsoleReporter.prototype.showArray = function showArray(array, padding) {
|
|
62
|
+
var _a, _b, _c, _d, i, lastIndex;
|
|
63
|
+
padding = (typeof padding !== "undefined" && padding !== null) ? padding : 0;
|
|
64
|
+
lastIndex = array.length - 1;
|
|
65
|
+
_a = []; _c = 0; _d = lastIndex;
|
|
66
|
+
for (_b = 0, i = _c; (_c <= _d ? i <= _d : i >= _d); (_c <= _d ? i += 1 : i -= 1), _b++) {
|
|
67
|
+
_a.push((function() {
|
|
68
|
+
this.showResults(array[i], padding);
|
|
69
|
+
if (!(i === lastIndex)) {
|
|
70
|
+
return this.paddedPuts(padding, "");
|
|
71
|
+
}
|
|
72
|
+
}).call(this));
|
|
73
|
+
}
|
|
74
|
+
return _a;
|
|
75
|
+
};
|
|
76
|
+
// Set the current reporter.
|
|
77
|
+
reporters.current = reporters.ConsoleReporter;
|
|
78
|
+
Shuriken.Test.displayResults = function displayResults(results) {
|
|
79
|
+
var reporter;
|
|
80
|
+
reporter = new reporters.current(results);
|
|
81
|
+
return reporter.showResults();
|
|
82
|
+
};
|
|
83
|
+
return Shuriken.Test.displayResults;
|
|
84
|
+
})(Shuriken.Test.Reporters);
|