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 CHANGED
@@ -1,27 +1,5 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
- desc "Build opal-spec (with opal) into build"
5
- task :build => [:dir] do
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
@@ -0,0 +1,5 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'opal/spec/server'
5
+ run Opal::Spec::Server.new
@@ -1,194 +1,192 @@
1
- module Opal
2
- module Spec
3
- class BrowserFormatter
4
- CSS = <<-EOS
5
-
6
- body {
7
- font-size: 14px;
8
- font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
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
- pre {
12
- font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace;
13
- font-size: 12px;
14
- color: #444444;
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
- ul.example_groups {
28
- list-style-type: none;
29
- }
64
+ var summary_element = document.createElement('p');
65
+ summary_element.className = 'summary';
66
+ summary_element.innerHTML = "Running...";
30
67
 
31
- li.group.passed .group_description {
32
- color: #597800;
33
- font-weight: bold;
34
- }
68
+ var groups_element = document.createElement('ul');
69
+ groups_element.className = 'example_groups';
35
70
 
36
- li.group.failed .group_description {
37
- color: #FF000E;
38
- font-weight: bold;
39
- }
71
+ var target = document.getElementById('opal-spec-output');
40
72
 
41
- li.example.passed {
42
- color: #597800;
73
+ if (!target) {
74
+ target = document.body;
43
75
  }
44
76
 
45
- li.example.failed {
46
- color: #FF000E;
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
- def initialize
55
- @examples = []
56
- @failed_examples = []
57
- end
80
+ var styles = document.createElement('style');
81
+ styles.type = 'text/css';
58
82
 
59
- def start
60
- %x{
61
- if (!document || !document.body) {
62
- #{ raise "Not running in browser." };
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
- var summary_element = document.createElement('p');
66
- summary_element.className = 'summary';
67
- summary_element.innerHTML = "Running...";
90
+ document.getElementsByTagName('head')[0].appendChild(styles);
91
+ }
68
92
 
69
- var groups_element = document.createElement('ul');
70
- groups_element.className = 'example_groups';
93
+ @start_time = Time.now.to_f
94
+ @groups_element = `groups_element`
95
+ @summary_element = `summary_element`
96
+ end
71
97
 
72
- var target = document.getElementById('opal-spec-output');
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
- if (!target) {
75
- target = document.body;
76
- }
104
+ def example_group_started group
105
+ @example_group = group
106
+ @example_group_failed = false
77
107
 
78
- target.appendChild(summary_element);
79
- target.appendChild(groups_element);
108
+ %x{
109
+ var group_element = document.createElement('li');
80
110
 
81
- var styles = document.createElement('style');
82
- styles.type = 'text/css';
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
- if (styles.styleSheet) {
85
- styles.styleSheet.cssText = __scope.CSS;
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
- document.getElementsByTagName('head')[0].appendChild(styles);
92
- }
120
+ #@groups_element.appendChild(group_element);
121
+ }
93
122
 
94
- @start_time = Time.now.to_f
95
- @groups_element = `groups_element`
96
- @summary_element = `summary_element`
97
- end
123
+ @group_element = `group_element`
124
+ @example_list = `example_list`
125
+ end
98
126
 
99
- def finish
100
- time = Time.now.to_f - @start_time
101
- text = "\n#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
102
- `#{@summary_element}.innerHTML = text`
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
- def example_group_started group
106
- @example_group = group
107
- @example_group_failed = false
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
- var example_list = document.createElement('ul');
118
- example_list.className = 'examples';
119
- group_element.appendChild(example_list);
140
+ def example_failed example
141
+ @failed_examples << example
142
+ @example_group_failed = true
120
143
 
121
- #@groups_element.appendChild(group_element);
122
- }
123
-
124
- @group_element = `group_element`
125
- @example_list = `example_list`
126
- end
144
+ exception = example.exception
127
145
 
128
- def example_group_finished group
129
- if @example_group_failed
130
- `#@group_element.className = 'group failed';`
131
- else
132
- `#@group_element.className = 'group passed';`
133
- end
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
- def example_started example
137
- @examples << example
138
- @example = example
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
- %x{
156
- var wrapper = document.createElement('li');
157
- wrapper.className = 'example failed';
158
+ var description = document.createElement('span');
159
+ description.className = 'example_description';
160
+ description.innerHTML = #{example.description};
158
161
 
159
- var description = document.createElement('span');
160
- description.className = 'example_description';
161
- description.innerHTML = #{example.description};
162
+ var exception = document.createElement('pre');
163
+ exception.className = 'exception';
164
+ exception.innerHTML = output;
162
165
 
163
- var exception = document.createElement('pre');
164
- exception.className = 'exception';
165
- exception.innerHTML = output;
166
+ wrapper.appendChild(description);
167
+ wrapper.appendChild(exception);
166
168
 
167
- wrapper.appendChild(description);
168
- wrapper.appendChild(exception);
169
-
170
- #@example_list.appendChild(wrapper);
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
- def example_passed example
176
- %x{
177
- var wrapper = document.createElement('li');
178
- wrapper.className = 'example passed';
174
+ def example_passed example
175
+ %x{
176
+ var wrapper = document.createElement('li');
177
+ wrapper.className = 'example passed';
179
178
 
180
- var description = document.createElement('span');
181
- description.className = 'example_description';
182
- description.innerHTML = #{example.description};
179
+ var description = document.createElement('span');
180
+ description.className = 'example_description';
181
+ description.innerHTML = #{example.description};
183
182
 
184
- wrapper.appendChild(description);
185
- #@example_list.appendChild(wrapper);
186
- }
187
- end
183
+ wrapper.appendChild(description);
184
+ #@example_list.appendChild(wrapper);
185
+ }
186
+ end
188
187
 
189
- def example_count
190
- @examples.size
191
- end
188
+ def example_count
189
+ @examples.size
192
190
  end
193
191
  end
194
192
  end
@@ -1,78 +1,76 @@
1
- module Opal
2
- module Spec
3
- class Example
4
- attr_reader :description, :example_group, :exception
5
- attr_accessor :asynchronous
1
+ module Spec
2
+ class Example
3
+ attr_reader :description, :example_group, :exception
4
+ attr_accessor :asynchronous
6
5
 
7
- def initialize(group, desc, block)
8
- @example_group = group
9
- @description = desc
10
- @__block__ = block
11
- end
6
+ def initialize(group, desc, block)
7
+ @example_group = group
8
+ @description = desc
9
+ @__block__ = block
10
+ end
12
11
 
13
- def finish_running
14
- if @exception
15
- @example_group.example_failed self
16
- else
17
- @example_group.example_passed self
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
- def run
22
- begin
23
- @example_group.example_started self
24
- run_before_hooks
25
- instance_eval(&@__block__)
26
- rescue => e
27
- @exception = e
28
- ensure
29
- run_after_hooks unless @asynchronous
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
- def run_after_hooks
40
- begin
41
- @example_group.after_hooks.each do |after|
42
- instance_eval &after
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
- def run_before_hooks
50
- @example_group.before_hooks.each do |before|
51
- instance_eval &before
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
- def run_async(&block)
56
- begin
57
- block.call
58
- rescue => e
59
- @exception = e
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
- finish_running
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
- def set_timeout(duration, &block)
68
- %x{
69
- setTimeout(function() {
70
- #{ block.call };
71
- }, duration);
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
- self
75
- end
73
+ self
76
74
  end
77
75
  end
78
- end
76
+ end