shuriken 0.1.3 → 0.1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/shuriken.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Shuriken
2
2
 
3
- VERSION = "0.1.3".freeze
3
+ VERSION = "0.1.3.1".freeze
4
4
 
5
5
  def self.register_framework!
6
6
  Barista::Framework.register 'shuriken', File.expand_path('../coffeescripts', File.dirname(__FILE__))
data/shuriken.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shuriken}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Darcy Laycock"]
@@ -22,9 +22,6 @@ Gem::Specification.new do |s|
22
22
  "coffeescripts/shuriken.coffee",
23
23
  "coffeescripts/shuriken/mixins.coffee",
24
24
  "coffeescripts/shuriken/mixins/callbacks.coffee",
25
- "coffeescripts/shuriken/test.coffee",
26
- "coffeescripts/shuriken/test/assertions.coffee",
27
- "coffeescripts/shuriken/test/reporters.coffee",
28
25
  "javascripts/shuriken.js",
29
26
  "javascripts/shuriken/mixins.js",
30
27
  "javascripts/shuriken/mixins/callbacks.js",
metadata CHANGED
@@ -6,7 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 1
8
8
  - 3
9
- version: 0.1.3
9
+ - 1
10
+ version: 0.1.3.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Darcy Laycock
@@ -33,9 +34,6 @@ files:
33
34
  - coffeescripts/shuriken.coffee
34
35
  - coffeescripts/shuriken/mixins.coffee
35
36
  - coffeescripts/shuriken/mixins/callbacks.coffee
36
- - coffeescripts/shuriken/test.coffee
37
- - coffeescripts/shuriken/test/assertions.coffee
38
- - coffeescripts/shuriken/test/reporters.coffee
39
37
  - javascripts/shuriken.js
40
38
  - javascripts/shuriken/mixins.js
41
39
  - javascripts/shuriken/mixins/callbacks.js
@@ -1,111 +0,0 @@
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
-
@@ -1,61 +0,0 @@
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)
@@ -1,117 +0,0 @@
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)