opal-spec 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -24
- data/config.ru +5 -0
- data/lib/assets/javascripts/opal/spec/browser_formatter.rb +154 -156
- data/lib/assets/javascripts/opal/spec/example.rb +59 -61
- data/lib/assets/javascripts/opal/spec/example_group.rb +70 -72
- data/lib/assets/javascripts/opal/spec/expectations.rb +38 -39
- data/lib/assets/javascripts/opal/spec/kernel.rb +3 -3
- data/lib/assets/javascripts/opal/spec/matchers.rb +68 -70
- data/lib/assets/javascripts/opal/spec/phantom_formatter.rb +71 -73
- data/lib/assets/javascripts/opal/spec/runner.rb +59 -61
- data/lib/assets/javascripts/opal/spec/sprockets_runner.js.erb +11 -0
- data/lib/assets/javascripts/opal/spec.rb +5 -2
- data/lib/opal/spec/rake_task.rb +3 -2
- data/lib/opal/spec/server.rb +49 -0
- data/lib/opal/spec/version.rb +1 -1
- data/lib/opal/spec.rb +5 -3
- data/spec/specs.rb +4 -7
- data/vendor/spec_runner.html.erb +9 -0
- data/vendor/{runner.js → spec_runner.js} +0 -0
- metadata +7 -5
- data/lib/opal/spec/runner.rb +0 -12
- data/spec/index.html +0 -9
@@ -1,94 +1,92 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
module Spec
|
2
|
+
class ExampleGroup
|
3
|
+
@example_groups = []
|
4
|
+
def self.example_groups
|
5
|
+
@example_groups
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
@stack = []
|
9
|
+
def self.create desc, block
|
10
|
+
group = self.new desc, @stack.last
|
11
|
+
@example_groups << group
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
@stack << group
|
14
|
+
group.instance_eval &block
|
15
|
+
@stack.pop
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def initialize desc, parent
|
19
|
+
@desc = desc.to_s
|
20
|
+
@parent = parent
|
21
|
+
@examples = []
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
@before_hooks = []
|
24
|
+
@after_hooks = []
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def it(desc, &block)
|
28
|
+
@examples << Example.new(self, desc, block)
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
def async(desc, &block)
|
32
|
+
example = Example.new(self, desc, block)
|
33
|
+
example.asynchronous = true
|
34
|
+
@examples << example
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
37
|
+
def it_behaves_like(*objs)
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def before type = :each, &block
|
41
|
+
raise "unsupported before type: #{type}" unless type == :each
|
42
|
+
@before_hooks << block
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
def after type = :each, &block
|
46
|
+
raise "unsupported after type: #{type}" unless type == :each
|
47
|
+
@after_hooks << block
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def before_hooks
|
51
|
+
@parent ? [].concat(@parent.before_hooks).concat(@before_hooks) : @before_hooks
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def after_hooks
|
55
|
+
@parent ? [].concat(@parent.after_hooks).concat(@after_hooks) : @after_hooks
|
56
|
+
end
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def run(runner)
|
59
|
+
@runner = runner
|
60
|
+
@runner.example_group_started self
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
@running_examples = @examples.dup
|
63
|
+
run_next_example
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
66
|
+
def run_next_example
|
67
|
+
if @running_examples.empty?
|
68
|
+
@runner.example_group_finished self
|
69
|
+
else
|
70
|
+
@running_examples.shift.run
|
73
71
|
end
|
72
|
+
end
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
def example_started(example)
|
75
|
+
@runner.example_started(example)
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
def example_passed(example)
|
79
|
+
@runner.example_passed(example)
|
80
|
+
run_next_example
|
81
|
+
end
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
def example_failed(example)
|
84
|
+
@runner.example_failed(example)
|
85
|
+
run_next_example
|
86
|
+
end
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
end
|
88
|
+
def description
|
89
|
+
@parent ? "#{@parent.description} #{@desc}" : @desc
|
92
90
|
end
|
93
91
|
end
|
94
92
|
end
|
@@ -1,55 +1,54 @@
|
|
1
|
-
module Opal
|
2
|
-
module Spec
|
3
|
-
class ExpectationNotMetError < StandardError; end
|
4
|
-
|
5
|
-
module Expectations
|
6
|
-
def should matcher = nil
|
7
|
-
if matcher
|
8
|
-
matcher.match self
|
9
|
-
else
|
10
|
-
Opal::Spec::PositiveOperatorMatcher.new self
|
11
|
-
end
|
12
|
-
end
|
13
1
|
|
14
|
-
|
15
|
-
|
16
|
-
matcher.not_match self
|
17
|
-
else
|
18
|
-
Opal::Spec::NegativeOperatorMatcher.new self
|
19
|
-
end
|
20
|
-
end
|
2
|
+
module Spec
|
3
|
+
class ExpectationNotMetError < StandardError; end
|
21
4
|
|
22
|
-
|
23
|
-
|
5
|
+
module Expectations
|
6
|
+
def should matcher = nil
|
7
|
+
if matcher
|
8
|
+
matcher.match self
|
9
|
+
else
|
10
|
+
Spec::PositiveOperatorMatcher.new self
|
24
11
|
end
|
12
|
+
end
|
25
13
|
|
26
|
-
|
27
|
-
|
14
|
+
def should_not matcher = nil
|
15
|
+
if matcher
|
16
|
+
matcher.not_match self
|
17
|
+
else
|
18
|
+
Spec::NegativeOperatorMatcher.new self
|
28
19
|
end
|
20
|
+
end
|
29
21
|
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
def be_kind_of expected
|
23
|
+
Spec::BeKindOfMatcher.new expected
|
24
|
+
end
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
def be_nil
|
27
|
+
Spec::BeNilMatcher.new nil
|
28
|
+
end
|
37
29
|
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
def be_true
|
31
|
+
Spec::BeTrueMatcher.new true
|
32
|
+
end
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
def be_false
|
35
|
+
Spec::BeFalseMatcher.new false
|
36
|
+
end
|
45
37
|
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
def eq(expected)
|
39
|
+
Spec::EqlMatcher.new expected
|
40
|
+
end
|
41
|
+
|
42
|
+
def equal expected
|
43
|
+
Spec::EqualMatcher.new expected
|
44
|
+
end
|
45
|
+
|
46
|
+
def raise_error expected
|
47
|
+
Spec::RaiseErrorMatcher.new expected
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
52
|
class Object
|
54
|
-
include
|
53
|
+
include Spec::Expectations
|
55
54
|
end
|
@@ -1,105 +1,103 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
module Spec
|
2
|
+
class Matcher
|
3
|
+
def initialize(actual)
|
4
|
+
@actual = actual
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
7
|
+
def failure(message)
|
8
|
+
raise Spec::ExpectationNotMetError, message
|
11
9
|
end
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
12
|
+
class PositiveOperatorMatcher < Matcher
|
13
|
+
def == expected
|
14
|
+
if @actual == expected
|
15
|
+
true
|
16
|
+
else
|
17
|
+
failure "expected: #{expected.inspect}, got: #{@actual.inspect} (using ==)."
|
20
18
|
end
|
21
19
|
end
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
22
|
+
class NegativeOperatorMatcher < Matcher
|
23
|
+
def == expected
|
24
|
+
if @actual == expected
|
25
|
+
failure "expected: #{expected.inspect} not to be #{@actual.inspect} (using ==)."
|
28
26
|
end
|
29
27
|
end
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
30
|
+
class BeKindOfMatcher < Matcher
|
31
|
+
def match expected
|
32
|
+
unless expected.kind_of? @actual
|
33
|
+
failure "expected #{expected.inspect} to be a kind of #{@actual.name}, not #{expected.class.name}."
|
36
34
|
end
|
37
35
|
end
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
38
|
+
class BeNilMatcher < Matcher
|
39
|
+
def match expected
|
40
|
+
unless expected.nil?
|
41
|
+
failure "expected #{expected.inspect} to be nil."
|
44
42
|
end
|
45
43
|
end
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
46
|
+
class BeTrueMatcher < Matcher
|
47
|
+
def match expected
|
48
|
+
unless expected == true
|
49
|
+
failure "expected #{expected.inspect} to be true."
|
52
50
|
end
|
53
51
|
end
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
54
|
+
class BeFalseMatcher < Matcher
|
55
|
+
def match expected
|
56
|
+
unless expected == false
|
57
|
+
failure "expected #{expected.inspect} to be false."
|
60
58
|
end
|
61
59
|
end
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
62
|
+
class EqlMatcher < Matcher
|
63
|
+
def match(expected)
|
64
|
+
unless expected == @actual
|
65
|
+
failure "expected: #{expected.inspect}, got: #{@actual.inspect} (using ==)."
|
68
66
|
end
|
67
|
+
end
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
69
|
+
def not_match(expected)
|
70
|
+
if expected.equal? @actual
|
71
|
+
failure "expected: #{expected.inspect} not to be #{@actual.inspect} (using ==)."
|
74
72
|
end
|
75
73
|
end
|
74
|
+
end
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
76
|
+
class EqualMatcher < Matcher
|
77
|
+
def match expected
|
78
|
+
unless expected.equal? @actual
|
79
|
+
failure "expected #{@actual.inspect} to be the same as #{expected.inspect}."
|
82
80
|
end
|
81
|
+
end
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
83
|
+
def not_match expected
|
84
|
+
if expected.equal? @actual
|
85
|
+
failure "expected #{@actual.inspect} not to be equal to #{expected.inspect}."
|
88
86
|
end
|
89
87
|
end
|
88
|
+
end
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
90
|
+
class RaiseErrorMatcher < Matcher
|
91
|
+
def match block
|
92
|
+
should_raise = false
|
93
|
+
begin
|
94
|
+
block.call
|
95
|
+
should_raise = true
|
96
|
+
rescue => e
|
97
|
+
end
|
99
98
|
|
100
|
-
|
101
|
-
|
102
|
-
end
|
99
|
+
if should_raise
|
100
|
+
failure "expected #{@actual} to be raised, but nothing was."
|
103
101
|
end
|
104
102
|
end
|
105
103
|
end
|
@@ -1,93 +1,91 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
module Spec
|
2
|
+
class PhantomFormatter
|
3
|
+
def initialize
|
4
|
+
@examples = []
|
5
|
+
@failed_examples = []
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def log_green(str)
|
9
|
+
`console.log('\\033[32m' + str + '\\033[0m')`
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def log_red(str)
|
13
|
+
`console.log('\\033[31m' + str + '\\033[0m')`
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def log(str)
|
17
|
+
`console.log(str)`
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def start
|
21
|
+
@start_time = Time.now.to_f
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
def finish
|
25
|
+
time = Time.now.to_f - @start_time
|
26
|
+
if @failed_examples.empty?
|
27
|
+
log "\nFinished"
|
28
|
+
log_green "#{example_count} examples, 0 failures (time taken: #{time})"
|
29
|
+
finish_with_code(0)
|
30
|
+
else
|
31
|
+
log "\nFailures:"
|
32
|
+
@failed_examples.each_with_index do |example, idx|
|
33
|
+
log "\n #{idx+1}. #{example.example_group.description} #{example.description}"
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
log_red " #{output}"
|
35
|
+
exception = example.exception
|
36
|
+
case exception
|
37
|
+
when Spec::ExpectationNotMetError
|
38
|
+
output = exception.message
|
39
|
+
else
|
40
|
+
output = "#{exception.class.name}: #{exception.message}\n"
|
41
|
+
output += " #{exception.backtrace.join "\n "}\n"
|
45
42
|
end
|
46
|
-
|
47
|
-
log "\nFinished"
|
48
|
-
log_red "#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
|
49
|
-
finish_with_code(1)
|
43
|
+
log_red " #{output}"
|
50
44
|
end
|
45
|
+
|
46
|
+
log "\nFinished"
|
47
|
+
log_red "#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
|
48
|
+
finish_with_code(1)
|
51
49
|
end
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
window.OPAL_SPEC_CODE = code;
|
60
|
-
}
|
52
|
+
def finish_with_code(code)
|
53
|
+
%x{
|
54
|
+
if (typeof(phantom) !== 'undefined') {
|
55
|
+
return phantom.exit(code);
|
61
56
|
}
|
62
|
-
|
57
|
+
else {
|
58
|
+
window.OPAL_SPEC_CODE = code;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
def example_group_started group
|
64
|
+
@example_group = group
|
65
|
+
@example_group_failed = false
|
66
|
+
log "\n#{group.description}"
|
67
|
+
end
|
69
68
|
|
70
|
-
|
71
|
-
|
69
|
+
def example_group_finished group
|
70
|
+
end
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
def example_started example
|
73
|
+
@examples << example
|
74
|
+
@example = example
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
def example_failed example
|
78
|
+
@failed_examples << example
|
79
|
+
@example_group_failed = true
|
80
|
+
log_red " #{example.description}"
|
81
|
+
end
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
def example_passed example
|
84
|
+
log_green " #{example.description}"
|
85
|
+
end
|
87
86
|
|
88
|
-
|
89
|
-
|
90
|
-
end
|
87
|
+
def example_count
|
88
|
+
@examples.size
|
91
89
|
end
|
92
90
|
end
|
93
91
|
end
|