opal-spec 0.0.1 → 0.0.2
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/.gitignore +2 -5
- data/README.md +16 -2
- data/Rakefile +11 -0
- data/lib/opal/spec/autorun.rb +0 -19
- data/lib/opal/spec/browser_formatter.rb +155 -0
- data/lib/opal/spec/formatter.rb +18 -22
- data/lib/opal/spec/runner.rb +5 -1
- data/lib/opal/spec/version.rb +1 -1
- data/lib/opal/spec.rb +1 -0
- metadata +4 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
opal-spec
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
opal-spec is a minimal spec lib for opal, inspired by RSpec and MSpec.
|
|
5
|
+
It is designed to run on [opal][http://opalrb.org], and provides the
|
|
6
|
+
bare minimum to get specs running.
|
|
7
|
+
|
|
8
|
+
Change Log
|
|
9
|
+
----------
|
|
10
|
+
|
|
11
|
+
### 0.0.2
|
|
12
|
+
|
|
13
|
+
* Added seperate BrowserFormatter class for cleaner output
|
|
14
|
+
* Update Rake tasks to use new Opal::Builder class
|
|
15
|
+
|
|
16
|
+
### 0.0.1
|
|
17
|
+
|
|
18
|
+
Initial release
|
data/Rakefile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'opal'
|
|
2
|
+
|
|
3
|
+
desc "Build latest opal-spec to current dir"
|
|
4
|
+
task :opal do
|
|
5
|
+
Opal::Builder.new('lib', :join => "opal-spec.js").build
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
desc "Get all running dependnecies"
|
|
9
|
+
task :dependencies do
|
|
10
|
+
Opal::DependencyBuilder.new(opal: true, verbose: true).build
|
|
11
|
+
end
|
data/lib/opal/spec/autorun.rb
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
require 'opal/spec'
|
|
2
2
|
|
|
3
|
-
##
|
|
4
|
-
# If running in the browser then capture test output straight to the
|
|
5
|
-
# page.
|
|
6
|
-
|
|
7
|
-
if RUBY_ENGINE =~ /opal-browser/
|
|
8
|
-
raise "Body not loaded. Add tests into <body> element" unless `document.body`
|
|
9
|
-
|
|
10
|
-
def $stdout.puts(*a)
|
|
11
|
-
a.each do |str|
|
|
12
|
-
`var elem = document.createElement('pre');
|
|
13
|
-
elem.textContent == null ? elem.innerText = str : elem.textContent = str;
|
|
14
|
-
elem.style.margin = "0px";
|
|
15
|
-
document.body.appendChild(elem);`
|
|
16
|
-
end
|
|
17
|
-
end # $stdout
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
##
|
|
21
3
|
# If autorun is the main file (entry point), then automatically load all
|
|
22
4
|
# specs from spec/
|
|
23
|
-
|
|
24
5
|
if $0 == __FILE__
|
|
25
6
|
Dir['spec/**/*.rb'].each do |spec|
|
|
26
7
|
require spec
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
require 'opal/spec/formatter'
|
|
2
|
+
|
|
3
|
+
module OpalSpec
|
|
4
|
+
class BrowserFormatter < Formatter
|
|
5
|
+
CSS = <<-EOS
|
|
6
|
+
|
|
7
|
+
body {
|
|
8
|
+
font-size: 14px;
|
|
9
|
+
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
pre {
|
|
13
|
+
font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace;
|
|
14
|
+
font-size: 12px;
|
|
15
|
+
color: #444444;
|
|
16
|
+
white-space: pre;
|
|
17
|
+
padding: 3px 0px 3px 12px;
|
|
18
|
+
margin: 0px 0px 8px;
|
|
19
|
+
|
|
20
|
+
background: #FAFAFA;
|
|
21
|
+
-webkit-box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset;
|
|
22
|
+
-webkit-border-radius: 3px;
|
|
23
|
+
-moz-border-radius: 3px;
|
|
24
|
+
border-radius: 3px;
|
|
25
|
+
border: 1px solid #DDDDDD;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
ul.example_groups {
|
|
29
|
+
list-style-type: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
li.group.passed .group_description {
|
|
33
|
+
color: #597800;
|
|
34
|
+
font-weight: bold;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
li.group.failed .group_description {
|
|
38
|
+
color: #FF000E;
|
|
39
|
+
font-weight: bold;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
li.example.passed {
|
|
43
|
+
color: #597800;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
li.example.failed {
|
|
47
|
+
color: #FF000E;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.examples {
|
|
51
|
+
list-style-type: none;
|
|
52
|
+
}
|
|
53
|
+
EOS
|
|
54
|
+
|
|
55
|
+
def start
|
|
56
|
+
%x{
|
|
57
|
+
if (!document || !document.body) {
|
|
58
|
+
#{ raise "Not running in browser." };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var groups_element = document.createElement('ul');
|
|
62
|
+
groups_element.className = 'example_groups';
|
|
63
|
+
document.body.appendChild(groups_element);
|
|
64
|
+
|
|
65
|
+
var styles = document.createElement('style');
|
|
66
|
+
styles.innerHTML = #{ CSS };
|
|
67
|
+
document.head.appendChild(styles);
|
|
68
|
+
}
|
|
69
|
+
@groups_element = `groups_element`
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def finish
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def example_group_started group
|
|
76
|
+
@example_group = group
|
|
77
|
+
@example_group_failed = false
|
|
78
|
+
|
|
79
|
+
%x{
|
|
80
|
+
var group_element = document.createElement('li');
|
|
81
|
+
|
|
82
|
+
var description = document.createElement('span');
|
|
83
|
+
description.className = 'group_description';
|
|
84
|
+
description.innerHTML = #{group.description};
|
|
85
|
+
group_element.appendChild(description);
|
|
86
|
+
|
|
87
|
+
var example_list = document.createElement('ul');
|
|
88
|
+
example_list.className = 'examples';
|
|
89
|
+
example_list.style.display = 'none';
|
|
90
|
+
group_element.appendChild(example_list);
|
|
91
|
+
|
|
92
|
+
#@groups_element.appendChild(group_element);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@group_element = `group_element`
|
|
96
|
+
@example_list = `example_list`
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def example_group_finished group
|
|
100
|
+
if @example_group_failed
|
|
101
|
+
`#@group_element.className = 'group failed';`
|
|
102
|
+
else
|
|
103
|
+
`#@group_element.className = 'group passed';`
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def example_failed example
|
|
108
|
+
@failed_examples << example
|
|
109
|
+
@example_group_failed = true
|
|
110
|
+
|
|
111
|
+
exception = example.exception
|
|
112
|
+
|
|
113
|
+
case exception
|
|
114
|
+
when OpalSpec::ExpectationNotMetError
|
|
115
|
+
output = exception.message
|
|
116
|
+
else
|
|
117
|
+
output = "#{exception.class}: #{exception.message}\n"
|
|
118
|
+
output += " #{exception.backtrace.join "\n "}\n"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
%x{
|
|
122
|
+
var wrapper = document.createElement('li');
|
|
123
|
+
wrapper.className = 'example failed';
|
|
124
|
+
|
|
125
|
+
var description = document.createElement('span');
|
|
126
|
+
description.className = 'example_description';
|
|
127
|
+
description.innerHTML = #{example.description};
|
|
128
|
+
|
|
129
|
+
var exception = document.createElement('pre');
|
|
130
|
+
exception.className = 'exception';
|
|
131
|
+
exception.innerHTML = output;
|
|
132
|
+
|
|
133
|
+
wrapper.appendChild(description);
|
|
134
|
+
wrapper.appendChild(exception);
|
|
135
|
+
|
|
136
|
+
#@example_list.appendChild(wrapper);
|
|
137
|
+
#@example_list.style.display = 'list-item';
|
|
138
|
+
}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def example_passed example
|
|
142
|
+
%x{
|
|
143
|
+
var wrapper = document.createElement('li');
|
|
144
|
+
wrapper.className = 'example passed';
|
|
145
|
+
|
|
146
|
+
var description = document.createElement('span');
|
|
147
|
+
description.className = 'example_description';
|
|
148
|
+
description.innerHTML = #{example.description};
|
|
149
|
+
|
|
150
|
+
wrapper.appendChild(description);
|
|
151
|
+
#@example_list.appendChild(wrapper);
|
|
152
|
+
}
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
data/lib/opal/spec/formatter.rb
CHANGED
|
@@ -9,6 +9,23 @@ module OpalSpec
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def finish
|
|
12
|
+
@failed_examples.each_with_index do |example, i|
|
|
13
|
+
exception = example.exception
|
|
14
|
+
description = example.description
|
|
15
|
+
group = example.example_group
|
|
16
|
+
|
|
17
|
+
case exception
|
|
18
|
+
when OpalSpec::ExpectationNotMetError
|
|
19
|
+
puts "\n#{i + 1}) Failure:\n#{group.description} #{description}:"
|
|
20
|
+
puts "#{exception.message}\n"
|
|
21
|
+
else
|
|
22
|
+
puts "\n#{i + 1}) Error:\n#{group.description} #{description}:"
|
|
23
|
+
puts "#{exception.class}: #{exception.message}\n"
|
|
24
|
+
puts " #{exception.backtrace.join "\n "}\n"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
puts "\n#{example_count} examples, #{@failed_examples.size} failures"
|
|
12
29
|
end
|
|
13
30
|
|
|
14
31
|
def example_group_started group
|
|
@@ -20,6 +37,7 @@ module OpalSpec
|
|
|
20
37
|
|
|
21
38
|
def example_started example
|
|
22
39
|
@examples << example
|
|
40
|
+
@example = example
|
|
23
41
|
end
|
|
24
42
|
|
|
25
43
|
def example_passed example
|
|
@@ -33,26 +51,4 @@ module OpalSpec
|
|
|
33
51
|
@examples.size
|
|
34
52
|
end
|
|
35
53
|
end
|
|
36
|
-
|
|
37
|
-
class ConsoleFormatter < Formatter
|
|
38
|
-
def finish
|
|
39
|
-
@failed_examples.each_with_index do |example, i|
|
|
40
|
-
exception = example.exception
|
|
41
|
-
description = example.description
|
|
42
|
-
group = example.example_group
|
|
43
|
-
|
|
44
|
-
case exception
|
|
45
|
-
when OpalSpec::ExpectationNotMetError
|
|
46
|
-
puts "\n#{i + 1}) Failure:\n#{group.description} #{description}:"
|
|
47
|
-
puts "#{exception.message}\n"
|
|
48
|
-
else
|
|
49
|
-
puts "\n#{i + 1}) Error:\n#{group.description} #{description}:"
|
|
50
|
-
puts "#{exception.class}: #{exception.message}\n"
|
|
51
|
-
puts " #{exception.backtrace.join "\n "}\n"
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
puts "\n#{example_count} specifications, #{@failed_examples.size} failures"
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
54
|
end
|
data/lib/opal/spec/runner.rb
CHANGED
data/lib/opal/spec/version.rb
CHANGED
data/lib/opal/spec.rb
CHANGED
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.0.
|
|
4
|
+
version: 0.0.2
|
|
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:
|
|
12
|
+
date: 2012-01-10 00:00:00.000000000Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Opal spec lib
|
|
15
15
|
email:
|
|
@@ -20,8 +20,10 @@ extra_rdoc_files: []
|
|
|
20
20
|
files:
|
|
21
21
|
- .gitignore
|
|
22
22
|
- README.md
|
|
23
|
+
- Rakefile
|
|
23
24
|
- lib/opal/spec.rb
|
|
24
25
|
- lib/opal/spec/autorun.rb
|
|
26
|
+
- lib/opal/spec/browser_formatter.rb
|
|
25
27
|
- lib/opal/spec/example.rb
|
|
26
28
|
- lib/opal/spec/example_group.rb
|
|
27
29
|
- lib/opal/spec/expectations.rb
|