opal-spec 0.2.17 → 0.3.1

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 CHANGED
@@ -1,2 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+
4
+ gem 'opal'
5
+ gem 'opal-sprockets'
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Spec
3
- VERSION = '0.2.17'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.require_paths = ['lib']
15
15
 
16
- s.add_dependency 'opal', '~> 0.4.1'
17
- s.add_dependency 'opal-sprockets', '~> 0.1.0'
16
+ s.add_dependency 'opal', '~> 0.4.4'
17
+ s.add_dependency 'opal-sprockets', '~> 0.2.0'
18
18
 
19
19
  s.add_development_dependency 'rake'
20
20
  end
@@ -50,38 +50,77 @@ module OpalSpec
50
50
  }
51
51
  CSS
52
52
 
53
+ class Node
54
+
55
+ attr_reader :element
56
+
57
+ def self.create(tag)
58
+ new(`document.createElement(tag)`)
59
+ end
60
+
61
+ def initialize(element)
62
+ @element = element
63
+ end
64
+
65
+ def class_name=(name)
66
+ `#{ @element }.className = name`
67
+ end
68
+
69
+ def html=(html)
70
+ `#{ @element }.innerHTML = html`
71
+ end
72
+
73
+ def type=(type)
74
+ `#{ @element }.type = type`
75
+ end
76
+
77
+ def append(child)
78
+ `#{ @element }.appendChild(#{ child.element })`
79
+ end
80
+
81
+ def css_text=(text)
82
+ %x{
83
+ if (#{ @element }.styleSheet) {
84
+ #{ @element }.styleSheet.cssText = text;
85
+ }
86
+ else {
87
+ #{ @element }.appendChild(document.createTextNode(text));
88
+ }
89
+ }
90
+ end
91
+
92
+ def style(name, value)
93
+ `#{@element}.style[name] = value`
94
+ end
95
+
96
+ def append_to_head
97
+ `document.getElementsByTagName('head')[0].appendChild(#{@element})`
98
+ end
99
+ end
100
+
53
101
  def initialize
54
102
  @examples = []
55
103
  @failed_examples = []
56
104
  end
57
105
 
58
106
  def start
59
- raise "Not running in browser" unless $global[:document]
107
+ raise "Not running in browser" unless Runner.in_browser?
60
108
 
61
- @summary_element = $global.document.createElement 'p'
62
- @summary_element.className = 'summary'
63
- @summary_element.innerHTML = "Running..."
109
+ @summary_element = Node.create 'p'
110
+ @summary_element.class_name = "summary"
111
+ @summary_element.html = "Runner..."
64
112
 
65
- @groups_element = $global.document.createElement 'ul'
66
- @groups_element.className = 'example_groups'
113
+ @groups_element = Node.create("ul")
114
+ @groups_element.class_name = "example_groups"
67
115
 
68
- #target = $global.document.getElementById 'opal-spec-output'
116
+ target = Node.new(`document.body`)
117
+ target.append @summary_element
118
+ target.append @groups_element
69
119
 
70
- target = $global.document.body unless target
71
-
72
- target.appendChild @summary_element
73
- target.appendChild @groups_element
74
-
75
- styles = $global.document.createElement 'style'
120
+ styles = Node.create "style"
76
121
  styles.type = "text/css"
77
-
78
- if styles[:styleSheet]
79
- styles.styleSheet.cssText = CSS
80
- else
81
- styles.appendChild $global.document.createTextNode CSS
82
- end
83
-
84
- $global.document.getElementsByTagName('head')[0].appendChild styles
122
+ styles.css_text = CSS
123
+ styles.append_to_head
85
124
 
86
125
  @start_time = Time.now.to_f
87
126
  end
@@ -90,32 +129,32 @@ module OpalSpec
90
129
  time = Time.now.to_f - @start_time
91
130
  text = "\n#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
92
131
 
93
- @summary_element.innerHTML = text
132
+ @summary_element.html = text
94
133
  end
95
134
 
96
135
  def example_group_started group
97
136
  @example_group = group
98
137
  @example_group_failed = false
99
138
 
100
- @group_element = $global.document.createElement 'li'
139
+ @group_element = Node.create("li")
101
140
 
102
- description = $global.document.createElement 'span'
103
- description.className = 'group_description'
104
- description.innerHTML = group.description.to_s
105
- @group_element.appendChild description
141
+ description = Node.create("span")
142
+ description.class_name = "group_description"
143
+ description.html = group.description.to_s
144
+ @group_element.append description
106
145
 
107
- @example_list = $global.document.createElement 'ul'
108
- @example_list.className = 'examples'
109
- @group_element.appendChild @example_list
146
+ @example_list = Node.create "ul"
147
+ @example_list.class_name = "examples"
148
+ @group_element.append @example_list
110
149
 
111
- @groups_element.appendChild @group_element
150
+ @groups_element.append @group_element
112
151
  end
113
152
 
114
153
  def example_group_finished group
115
154
  if @example_group_failed
116
- @group_element.className = 'group failed'
155
+ @group_element.class_name = "group failed"
117
156
  else
118
- @group_element.className = 'group passed'
157
+ @group_element.class_name = "group passed"
119
158
  end
120
159
  end
121
160
 
@@ -138,34 +177,34 @@ module OpalSpec
138
177
  output += " #{exception.backtrace.join "\n "}\n"
139
178
  end
140
179
 
141
- wrapper = $global.document.createElement 'li'
142
- wrapper.className = 'example failed'
180
+ wrapper = Node.create "li"
181
+ wrapper.class_name = "example failed"
143
182
 
144
- description = $global.document.createElement 'span'
145
- description.className = 'example_description'
146
- description.innerHTML = example.description
183
+ description = Node.create "span"
184
+ description.class_name = "example_description"
185
+ description.html = example.description.to_s
147
186
 
