opal-spec 0.1.15 → 0.2.0
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/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/opal-spec/browser_formatter.rb +183 -0
- data/lib/{opal/spec → opal-spec}/example.rb +1 -1
- data/lib/{opal/spec → opal-spec}/example_group.rb +1 -1
- data/lib/{opal/spec → opal-spec}/expectations.rb +10 -10
- data/lib/{opal/spec → opal-spec}/kernel.rb +1 -1
- data/lib/{opal/spec → opal-spec}/matchers.rb +2 -2
- data/lib/opal-spec/phantom_formatter.rb +78 -0
- data/lib/opal-spec/runner.rb +70 -0
- data/lib/{opal/spec → opal-spec}/scratch_pad.rb +0 -0
- data/lib/opal-spec/version.rb +3 -0
- data/lib/opal-spec.rb +10 -0
- data/opal-spec.gemspec +2 -2
- metadata +14 -20
- data/example/bar.rb +0 -27
- data/example/before.rb +0 -19
- data/example/foo.rb +0 -39
- data/example/groups.rb +0 -11
- data/example/nested.rb +0 -11
- data/example/runner.html +0 -16
- data/example/spec_helper.rb +0 -5
- data/lib/opal/spec/browser_formatter.rb +0 -149
- data/lib/opal/spec/runner.rb +0 -34
- data/lib/opal/spec/version.rb +0 -3
- data/lib/opal/spec.rb +0 -9
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
gem "opal", :
|
1
|
+
gem "opal", :git => 'git://github/opal/opal.git'
|
2
2
|
gem "rake"
|
data/README.md
CHANGED
@@ -0,0 +1,183 @@
|
|
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
|
+
|
67
|
+
var groups_element = document.createElement('ul');
|
68
|
+
groups_element.className = 'example_groups';
|
69
|
+
|
70
|
+
var target = document.getElementById('opal-spec-output');
|
71
|
+
|
72
|
+
if (!target) {
|
73
|
+
target = document.body;
|
74
|
+
}
|
75
|
+
|
76
|
+
target.appendChild(summary_element);
|
77
|
+
target.appendChild(groups_element);
|
78
|
+
|
79
|
+
var styles = document.createElement('style');
|
80
|
+
styles.innerHTML = #{ CSS };
|
81
|
+
document.head.appendChild(styles);
|
82
|
+
}
|
83
|
+
|
84
|
+
@start_time = Time.now.to_f
|
85
|
+
@groups_element = `groups_element`
|
86
|
+
@summary_element = `summary_element`
|
87
|
+
end
|
88
|
+
|
89
|
+
def finish
|
90
|
+
time = Time.now.to_f - @start_time
|
91
|
+
text = "\n#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
|
92
|
+
`#{@summary_element}.innerHTML = text`
|
93
|
+
end
|
94
|
+
|
95
|
+
def example_group_started group
|
96
|
+
@example_group = group
|
97
|
+
@example_group_failed = false
|
98
|
+
|
99
|
+
%x{
|
100
|
+
var group_element = document.createElement('li');
|
101
|
+
|
102
|
+
var description = document.createElement('span');
|
103
|
+
description.className = 'group_description';
|
104
|
+
description.innerHTML = #{group.description};
|
105
|
+
group_element.appendChild(description);
|
106
|
+
|
107
|
+
var example_list = document.createElement('ul');
|
108
|
+
example_list.className = 'examples';
|
109
|
+
group_element.appendChild(example_list);
|
110
|
+
|
111
|
+
#@groups_element.appendChild(group_element);
|
112
|
+
}
|
113
|
+
|
114
|
+
@group_element = `group_element`
|
115
|
+
@example_list = `example_list`
|
116
|
+
end
|
117
|
+
|
118
|
+
def example_group_finished group
|
119
|
+
if @example_group_failed
|
120
|
+
`#@group_element.className = 'group failed';`
|
121
|
+
else
|
122
|
+
`#@group_element.className = 'group passed';`
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def example_started example
|
127
|
+
@examples << example
|
128
|
+
@example = example
|
129
|
+
end
|
130
|
+
|
131
|
+
def example_failed example
|
132
|
+
@failed_examples << example
|
133
|
+
@example_group_failed = true
|
134
|
+
|
135
|
+
exception = example.exception
|
136
|
+
|
137
|
+
case exception
|
138
|
+
when OpalSpec::ExpectationNotMetError
|
139
|
+
output = exception.message
|
140
|
+
else
|
141
|
+
output = "#{exception.class}: #{exception.message}\n"
|
142
|
+
output += " #{exception.backtrace.join "\n "}\n"
|
143
|
+
end
|
144
|
+
|
145
|
+
%x{
|
146
|
+
var wrapper = document.createElement('li');
|
147
|
+
wrapper.className = 'example failed';
|
148
|
+
|
149
|
+
var description = document.createElement('span');
|
150
|
+
description.className = 'example_description';
|
151
|
+
description.innerHTML = #{example.description};
|
152
|
+
|
153
|
+
var exception = document.createElement('pre');
|
154
|
+
exception.className = 'exception';
|
155
|
+
exception.innerHTML = output;
|
156
|
+
|
157
|
+
wrapper.appendChild(description);
|
158
|
+
wrapper.appendChild(exception);
|
159
|
+
|
160
|
+
#@example_list.appendChild(wrapper);
|
161
|
+
#@example_list.style.display = 'list-item';
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
def example_passed example
|
166
|
+
%x{
|
167
|
+
var wrapper = document.createElement('li');
|
168
|
+
wrapper.className = 'example passed';
|
169
|
+
|
170
|
+
var description = document.createElement('span');
|
171
|
+
description.className = 'example_description';
|
172
|
+
description.innerHTML = #{example.description};
|
173
|
+
|
174
|
+
wrapper.appendChild(description);
|
175
|
+
#@example_list.appendChild(wrapper);
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
def example_count
|
180
|
+
@examples.size
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module OpalSpec
|
2
2
|
class ExpectationNotMetError < StandardError; end
|
3
3
|
|
4
4
|
module Expectations
|
@@ -6,7 +6,7 @@ module Spec
|
|
6
6
|
if matcher
|
7
7
|
matcher.match self
|
8
8
|
else
|
9
|
-
|
9
|
+
OpalSpec::PositiveOperatorMatcher.new self
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -14,36 +14,36 @@ module Spec
|
|
14
14
|
if matcher
|
15
15
|
matcher.not_match self
|
16
16
|
else
|
17
|
-
|
17
|
+
OpalSpec::NegativeOperatorMatcher.new self
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def be_kind_of expected
|
22
|
-
|
22
|
+
OpalSpec::BeKindOfMatcher.new expected
|
23
23
|
end
|
24
24
|
|
25
25
|
def be_nil
|
26
|
-
|
26
|
+
OpalSpec::BeNilMatcher.new nil
|
27
27
|
end
|
28
28
|
|
29
29
|
def be_true
|
30
|
-
|
30
|
+
OpalSpec::BeTrueMatcher.new true
|
31
31
|
end
|
32
32
|
|
33
33
|
def be_false
|
34
|
-
|
34
|
+
OpalSpec::BeFalseMatcher.new false
|
35
35
|
end
|
36
36
|
|
37
37
|
def equal expected
|
38
|
-
|
38
|
+
OpalSpec::EqualMatcher.new expected
|
39
39
|
end
|
40
40
|
|
41
41
|
def raise_error expected
|
42
|
-
|
42
|
+
OpalSpec::RaiseErrorMatcher.new expected
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
class Object
|
48
|
-
include
|
48
|
+
include OpalSpec::Expectations
|
49
49
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module OpalSpec
|
2
|
+
class PhantomFormatter
|
3
|
+
def initialize
|
4
|
+
@examples = []
|
5
|
+
@failed_examples = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def log_green(str)
|
9
|
+
`console.log('\\033[92m' + str + '\\033[0m')`
|
10
|
+
end
|
11
|
+
|
12
|
+
def log_red(str)
|
13
|
+
`console.log('\\033[31m' + str + '\\033[0m')`
|
14
|
+
end
|
15
|
+
|
16
|
+
def log(str)
|
17
|
+
`console.log(str)`
|
18
|
+
end
|
19
|
+
|
20
|
+
def start
|
21
|
+
end
|
22
|
+
|
23
|
+
def finish
|
24
|
+
if @failed_examples.empty?
|
25
|
+
log "\nFinished"
|
26
|
+
log_green "#{example_count} examples, 0 failures"
|
27
|
+
`phantom.exit(0)`
|
28
|
+
else
|
29
|
+
log "\nFailures:"
|
30
|
+
@failed_examples.each_with_index do |example, idx|
|
31
|
+
log "\n #{idx+1}. #{example.example_group.description} #{example.description}"
|
32
|
+
|
33
|
+
exception = example.exception
|
34
|
+
case exception
|
35
|
+
when OpalSpec::ExpectationNotMetError
|
36
|
+
output = exception.message
|
37
|
+
else
|
38
|
+
output = "#{exception.class}: #{exception.message}\n"
|
39
|
+
output += " #{exception.backtrace.join "\n "}\n"
|
40
|
+
end
|
41
|
+
log_red " #{output}"
|
42
|
+
end
|
43
|
+
|
44
|
+
log "\nFinished"
|
45
|
+
log_red "#{example_count} examples, #{@failed_examples.size} failures"
|
46
|
+
`phantom.exit(1)`
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def example_group_started group
|
51
|
+
@example_group = group
|
52
|
+
@example_group_failed = false
|
53
|
+
log "\n#{group.description}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def example_group_finished group
|
57
|
+
end
|
58
|
+
|
59
|
+
def example_started example
|
60
|
+
@examples << example
|
61
|
+
@example = example
|
62
|
+
end
|
63
|
+
|
64
|
+
def example_failed example
|
65
|
+
@failed_examples << example
|
66
|
+
@example_group_failed = true
|
67
|
+
log_red " #{example.description}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def example_passed example
|
71
|
+
log_green " #{example.description}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def example_count
|
75
|
+
@examples.size
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module OpalSpec
|
2
|
+
class Runner
|
3
|
+
def self.in_browser?
|
4
|
+
%x{
|
5
|
+
if (typeof(window) !== 'undefined' && typeof(document) !== 'undefined') {
|
6
|
+
return true;
|
7
|
+
}
|
8
|
+
|
9
|
+
return false;
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.in_phantom?
|
14
|
+
%x{
|
15
|
+
if (typeof(phantom) !== 'undefined' && phantom.exit) {
|
16
|
+
return true;
|
17
|
+
}
|
18
|
+
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.autorun
|
24
|
+
if in_browser?
|
25
|
+
%x{
|
26
|
+
setTimeout(function() {
|
27
|
+
#{ Runner.new.run };
|
28
|
+
}, 0);
|
29
|
+
}
|
30
|
+
else
|
31
|
+
Runner.new.run
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
if Runner.in_phantom?
|
37
|
+
@formatter = PhantomFormatter.new
|
38
|
+
elsif Runner.in_browser?
|
39
|
+
@formatter = BrowserFormatter.new
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def run
|
44
|
+
groups = ExampleGroup.example_groups
|
45
|
+
@formatter.start
|
46
|
+
groups.each { |group| group.run self }
|
47
|
+
@formatter.finish
|
48
|
+
end
|
49
|
+
|
50
|
+
def example_group_started group
|
51
|
+
@formatter.example_group_started group
|
52
|
+
end
|
53
|
+
|
54
|
+
def example_group_finished group
|
55
|
+
@formatter.example_group_finished group
|
56
|
+
end
|
57
|
+
|
58
|
+
def example_started example
|
59
|
+
@formatter.example_started example
|
60
|
+
end
|
61
|
+
|
62
|
+
def example_passed example
|
63
|
+
@formatter.example_passed example
|
64
|
+
end
|
65
|
+
|
66
|
+
def example_failed example
|
67
|
+
@formatter.example_failed example
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
File without changes
|
data/lib/opal-spec.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'opal-spec/example'
|
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'
|
data/opal-spec.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
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 = OpalSpec::VERSION
|
7
7
|
s.author = 'Adam Beynon'
|
8
8
|
s.email = 'adam@adambeynon.com'
|
9
9
|
s.homepage = 'http://opalrb.org'
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-11 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Opal compatible spec library
|
15
15
|
email: adam@adambeynon.com
|
@@ -21,23 +21,17 @@ files:
|
|
21
21
|
- Gemfile
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
24
|
-
-
|
25
|
-
-
|
26
|
-
- example
|
27
|
-
-
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
- lib/opal/
|
32
|
-
- lib/opal
|
33
|
-
- lib/opal
|
34
|
-
- lib/opal
|
35
|
-
- lib/opal/spec/expectations.rb
|
36
|
-
- lib/opal/spec/kernel.rb
|
37
|
-
- lib/opal/spec/matchers.rb
|
38
|
-
- lib/opal/spec/runner.rb
|
39
|
-
- lib/opal/spec/scratch_pad.rb
|
40
|
-
- lib/opal/spec/version.rb
|
24
|
+
- lib/opal-spec.rb
|
25
|
+
- lib/opal-spec/browser_formatter.rb
|
26
|
+
- lib/opal-spec/example.rb
|
27
|
+
- lib/opal-spec/example_group.rb
|
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
|
41
35
|
- opal-spec.gemspec
|
42
36
|
homepage: http://opalrb.org
|
43
37
|
licenses: []
|
@@ -59,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
53
|
version: '0'
|
60
54
|
requirements: []
|
61
55
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.8.
|
56
|
+
rubygems_version: 1.8.11
|
63
57
|
signing_key:
|
64
58
|
specification_version: 3
|
65
59
|
summary: Opal compatible spec
|
data/example/bar.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
describe "All these tests will pass" do
|
2
|
-
it "some simple expectations" do
|
3
|
-
1.should == 1
|
4
|
-
2.should == 2
|
5
|
-
|
6
|
-
[1, 2, 3].should == [1, 2, 3]
|
7
|
-
[].should == []
|
8
|
-
|
9
|
-
"foo".should == "foo"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "some simple negative expectations" do
|
13
|
-
1.should_not == 2
|
14
|
-
3.should_not == 1
|
15
|
-
|
16
|
-
[1, 2, 3].should_not == [1, 2, 3, 4]
|
17
|
-
[].should_not == [1]
|
18
|
-
|
19
|
-
"foo".should_not == "bar"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should raise exceptions" do
|
23
|
-
lambda {
|
24
|
-
raise "foo"
|
25
|
-
}.should raise_error(Exception)
|
26
|
-
end
|
27
|
-
end
|
data/example/before.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
describe "Outer before" do
|
2
|
-
before do
|
3
|
-
@foo = "foo_ran"
|
4
|
-
end
|
5
|
-
|
6
|
-
describe "with an inner before" do
|
7
|
-
before do
|
8
|
-
@bah = "bah_ran"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should get the outer before hooks run" do
|
12
|
-
@foo.should == "foo_ran"
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should still run inner befores" do
|
16
|
-
@bah.should == "bah_ran"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/example/foo.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
describe "All these tests will fail" do
|
2
|
-
it "some simple expectations" do
|
3
|
-
1.should == 2
|
4
|
-
end
|
5
|
-
|
6
|
-
it "some array comparisons" do
|
7
|
-
[1, 2, 3].should == nil
|
8
|
-
end
|
9
|
-
|
10
|
-
it "be_kind_of expectations" do
|
11
|
-
1.should be_kind_of String
|
12
|
-
end
|
13
|
-
|
14
|
-
it "be_nil expectation" do
|
15
|
-
[].should be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it "be_true expectation" do
|
19
|
-
false.should be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "be_false expectation" do
|
23
|
-
true.should be_false
|
24
|
-
end
|
25
|
-
|
26
|
-
it "equal expectation" do
|
27
|
-
Object.new.should equal(Object.new)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "raise_error expectation" do
|
31
|
-
lambda {
|
32
|
-
"dont raise"
|
33
|
-
}.should raise_error(Exception)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "can use backtraces when available" do
|
37
|
-
something.should.fail.as.all.these.methods.dont.exist
|
38
|
-
end
|
39
|
-
end
|
data/example/groups.rb
DELETED
data/example/nested.rb
DELETED
data/example/runner.html
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
5
|
-
|
6
|
-
<title>Opal Spec Runner</title>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
<script src="../opal.debug.js"></script>
|
10
|
-
<script src="../opal-spec.debug.js"></script>
|
11
|
-
<script src="../example.debug.js"></script>
|
12
|
-
<script>
|
13
|
-
opal.main('example/spec_helper');
|
14
|
-
</script>
|
15
|
-
</body>
|
16
|
-
</html>
|
data/example/spec_helper.rb
DELETED
@@ -1,149 +0,0 @@
|
|
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
|
57
|
-
|
58
|
-
def start
|
59
|
-
@summary_element = Element.new '<p class="summary"></p>'
|
60
|
-
@summary_element.append_to_body
|
61
|
-
|
62
|
-
@groups_element = Element.new '<ul class="example_groups"></ul>'
|
63
|
-
@groups_element.append_to_body
|
64
|
-
|
65
|
-
Element.new("<style>#{ CSS }</style>").append_to_head
|
66
|
-
end
|
67
|
-
|
68
|
-
def finish
|
69
|
-
text = "\n#{example_count} examples, #{@failed_examples.size} failures"
|
70
|
-
@summary_element.html = text
|
71
|
-
end
|
72
|
-
|
73
|
-
def example_group_started group
|
74
|
-
@example_group = group
|
75
|
-
@example_group_failed = false
|
76
|
-
|
77
|
-
@group_element = Element.new <<-HTML
|
78
|
-
<li>
|
79
|
-
<span class="group_description">
|
80
|
-
#{ group.description }
|
81
|
-
</span>
|
82
|
-
</li>
|
83
|
-
HTML
|
84
|
-
|
85
|
-
@example_list = Element.new <<-HTML
|
86
|
-
<ul class="examples"></ul>
|
87
|
-
HTML
|
88
|
-
|
89
|
-
@group_element << @example_list
|
90
|
-
@groups_element << @group_element
|
91
|
-
end
|
92
|
-
|
93
|
-
def example_group_finished group
|
94
|
-
if @example_group_failed
|
95
|
-
@group_element.class_name = 'group failed'
|
96
|
-
else
|
97
|
-
@group_element.class_name = 'group passed'
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def example_started example
|
102
|
-
@examples << example
|
103
|
-
@example = example
|
104
|
-
end
|
105
|
-
|
106
|
-
def example_failed example
|
107
|
-
@failed_examples << example
|
108
|
-
@example_group_failed = true
|
109
|
-
|
110
|
-
exception = example.exception
|
111
|
-
|
112
|
-
case exception
|
113
|
-
when Spec::ExpectationNotMetError
|
114
|
-
output = exception.message
|
115
|
-
else
|
116
|
-
output = "#{exception.class.name}: #{exception.message}\n"
|
117
|
-
output += " #{exception.backtrace.join "\n "}\n"
|
118
|
-
end
|
119
|
-
|
120
|
-
wrapper = Element.new('<li class="example failed"></li>')
|
121
|
-
|
122
|
-
description = Element.new('<span class="example_description"></span>')
|
123
|
-
description.text = example.description
|
124
|
-
|
125
|
-
exception = Element.new('<pre class="exception"></pre>')
|
126
|
-
exception.text = output
|
127
|
-
|
128
|
-
wrapper << description
|
129
|
-
wrapper << exception
|
130
|
-
|
131
|
-
@example_list.append wrapper
|
132
|
-
@example_list.css 'display', 'list-item'
|
133
|
-
end
|
134
|
-
|
135
|
-
def example_passed example
|
136
|
-
out = Element.new <<-HTML
|
137
|
-
<li class="example passed">
|
138
|
-
<span class="example_description">#{ example.description }</span>
|
139
|
-
</li>
|
140
|
-
HTML
|
141
|
-
|
142
|
-
@example_list.append out
|
143
|
-
end
|
144
|
-
|
145
|
-
def example_count
|
146
|
-
@examples.size
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
data/lib/opal/spec/runner.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Spec
|
2
|
-
class Runner
|
3
|
-
def initialize
|
4
|
-
@formatter = BrowserFormatter.new
|
5
|
-
end
|
6
|
-
|
7
|
-
def run
|
8
|
-
groups = ExampleGroup.example_groups
|
9
|
-
@formatter.start
|
10
|
-
groups.each { |group| group.run self }
|
11
|
-
@formatter.finish
|
12
|
-
end
|
13
|
-
|
14
|
-
def example_group_started group
|
15
|
-
@formatter.example_group_started group
|
16
|
-
end
|
17
|
-
|
18
|
-
def example_group_finished group
|
19
|
-
@formatter.example_group_finished group
|
20
|
-
end
|
21
|
-
|
22
|
-
def example_started example
|
23
|
-
@formatter.example_started example
|
24
|
-
end
|
25
|
-
|
26
|
-
def example_passed example
|
27
|
-
@formatter.example_passed example
|
28
|
-
end
|
29
|
-
|
30
|
-
def example_failed example
|
31
|
-
@formatter.example_failed example
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/lib/opal/spec/version.rb
DELETED
data/lib/opal/spec.rb
DELETED