opal-spec 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/README.md +6 -6
- data/Rakefile +24 -6
- data/lib/assets/javascripts/opal/spec/browser_formatter.rb +194 -0
- data/lib/assets/javascripts/opal/spec/example.rb +78 -0
- data/lib/assets/javascripts/opal/spec/example_group.rb +94 -0
- data/lib/assets/javascripts/opal/spec/expectations.rb +55 -0
- data/lib/{opal-spec → assets/javascripts/opal/spec}/kernel.rb +2 -2
- data/lib/assets/javascripts/opal/spec/matchers.rb +106 -0
- data/lib/assets/javascripts/opal/spec/phantom_formatter.rb +93 -0
- data/lib/assets/javascripts/opal/spec/runner.rb +80 -0
- data/lib/{opal-spec → assets/javascripts/opal/spec}/scratch_pad.rb +1 -1
- data/lib/assets/javascripts/opal/spec.rb +13 -0
- data/lib/assets/javascripts/opal-spec.rb +1 -0
- data/lib/opal/spec/runner.rb +12 -0
- data/lib/opal/spec/version.rb +5 -0
- data/lib/opal/spec.rb +9 -0
- data/lib/opal-spec.rb +1 -10
- data/opal-spec.gemspec +4 -4
- data/spec/index.html +1 -4
- data/spec/{test.rb → specs.rb} +5 -2
- data/vendor/runner.js +40 -0
- metadata +20 -15
- data/lib/opal-spec/browser_formatter.rb +0 -192
- data/lib/opal-spec/example.rb +0 -76
- data/lib/opal-spec/example_group.rb +0 -92
- data/lib/opal-spec/expectations.rb +0 -53
- data/lib/opal-spec/matchers.rb +0 -104
- data/lib/opal-spec/phantom_formatter.rb +0 -91
- data/lib/opal-spec/runner.rb +0 -78
- data/lib/opal-spec/version.rb +0 -3
@@ -0,0 +1,80 @@
|
|
1
|
+
module Opal
|
2
|
+
module Spec
|
3
|
+
class Runner
|
4
|
+
def self.in_browser?
|
5
|
+
%x{
|
6
|
+
if (typeof(window) !== 'undefined' && typeof(document) !== 'undefined') {
|
7
|
+
return true;
|
8
|
+
}
|
9
|
+
|
10
|
+
return false;
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.in_phantom?
|
15
|
+
%x{
|
16
|
+
if (typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined') {
|
17
|
+
return true;
|
18
|
+
}
|
19
|
+
|
20
|
+
return false;
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.autorun
|
25
|
+
if in_browser?
|
26
|
+
%x{
|
27
|
+
setTimeout(function() {
|
28
|
+
#{ Runner.new.run };
|
29
|
+
}, 0);
|
30
|
+
}
|
31
|
+
else
|
32
|
+
Runner.new.run
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
if Runner.in_phantom?
|
38
|
+
@formatter = PhantomFormatter.new
|
39
|
+
elsif Runner.in_browser?
|
40
|
+
@formatter = BrowserFormatter.new
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
@groups = ExampleGroup.example_groups.dup
|
46
|
+
@formatter.start
|
47
|
+
run_next_group
|
48
|
+
end
|
49
|
+
|
50
|
+
def run_next_group
|
51
|
+
if @groups.empty?
|
52
|
+
@formatter.finish
|
53
|
+
else
|
54
|
+
@groups.shift.run self
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def example_group_started group
|
59
|
+
@formatter.example_group_started group
|
60
|
+
end
|
61
|
+
|
62
|
+
def example_group_finished group
|
63
|
+
@formatter.example_group_finished group
|
64
|
+
run_next_group
|
65
|
+
end
|
66
|
+
|
67
|
+
def example_started example
|
68
|
+
@formatter.example_started example
|
69
|
+
end
|
70
|
+
|
71
|
+
def example_passed example
|
72
|
+
@formatter.example_passed example
|
73
|
+
end
|
74
|
+
|
75
|
+
def example_failed example
|
76
|
+
@formatter.example_failed example
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#= require opal
|
2
|
+
#= require opal/spec/example
|
3
|
+
#= require opal/spec/example_group
|
4
|
+
#= require opal/spec/matchers
|
5
|
+
#= require opal/spec/runner
|
6
|
+
#= require opal/spec/scratch_pad
|
7
|
+
#= require opal/spec/expectations
|
8
|
+
#= require opal/spec/browser_formatter
|
9
|
+
#= require opal/spec/phantom_formatter
|
10
|
+
#= require opal/spec/kernel
|
11
|
+
|
12
|
+
# Compatibility with older versions
|
13
|
+
OpalSpec = Opal::Spec
|
@@ -0,0 +1 @@
|
|
1
|
+
#= require opal/spec
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Opal
|
2
|
+
module Spec
|
3
|
+
|
4
|
+
# Run tests on the command line using phantomjs. Phantomjs **must** be
|
5
|
+
# installed, and the runner assumes you have an HTML file at
|
6
|
+
# ./spec/index.html which will be run.
|
7
|
+
def self.runner
|
8
|
+
runner = File.join File.dirname(__FILE__), '..', '..', '..', 'vendor', 'runner.js'
|
9
|
+
system "phantomjs #{runner} spec/index.html"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/opal/spec.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'opal'
|
2
|
+
require 'opal/spec/runner'
|
3
|
+
require 'opal/spec/version'
|
4
|
+
|
5
|
+
# Compatibility with old namespace
|
6
|
+
OpalSpec = Opal::Spec
|
7
|
+
|
8
|
+
# Just register our opal code path with opal build tools
|
9
|
+
Opal.append_path File.join(File.dirname(__FILE__), '..', 'assets', 'javascripts')
|
data/lib/opal-spec.rb
CHANGED
@@ -1,10 +1 @@
|
|
1
|
-
require 'opal
|
2
|
-
require 'opal-spec/example_group'
|
3
|
-
require 'opal-spec/matchers'
|
4
|
-
require 'opal-spec/runner'
|
5
|
-
require 'opal-spec/scratch_pad'
|
6
|
-
require 'opal-spec/expectations'
|
7
|
-
require 'opal-spec/browser_formatter'
|
8
|
-
require 'opal-spec/phantom_formatter'
|
9
|
-
require 'opal-spec/kernel'
|
10
|
-
require 'opal-spec/version'
|
1
|
+
require 'opal/spec'
|
data/opal-spec.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/opal
|
2
|
+
require File.expand_path('../lib/opal/spec/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'opal-spec'
|
6
|
-
s.version =
|
6
|
+
s.version = Opal::Spec::VERSION
|
7
7
|
s.author = 'Adam Beynon'
|
8
|
-
s.email = 'adam@
|
8
|
+
s.email = 'adam.beynon@gmail.com'
|
9
9
|
s.homepage = 'http://opalrb.org'
|
10
10
|
s.summary = 'Opal compatible spec'
|
11
11
|
s.description = 'Opal compatible spec library'
|
12
12
|
|
13
13
|
s.files = `git ls-files`.split("\n")
|
14
14
|
s.require_paths = ['lib']
|
15
|
-
end
|
15
|
+
end
|
data/spec/index.html
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
|
-
|
3
2
|
<html>
|
4
3
|
<head>
|
5
|
-
<title>opal-spec
|
4
|
+
<title>opal-spec specs</title>
|
6
5
|
</head>
|
7
6
|
<body>
|
8
|
-
<script src="../build/opal.js"></script>
|
9
|
-
<script src="../build/opal-spec.js"></script>
|
10
7
|
<script src="../build/specs.js"></script>
|
11
8
|
</body>
|
12
9
|
</html>
|
data/spec/{test.rb → specs.rb}
RENAMED
@@ -1,3 +1,6 @@
|
|
1
|
+
#= require opal
|
2
|
+
#= require opal-spec
|
3
|
+
|
1
4
|
@passed = 0
|
2
5
|
@failures = []
|
3
6
|
|
@@ -68,6 +71,6 @@ describe 'Another group' do
|
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
|
-
|
74
|
+
Opal::Spec::Runner.autorun
|
72
75
|
|
73
|
-
puts "Assertions: #{@passed + @failures.length}, Passed: #{@passed}, Failures: #{@failures.length}"
|
76
|
+
puts "Assertions: #{@passed + @failures.length}, Passed: #{@passed}, Failures: #{@failures.length}"
|
data/vendor/runner.js
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
* Test runner for phantomjs
|
3
|
+
*/
|
4
|
+
var args = phantom.args;
|
5
|
+
var page = require('webpage').create();
|
6
|
+
|
7
|
+
page.onConsoleMessage = function(msg) {
|
8
|
+
console.log(msg);
|
9
|
+
};
|
10
|
+
|
11
|
+
page.onInitialized = function() {
|
12
|
+
page.evaluate(function () {
|
13
|
+
window.OPAL_SPEC_PHANTOM = true;
|
14
|
+
});
|
15
|
+
};
|
16
|
+
|
17
|
+
page.open(args[0], function(status) {
|
18
|
+
if (status !== 'success') {
|
19
|
+
console.error("Cannot load: " + args[0]);
|
20
|
+
phantom.exit(1);
|
21
|
+
} else {
|
22
|
+
var timeout = parseInt(args[1] || 60000, 10);
|
23
|
+
var start = Date.now();
|
24
|
+
var interval = setInterval(function() {
|
25
|
+
if (Date.now() > start + timeout) {
|
26
|
+
console.error("Specs timed out");
|
27
|
+
phantom.exit(124);
|
28
|
+
} else {
|
29
|
+
var code = page.evaluate(function() {
|
30
|
+
return window.OPAL_SPEC_CODE;
|
31
|
+
});
|
32
|
+
|
33
|
+
if (code === 0 || code === 1) {
|
34
|
+
clearInterval(interval);
|
35
|
+
phantom.exit(code);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}, 500);
|
39
|
+
}
|
40
|
+
});
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-05 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Opal compatible spec library
|
15
|
-
email: adam@
|
15
|
+
email: adam.beynon@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
@@ -21,20 +21,25 @@ files:
|
|
21
21
|
- Gemfile
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
24
|
+
- lib/assets/javascripts/opal-spec.rb
|
25
|
+
- lib/assets/javascripts/opal/spec.rb
|
26
|
+
- lib/assets/javascripts/opal/spec/browser_formatter.rb
|
27
|
+
- lib/assets/javascripts/opal/spec/example.rb
|
28
|
+
- lib/assets/javascripts/opal/spec/example_group.rb
|
29
|
+
- lib/assets/javascripts/opal/spec/expectations.rb
|
30
|
+
- lib/assets/javascripts/opal/spec/kernel.rb
|
31
|
+
- lib/assets/javascripts/opal/spec/matchers.rb
|
32
|
+
- lib/assets/javascripts/opal/spec/phantom_formatter.rb
|
33
|
+
- lib/assets/javascripts/opal/spec/runner.rb
|
34
|
+
- lib/assets/javascripts/opal/spec/scratch_pad.rb
|
24
35
|
- lib/opal-spec.rb
|
25
|
-
- lib/opal
|
26
|
-
- lib/opal
|
27
|
-
- lib/opal
|
28
|
-
- lib/opal-spec/expectations.rb
|
29
|
-
- lib/opal-spec/kernel.rb
|
30
|
-
- lib/opal-spec/matchers.rb
|
31
|
-
- lib/opal-spec/phantom_formatter.rb
|
32
|
-
- lib/opal-spec/runner.rb
|
33
|
-
- lib/opal-spec/scratch_pad.rb
|
34
|
-
- lib/opal-spec/version.rb
|
36
|
+
- lib/opal/spec.rb
|
37
|
+
- lib/opal/spec/runner.rb
|
38
|
+
- lib/opal/spec/version.rb
|
35
39
|
- opal-spec.gemspec
|
36
40
|
- spec/index.html
|
37
|
-
- spec/
|
41
|
+
- spec/specs.rb
|
42
|
+
- vendor/runner.js
|
38
43
|
homepage: http://opalrb.org
|
39
44
|
licenses: []
|
40
45
|
post_install_message:
|
@@ -55,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
60
|
version: '0'
|
56
61
|
requirements: []
|
57
62
|
rubyforge_project:
|
58
|
-
rubygems_version: 1.8.
|
63
|
+
rubygems_version: 1.8.11
|
59
64
|
signing_key:
|
60
65
|
specification_version: 3
|
61
66
|
summary: Opal compatible spec
|
@@ -1,192 +0,0 @@
|
|
1
|
-
module OpalSpec
|
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
|
57
|
-
|
58
|
-
def start
|
59
|
-
%x{
|
60
|
-
if (!document || !document.body) {
|
61
|
-
#{ raise "Not running in browser." };
|
62
|
-
}
|
63
|
-
|
64
|
-
var summary_element = document.createElement('p');
|
65
|
-
summary_element.className = 'summary';
|
66
|
-
summary_element.innerHTML = "Running...";
|
67
|
-
|
68
|
-
var groups_element = document.createElement('ul');
|
69
|
-
groups_element.className = 'example_groups';
|
70
|
-
|
71
|
-
var target = document.getElementById('opal-spec-output');
|
72
|
-
|
73
|
-
if (!target) {
|
74
|
-
target = document.body;
|
75
|
-
}
|
76
|
-
|
77
|
-
target.appendChild(summary_element);
|
78
|
-
target.appendChild(groups_element);
|
79
|
-
|
80
|
-
var styles = document.createElement('style');
|
81
|
-
styles.type = 'text/css';
|
82
|
-
|
83
|
-
if (styles.styleSheet) {
|
84
|
-
styles.styleSheet.cssText = __scope.CSS;
|
85
|
-
}
|
86
|
-
else {
|
87
|
-
styles.appendChild(document.createTextNode(__scope.CSS));
|
88
|
-
}
|
89
|
-
|
90
|
-
document.getElementsByTagName('head')[0].appendChild(styles);
|
91
|
-
}
|
92
|
-
|
93
|
-
@start_time = Time.now.to_f
|
94
|
-
@groups_element = `groups_element`
|
95
|
-
@summary_element = `summary_element`
|
96
|
-
end
|
97
|
-
|
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
|
103
|
-
|
104
|
-
def example_group_started group
|
105
|
-
@example_group = group
|
106
|
-
@example_group_failed = false
|
107
|
-
|
108
|
-
%x{
|
109
|
-
var group_element = document.createElement('li');
|
110
|
-
|
111
|
-
var description = document.createElement('span');
|
112
|
-
description.className = 'group_description';
|
113
|
-
description.innerHTML = #{group.description.to_s};
|
114
|
-
group_element.appendChild(description);
|
115
|
-
|
116
|
-
var example_list = document.createElement('ul');
|
117
|
-
example_list.className = 'examples';
|
118
|
-
group_element.appendChild(example_list);
|
119
|
-
|
120
|
-
#@groups_element.appendChild(group_element);
|
121
|
-
}
|
122
|
-
|
123
|
-
@group_element = `group_element`
|
124
|
-
@example_list = `example_list`
|
125
|
-
end
|
126
|
-
|
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';`
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def example_started example
|
136
|
-
@examples << example
|
137
|
-
@example = example
|
138
|
-
end
|
139
|
-
|
140
|
-
def example_failed example
|
141
|
-
@failed_examples << example
|
142
|
-
@example_group_failed = true
|
143
|
-
|
144
|
-
exception = example.exception
|
145
|
-
|
146
|
-
case exception
|
147
|
-
when OpalSpec::ExpectationNotMetError
|
148
|
-
output = exception.message
|
149
|
-
else
|
150
|
-
output = "#{exception.class.name}: #{exception.message}\n"
|
151
|
-
output += " #{exception.backtrace.join "\n "}\n"
|
152
|
-
end
|
153
|
-
|
154
|
-
%x{
|
155
|
-
var wrapper = document.createElement('li');
|
156
|
-
wrapper.className = 'example failed';
|
157
|
-
|
158
|
-
var description = document.createElement('span');
|
159
|
-
description.className = 'example_description';
|
160
|
-
description.innerHTML = #{example.description};
|
161
|
-
|
162
|
-
var exception = document.createElement('pre');
|
163
|
-
exception.className = 'exception';
|
164
|
-
exception.innerHTML = output;
|
165
|
-
|
166
|
-
wrapper.appendChild(description);
|
167
|
-
wrapper.appendChild(exception);
|
168
|
-
|
169
|
-
#@example_list.appendChild(wrapper);
|
170
|
-
#@example_list.style.display = 'list-item';
|
171
|
-
}
|
172
|
-
end
|
173
|
-
|
174
|
-
def example_passed example
|
175
|
-
%x{
|
176
|
-
var wrapper = document.createElement('li');
|
177
|
-
wrapper.className = 'example passed';
|
178
|
-
|
179
|
-
var description = document.createElement('span');
|
180
|
-
description.className = 'example_description';
|
181
|
-
description.innerHTML = #{example.description};
|
182
|
-
|
183
|
-
wrapper.appendChild(description);
|
184
|
-
#@example_list.appendChild(wrapper);
|
185
|
-
}
|
186
|
-
end
|
187
|
-
|
188
|
-
def example_count
|
189
|
-
@examples.size
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
data/lib/opal-spec/example.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
module OpalSpec
|
2
|
-
class Example
|
3
|
-
attr_reader :description, :example_group, :exception
|
4
|
-
attr_accessor :asynchronous
|
5
|
-
|
6
|
-
def initialize(group, desc, block)
|
7
|
-
@example_group = group
|
8
|
-
@description = desc
|
9
|
-
@__block__ = block
|
10
|
-
end
|
11
|
-
|
12
|
-
def finish_running
|
13
|
-
if @exception
|
14
|
-
@example_group.example_failed self
|
15
|
-
else
|
16
|
-
@example_group.example_passed self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
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
|
29
|
-
end
|
30
|
-
|
31
|
-
if @asynchronous
|
32
|
-
# must wait ...
|
33
|
-
else
|
34
|
-
finish_running
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def run_after_hooks
|
39
|
-
begin
|
40
|
-
@example_group.after_hooks.each do |after|
|
41
|
-
instance_eval &after
|
42
|
-
end
|
43
|
-
rescue => e
|
44
|
-
@exception = e
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def run_before_hooks
|
49
|
-
@example_group.before_hooks.each do |before|
|
50
|
-
instance_eval &before
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def run_async(&block)
|
55
|
-
begin
|
56
|
-
block.call
|
57
|
-
rescue => e
|
58
|
-
@exception = e
|
59
|
-
ensure
|
60
|
-
run_after_hooks
|
61
|
-
end
|
62
|
-
|
63
|
-
finish_running
|
64
|
-
end
|
65
|
-
|
66
|
-
def set_timeout(duration, &block)
|
67
|
-
%x{
|
68
|
-
setTimeout(function() {
|
69
|
-
#{ block.call };
|
70
|
-
}, duration);
|
71
|
-
}
|
72
|
-
|
73
|
-
self
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
module OpalSpec
|
2
|
-
class ExampleGroup
|
3
|
-
@example_groups = []
|
4
|
-
def self.example_groups
|
5
|
-
@example_groups
|
6
|
-
end
|
7
|
-
|
8
|
-
@stack = []
|
9
|
-
def self.create desc, block
|
10
|
-
group = self.new desc, @stack.last
|
11
|
-
@example_groups << group
|
12
|
-
|
13
|
-
@stack << group
|
14
|
-
group.instance_eval &block
|
15
|
-
@stack.pop
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize desc, parent
|
19
|
-
@desc = desc.to_s
|
20
|
-
@parent = parent
|
21
|
-
@examples = []
|
22
|
-
|
23
|
-
@before_hooks = []
|
24
|
-
@after_hooks = []
|
25
|
-
end
|
26
|
-
|
27
|
-
def it(desc, &block)
|
28
|
-
@examples << Example.new(self, desc, block)
|
29
|
-
end
|
30
|
-
|
31
|
-
def async(desc, &block)
|
32
|
-
example = Example.new(self, desc, block)
|
33
|
-
example.asynchronous = true
|
34
|
-
@examples << example
|
35
|
-
end
|
36
|
-
|
37
|
-
def it_behaves_like(*objs)
|
38
|
-
end
|
39
|
-
|
40
|
-
def before type = :each, &block
|
41
|
-
raise "unsupported before type: #{type}" unless type == :each
|
42
|
-
@before_hooks << block
|
43
|
-
end
|
44
|
-
|
45
|
-
def after type = :each, &block
|
46
|
-
raise "unsupported after type: #{type}" unless type == :each
|
47
|
-
@after_hooks << block
|
48
|
-
end
|
49
|
-
|
50
|
-
def before_hooks
|
51
|
-
@parent ? [].concat(@parent.before_hooks).concat(@before_hooks) : @before_hooks
|
52
|
-
end
|
53
|
-
|
54
|
-
def after_hooks
|
55
|
-
@parent ? [].concat(@parent.after_hooks).concat(@after_hooks) : @after_hooks
|
56
|
-
end
|
57
|
-
|
58
|
-
def run(runner)
|
59
|
-
@runner = runner
|
60
|
-
@runner.example_group_started self
|
61
|
-
|
62
|
-
@running_examples = @examples.dup
|
63
|
-
run_next_example
|
64
|
-
end
|
65
|
-
|
66
|
-
def run_next_example
|
67
|
-
if @running_examples.empty?
|
68
|
-
@runner.example_group_finished self
|
69
|
-
else
|
70
|
-
@running_examples.shift.run
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def example_started(example)
|
75
|
-
@runner.example_started(example)
|
76
|
-
end
|
77
|
-
|
78
|
-
def example_passed(example)
|
79
|
-
@runner.example_passed(example)
|
80
|
-
run_next_example
|
81
|
-
end
|
82
|
-
|
83
|
-
def example_failed(example)
|
84
|
-
@runner.example_failed(example)
|
85
|
-
run_next_example
|
86
|
-
end
|
87
|
-
|
88
|
-
def description
|
89
|
-
@parent ? "#{@parent.description} #{@desc}" : @desc
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|