opal-spec 0.2.8 → 0.2.9
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/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
data/Rakefile
CHANGED
@@ -1,27 +1,5 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler.require
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
File.open('build/opal-spec.js', 'w+') do |out|
|
7
|
-
out.puts Opal.process('opal-spec')
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
desc "Build example specs ready to run"
|
12
|
-
task :build_specs => [:dir] do
|
13
|
-
Opal.append_path File.join(File.dirname(__FILE__), 'spec')
|
14
|
-
|
15
|
-
File.open('build/specs.js', 'w+') do |out|
|
16
|
-
out.puts Opal.process('specs')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
task :dir do
|
20
|
-
FileUtils.mkdir_p 'build'
|
21
|
-
end
|
22
|
-
|
23
|
-
task :test do
|
24
|
-
Opal::Spec.runner
|
25
|
-
end
|
26
|
-
|
27
|
-
task :default => [:build_specs, :test]
|
4
|
+
require 'opal/spec/rake_task'
|
5
|
+
Opal::Spec::RakeTask.new(:default)
|
data/config.ru
ADDED
@@ -1,194 +1,192 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Spec
|
2
|
+
class BrowserFormatter
|
3
|
+
CSS = <<-EOS
|
4
|
+
|
5
|
+
body {
|
6
|
+
font-size: 14px;
|
7
|
+
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
|
8
|
+
}
|
9
|
+
|
10
|
+
pre {
|
11
|
+
font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace;
|
12
|
+
font-size: 12px;
|
13
|
+
color: #444444;
|
14
|
+
white-space: pre;
|
15
|
+
padding: 3px 0px 3px 12px;
|
16
|
+
margin: 0px 0px 8px;
|
17
|
+
|
18
|
+
background: #FAFAFA;
|
19
|
+
-webkit-box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset;
|
20
|
+
-webkit-border-radius: 3px;
|
21
|
+
-moz-border-radius: 3px;
|
22
|
+
border-radius: 3px;
|
23
|
+
border: 1px solid #DDDDDD;
|
24
|
+
}
|
25
|
+
|
26
|
+
ul.example_groups {
|
27
|
+
list-style-type: none;
|
28
|
+
}
|
29
|
+
|
30
|
+
li.group.passed .group_description {
|
31
|
+
color: #597800;
|
32
|
+
font-weight: bold;
|
33
|
+
}
|
34
|
+
|
35
|
+
li.group.failed .group_description {
|
36
|
+
color: #FF000E;
|
37
|
+
font-weight: bold;
|
38
|
+
}
|
39
|
+
|
40
|
+
li.example.passed {
|
41
|
+
color: #597800;
|
42
|
+
}
|
43
|
+
|
44
|
+
li.example.failed {
|
45
|
+
color: #FF000E;
|
46
|
+
}
|
47
|
+
|
48
|
+
.examples {
|
49
|
+
list-style-type: none;
|
50
|
+
}
|
51
|
+
EOS
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
@examples = []
|
55
|
+
@failed_examples = []
|
56
|
+
end
|
10
57
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
white-space: pre;
|
16
|
-
padding: 3px 0px 3px 12px;
|
17
|
-
margin: 0px 0px 8px;
|
18
|
-
|
19
|
-
background: #FAFAFA;
|
20
|
-
-webkit-box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset;
|
21
|
-
-webkit-border-radius: 3px;
|
22
|
-
-moz-border-radius: 3px;
|
23
|
-
border-radius: 3px;
|
24
|
-
border: 1px solid #DDDDDD;
|
58
|
+
def start
|
59
|
+
%x{
|
60
|
+
if (!document || !document.body) {
|
61
|
+
#{ raise "Not running in browser." };
|
25
62
|
}
|
26
63
|
|
27
|
-
|
28
|
-
|
29
|
-
|
64
|
+
var summary_element = document.createElement('p');
|
65
|
+
summary_element.className = 'summary';
|
66
|
+
summary_element.innerHTML = "Running...";
|
30
67
|
|
31
|
-
|
32
|
-
|
33
|
-
font-weight: bold;
|
34
|
-
}
|
68
|
+
var groups_element = document.createElement('ul');
|
69
|
+
groups_element.className = 'example_groups';
|
35
70
|
|
36
|
-
|
37
|
-
color: #FF000E;
|
38
|
-
font-weight: bold;
|
39
|
-
}
|
71
|
+
var target = document.getElementById('opal-spec-output');
|
40
72
|
|
41
|
-
|
42
|
-
|
73
|
+
if (!target) {
|
74
|
+
target = document.body;
|
43
75
|
}
|
44
76
|
|
45
|
-
|
46
|
-
|
47
|
-
}
|
48
|
-
|
49
|
-
.examples {
|
50
|
-
list-style-type: none;
|
51
|
-
}
|
52
|
-
EOS
|
77
|
+
target.appendChild(summary_element);
|
78
|
+
target.appendChild(groups_element);
|
53
79
|
|
54
|
-
|
55
|
-
|
56
|
-
@failed_examples = []
|
57
|
-
end
|
80
|
+
var styles = document.createElement('style');
|
81
|
+
styles.type = 'text/css';
|
58
82
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
83
|
+
if (styles.styleSheet) {
|
84
|
+
styles.styleSheet.cssText = __scope.CSS;
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
styles.appendChild(document.createTextNode(__scope.CSS));
|
88
|
+
}
|
64
89
|
|
65
|
-
|
66
|
-
|
67
|
-
summary_element.innerHTML = "Running...";
|
90
|
+
document.getElementsByTagName('head')[0].appendChild(styles);
|
91
|
+
}
|
68
92
|
|
69
|
-
|
70
|
-
|
93
|
+
@start_time = Time.now.to_f
|
94
|
+
@groups_element = `groups_element`
|
95
|
+
@summary_element = `summary_element`
|
96
|
+
end
|
71
97
|
|
72
|
-
|
98
|
+
def finish
|
99
|
+
time = Time.now.to_f - @start_time
|
100
|
+
text = "\n#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
|
101
|
+
`#{@summary_element}.innerHTML = text`
|
102
|
+
end
|
73
103
|
|
74
|
-
|
75
|
-
|
76
|
-
|
104
|
+
def example_group_started group
|
105
|
+
@example_group = group
|
106
|
+
@example_group_failed = false
|
77
107
|
|
78
|
-
|
79
|
-
|
108
|
+
%x{
|
109
|
+
var group_element = document.createElement('li');
|
80
110
|
|
81
|
-
|
82
|
-
|
111
|
+
var description = document.createElement('span');
|
112
|
+
description.className = 'group_description';
|
113
|
+
description.innerHTML = #{group.description.to_s};
|
114
|
+
group_element.appendChild(description);
|
83
115
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
else {
|
88
|
-
styles.appendChild(document.createTextNode(__scope.CSS));
|
89
|
-
}
|
116
|
+
var example_list = document.createElement('ul');
|
117
|
+
example_list.className = 'examples';
|
118
|
+
group_element.appendChild(example_list);
|
90
119
|
|
91
|
-
|
92
|
-
|
120
|
+
#@groups_element.appendChild(group_element);
|
121
|
+
}
|
93
122
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
123
|
+
@group_element = `group_element`
|
124
|
+
@example_list = `example_list`
|
125
|
+
end
|
98
126
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
127
|
+
def example_group_finished group
|
128
|
+
if @example_group_failed
|
129
|
+
`#@group_element.className = 'group failed';`
|
130
|
+
else
|
131
|
+
`#@group_element.className = 'group passed';`
|
103
132
|
end
|
133
|
+
end
|
104
134
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
%x{
|
110
|
-
var group_element = document.createElement('li');
|
111
|
-
|
112
|
-
var description = document.createElement('span');
|
113
|
-
description.className = 'group_description';
|
114
|
-
description.innerHTML = #{group.description.to_s};
|
115
|
-
group_element.appendChild(description);
|
135
|
+
def example_started example
|
136
|
+
@examples << example
|
137
|
+
@example = example
|
138
|
+
end
|
116
139
|
|
117
|
-
|
118
|
-
|
119
|
-
|
140
|
+
def example_failed example
|
141
|
+
@failed_examples << example
|
142
|
+
@example_group_failed = true
|
120
143
|
|
121
|
-
|
122
|
-
}
|
123
|
-
|
124
|
-
@group_element = `group_element`
|
125
|
-
@example_list = `example_list`
|
126
|
-
end
|
144
|
+
exception = example.exception
|
127
145
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
146
|
+
case exception
|
147
|
+
when Spec::ExpectationNotMetError
|
148
|
+
output = exception.message
|
149
|
+
else
|
150
|
+
output = "#{exception.class.name}: #{exception.message}\n"
|
151
|
+
output += " #{exception.backtrace.join "\n "}\n"
|
134
152
|
end
|
135
153
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
def example_failed example
|
142
|
-
@failed_examples << example
|
143
|
-
@example_group_failed = true
|
144
|
-
|
145
|
-
exception = example.exception
|
146
|
-
|
147
|
-
case exception
|
148
|
-
when Opal::Spec::ExpectationNotMetError
|
149
|
-
output = exception.message
|
150
|
-
else
|
151
|
-
output = "#{exception.class.name}: #{exception.message}\n"
|
152
|
-
output += " #{exception.backtrace.join "\n "}\n"
|
153
|
-
end
|
154
|
+
%x{
|
155
|
+
var wrapper = document.createElement('li');
|
156
|
+
wrapper.className = 'example failed';
|
154
157
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
+
var description = document.createElement('span');
|
159
|
+
description.className = 'example_description';
|
160
|
+
description.innerHTML = #{example.description};
|
158
161
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
+
var exception = document.createElement('pre');
|
163
|
+
exception.className = 'exception';
|
164
|
+
exception.innerHTML = output;
|
162
165
|
|
163
|
-
|
164
|
-
|
165
|
-
exception.innerHTML = output;
|
166
|
+
wrapper.appendChild(description);
|
167
|
+
wrapper.appendChild(exception);
|
166
168
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
#@example_list.style.display = 'list-item';
|
172
|
-
}
|
173
|
-
end
|
169
|
+
#@example_list.appendChild(wrapper);
|
170
|
+
#@example_list.style.display = 'list-item';
|
171
|
+
}
|
172
|
+
end
|
174
173
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
174
|
+
def example_passed example
|
175
|
+
%x{
|
176
|
+
var wrapper = document.createElement('li');
|
177
|
+
wrapper.className = 'example passed';
|
179
178
|
|
180
|
-
|
181
|
-
|
182
|
-
|
179
|
+
var description = document.createElement('span');
|
180
|
+
description.className = 'example_description';
|
181
|
+
description.innerHTML = #{example.description};
|
183
182
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
183
|
+
wrapper.appendChild(description);
|
184
|
+
#@example_list.appendChild(wrapper);
|
185
|
+
}
|
186
|
+
end
|
188
187
|
|
189
|
-
|
190
|
-
|
191
|
-
end
|
188
|
+
def example_count
|
189
|
+
@examples.size
|
192
190
|
end
|
193
191
|
end
|
194
192
|
end
|
@@ -1,78 +1,76 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
attr_accessor :asynchronous
|
1
|
+
module Spec
|
2
|
+
class Example
|
3
|
+
attr_reader :description, :example_group, :exception
|
4
|
+
attr_accessor :asynchronous
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
def initialize(group, desc, block)
|
7
|
+
@example_group = group
|
8
|
+
@description = desc
|
9
|
+
@__block__ = block
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
def finish_running
|
13
|
+
if @exception
|
14
|
+
@example_group.example_failed self
|
15
|
+
else
|
16
|
+
@example_group.example_passed self
|
19
17
|
end
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
if @asynchronous
|
33
|
-
# must wait ...
|
34
|
-
else
|
35
|
-
finish_running
|
36
|
-
end
|
20
|
+
def run
|
21
|
+
begin
|
22
|
+
@example_group.example_started self
|
23
|
+
run_before_hooks
|
24
|
+
instance_eval(&@__block__)
|
25
|
+
rescue => e
|
26
|
+
@exception = e
|
27
|
+
ensure
|
28
|
+
run_after_hooks unless @asynchronous
|
37
29
|
end
|
38
30
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
rescue => e
|
45
|
-
@exception = e
|
46
|
-
end
|
31
|
+
if @asynchronous
|
32
|
+
# must wait ...
|
33
|
+
else
|
34
|
+
finish_running
|
47
35
|
end
|
36
|
+
end
|
48
37
|
|
49
|
-
|
50
|
-
|
51
|
-
|
38
|
+
def run_after_hooks
|
39
|
+
begin
|
40
|
+
@example_group.after_hooks.each do |after|
|
41
|
+
instance_eval &after
|
52
42
|
end
|
43
|
+
rescue => e
|
44
|
+
@exception = e
|
53
45
|
end
|
46
|
+
end
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
ensure
|
61
|
-
run_after_hooks
|
62
|
-
end
|
48
|
+
def run_before_hooks
|
49
|
+
@example_group.before_hooks.each do |before|
|
50
|
+
instance_eval &before
|
51
|
+
end
|
52
|
+
end
|
63
53
|
|
64
|
-
|
54
|
+
def run_async(&block)
|
55
|
+
begin
|
56
|
+
block.call
|
57
|
+
rescue => e
|
58
|
+
@exception = e
|
59
|
+
ensure
|
60
|
+
run_after_hooks
|
65
61
|
end
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
63
|
+
finish_running
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_timeout(duration, &block)
|
67
|
+
%x{
|
68
|
+
setTimeout(function() {
|
69
|
+
#{ block.call };
|
70
|
+
}, duration);
|
71
|
+
}
|
73
72
|
|
74
|
-
|
75
|
-
end
|
73
|
+
self
|
76
74
|
end
|
77
75
|
end
|
78
|
-
end
|
76
|
+
end
|