148
- exception = $global.document.createElement 'pre'
149
- exception.className = 'exception'
150
- exception.innerHTML = output
187
+ exception = Node.create "pre"
188
+ exception.class_name = "exception"
189
+ exception.html = output
151
190
 
152
- wrapper.appendChild description
153
- wrapper.appendChild exception
191
+ wrapper.append description
192
+ wrapper.append exception
154
193
 
155
- @example_list.appendChild wrapper
156
- @example_list.style.display = 'list-item'
194
+ @example_list.append wrapper
195
+ @example_list.style :display, "list-item"
157
196
  end
158
197
 
159
198
  def example_passed example
160
- wrapper = $global.document.createElement 'li'
161
- wrapper.className = 'example passed'
199
+ wrapper = Node.create "li"
200
+ wrapper.class_name = "example passed"
162
201
 
163
- description = $global.document.createElement 'span'
164
- description.className = 'example_description'
165
- description.innerHTML = example.description
202
+ description = Node.create "span"
203
+ description.class_name = "example_description"
204
+ description.html = example.description.to_s
166
205
 
167
- wrapper.appendChild description
168
- @example_list.appendChild wrapper
206
+ wrapper.append description
207
+ @example_list.append wrapper
169
208
  end
170
209
 
171
210
  def example_count
@@ -41,7 +41,7 @@ module OpalSpec
41
41
  end
42
42
 
43
43
  def failure_message_for_should
44
- "expected #{expected.inspect}, but got: #{actual.inspect} (using ==)."
44
+ "expected #{actual.inspect}, but got: #{expected.inspect} (using ==)."
45
45
  end
46
46
  end
47
47
 
@@ -55,7 +55,7 @@ module OpalSpec
55
55
  end
56
56
 
57
57
  def failure_message_for_should_not
58
- "expected #{expected.inspect} not to be: #{actual.inspect} (using ==)."
58
+ "expected #{actual.inspect} not to be: #{expected.inspect} (using ==)."
59
59
  end
60
60
  end
61
61
  end
@@ -50,11 +50,14 @@ module OpalSpec
50
50
  end
51
51
 
52
52
  def finish_with_code(code)
53
- if $global[:phantom]
54
- $global[:phantom].exit code
55
- else
56
- $global.OPAL_SPEC_CODE = code
57
- end
53
+ %x{
54
+ if (typeof(phantom) !== "undefined") {
55
+ phantom.exit(code);
56
+ }
57
+ else {
58
+ Opal.global.OPAL_SPEC_CODE = code;
59
+ }
60
+ }
58
61
  end
59
62
 
60
63
  def example_group_started group
@@ -2,15 +2,16 @@ module OpalSpec
2
2
  class Runner
3
3
  def self.in_browser?
4
4
  $global[:document]
5
+ `typeof(document) !== 'undefined'`
5
6
  end
6
7
 
7
8
  def self.in_phantom?
8
- $global[:phantom] or $global[:OPAL_SPEC_PHANTOM]
9
+ `typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined'`
9
10
  end
10
11
 
11
12
  def self.autorun
12
13
  if in_browser?
13
- $global.setTimeout -> { Runner.new.run }, 0
14
+ `setTimeout(function() { #{ Runner.new.run } }, 0)`
14
15
  else
15
16
  Runner.new.run
16
17
  end
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.17
4
+ version: 0.3.1
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: 2013-06-16 00:00:00.000000000 Z
12
+ date: 2013-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: opal
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.4.1
21
+ version: 0.4.4
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.4.1
29
+ version: 0.4.4
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: opal-sprockets
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.1.0
37
+ version: 0.2.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.1.0
45
+ version: 0.2.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,6 @@ extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
68
  - .gitignore
69
- - CHANGELOG.md
70
69
  - Gemfile
71
70
  - README.md
72
71
  - Rakefile
@@ -1,52 +0,0 @@
1
- ## 0.2.17 2013-06-16
2
-
3
- * Use opal-sprockets as server for specs.
4
-
5
- ## 0.2.16 2013-06-09
6
-
7
- * Define matchers using OpalSpec.matcher() method.
8
-
9
- * Remove old TestCase code, and more to pure spec based testing.
10
-
11
- ## 0.2.15 2013-05-2
12
-
13
- * Remove opal-sprockets dependency and use opal directly for sprockets
14
- support.
15
-
16
- ## 0.2.13 2013-02-23
17
-
18
- * Re-write Opal::Spec::Server to inherit from Opal::Server. Opal::Server is
19
- a standard rack-app which configures Opal and load paths in a more
20
- consistent manner.
21
-
22
- * Add respond_to and be_empty matchers for Spec.
23
-
24
- * Added Spec::Pending as a standard way to mark specs as not compliant or
25
- working. Pending specs are simply ignored when running.
26
-
27
- ## 0.2.11 2013-02-20
28
-
29
- * Added TestCase class to allow unit tests. OpalTest::Spec now inherits from
30
- OpalTest::TestCase.
31
-
32
- * Added Spec#let and Spec#subject.
33
-
34
- ## 0.2.7
35
-
36
- * Can be built using asset pipeline/sprockets.
37
- * BrowserFormatter is now default.
38
-
39
- ## 0.0.3
40
-
41
- * Allow group names to be non-strings.
42
- * Nested groups now have outer group name as prefix.
43
- * Nested groups should inherit `before` and `after` blocks.
44
-
45
- ## 0.0.2
46
-
47
- * Added seperate BrowserFormatter class for cleaner output.
48
- * Update Rake tasks to use new Opal::Builder class.
49
-
50
- ## 0.0.1
51
-
52
- * Initial Release.