opal-spec 0.0.3 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,5 @@ doc
3
3
  /pkg
4
4
  /*.js
5
5
  /*.gem
6
+ /build
7
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ gem "opal", :path => "~/Development/opal"
2
+ gem "rake"
data/README.md CHANGED
@@ -2,12 +2,16 @@ 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
5
+ It is designed to run on [opal](http://opalrb.org), and provides the
6
6
  bare minimum to get specs running.
7
7
 
8
8
  Change Log
9
9
  ----------
10
10
 
11
+ ### Edge
12
+
13
+ * BrowserFormatter is now default
14
+
11
15
  ### 0.0.3
12
16
 
13
17
  * Allow group names to be non-strings
data/Rakefile CHANGED
@@ -1,11 +1,5 @@
1
1
  require 'opal'
2
2
 
3
- desc "Build latest opal-spec to current dir"
4
- task :opal do
5
- sh "opal build"
6
- end
3
+ Opal::Builder.setup do |b|
7
4
 
8
- desc "Get all running dependnecies"
9
- task :dependencies do
10
- sh "opal dependencies"
11
- end
5
+ end
data/example/bar.rb CHANGED
@@ -18,4 +18,10 @@ describe "All these tests will pass" do
18
18
 
19
19
  "foo".should_not == "bar"
20
20
  end
21
+
22
+ it "should raise exceptions" do
23
+ lambda {
24
+ raise "foo"
25
+ }.should raise_error(Exception)
26
+ end
21
27
  end
@@ -0,0 +1,164 @@
1
+ #require 'opal/spec/formatter'
2
+
3
+ module OpalSpec
4
+ class BrowserFormatter
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 initialize
56
+ @examples = []
57
+ @failed_examples = []
58
+ end
59
+
60
+ def start
61
+ unless Element.body_ready?
62
+ raise "Not running in browser"
63
+ end
64
+
65
+ @summary_element = Element.new 'p'
66
+ @summary_element.class_name = 'summary'
67
+ @summary_element.append_to_body
68
+
69
+ @groups_element = Element.new 'ul'
70
+ @groups_element.class_name = 'example_groups'
71
+ @groups_element.append_to_body
72
+
73
+ styles = Element.new 'style'
74
+ styles.html = CSS
75
+ styles.append_to_head
76
+ end
77
+
78
+ def finish
79
+ text = "\n#{example_count} examples, #{@failed_examples.size} failures"
80
+ @summary_element.html = text
81
+ end
82
+
83
+ def example_group_started group
84
+ @example_group = group
85
+ @example_group_failed = false
86
+
87
+ @group_element = Element.new 'li'
88
+
89
+ description = Element.new 'span'
90
+ description.class_name = 'group_description'
91
+ description.html = group.description
92
+
93
+ @group_element.append description
94
+
95
+ @example_list = Element.new 'ul'
96
+ @example_list.class_name = 'examples'
97
+ @example_list.hide
98
+
99
+ @group_element.append @example_list
100
+ @groups_element.append @group_element
101
+ end
102
+
103
+ def example_group_finished group
104
+ if @example_group_failed
105
+ @group_element.class_name = 'group failed'
106
+ else
107
+ @group_element.class_name = 'group passed'
108
+ end
109
+ end
110
+
111
+ def example_started example
112
+ @examples << example
113
+ @example = example
114
+ end
115
+
116
+ def example_failed example
117
+ @failed_examples << example
118
+ @example_group_failed = true
119
+
120
+ exception = example.exception
121
+
122
+ case exception
123
+ when OpalSpec::ExpectationNotMetError
124
+ output = exception.message
125
+ else
126
+ output = "#{exception.class}: #{exception.message}\n"
127
+ output += " #{exception.backtrace.join "\n "}\n"
128
+ end
129
+
130
+ wrapper = Element.new 'li'
131
+ wrapper.class_name = 'example failed'
132
+
133
+ description = Element.new 'span'
134
+ description.class_name = 'example_description'
135
+ description.html = example.description
136
+
137
+ exception = Element.new 'pre'
138
+ exception.class_name = 'exception'
139
+ exception.html = output
140
+
141
+ wrapper.append description
142
+ wrapper.append exception
143
+
144
+ @example_list.append wrapper
145
+ @example_list.style 'display', 'list-item'
146
+ end
147
+
148
+ def example_passed example
149
+ wrapper = Element.new 'li'
150
+ wrapper.class_name = 'example passed'
151
+
152
+ description = Element.new 'span'
153
+ description.class_name = 'example_description'
154
+ description.html = example.description
155
+
156
+ wrapper.append description
157
+ @example_list.append wrapper
158
+ end
159
+
160
+ def example_count
161
+ @examples.size
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,43 @@
1
+ module OpalSpec
2
+ class Element
3
+ def self.body_ready?
4
+ `!!(document && document.body)`
5
+ end
6
+
7
+ def initialize(tag = 'div')
8
+ `this.el = document.createElement(tag)`
9
+ end
10
+
11
+ def class_name=(class_name)
12
+ `this.el.className = class_name`
13
+ end
14
+
15
+ def html=(html)
16
+ `this.el.innerHTML = html`
17
+ end
18
+
19
+ def append(child)
20
+ `this.el.appendChild(child.el)`
21
+ end
22
+
23
+ def hide
24
+ `this.el.style.display = 'none'`
25
+ end
26
+
27
+ def show
28
+ `delete this.el.style.display`
29
+ end
30
+
31
+ def append_to_head
32
+ `document.head.appendChild(this.el)`
33
+ end
34
+
35
+ def append_to_body
36
+ `document.body.appendChild(this.el)`
37
+ end
38
+
39
+ def style(key, val)
40
+ `this.el.style[key] = val`
41
+ end
42
+ end
43
+ end
File without changes
@@ -42,11 +42,11 @@ module OpalSpec
42
42
  end
43
43
 
44
44
  def before_hooks
45
- @parent ? @parent.before_hooks + @before_hooks : @before_hooks
45
+ @parent ? [].concat(@parent.before_hooks).concat(@before_hooks) : @before_hooks
46
46
  end
47
47
 
48
48
  def after_hooks
49
- @parent ? @parent.after_hooks + @after_hooks : @after_hooks
49
+ @parent ? [].concat(@parent.after_hooks).concat(@after_hooks) : @after_hooks
50
50
  end
51
51
 
52
52
  def run runner
File without changes
File without changes
File without changes
@@ -1,15 +1,18 @@
1
+ # cheat until proper method available..
2
+ %x{
3
+ setTimeout(function() {
4
+ #{OpalSpec::Runner.new.run}
5
+ }, 0);
6
+ }
7
+
1
8
  module OpalSpec
2
9
  class Runner
3
- def self.autorun
4
- at_exit { OpalSpec::Runner.new.run }
5
- end
10
+ # def self.autorun
11
+ # at_exit { OpalSpec::Runner.new.run }
12
+ # end
6
13
 
7
14
  def initialize
8
- if RUBY_ENGINE == 'opal-browser'
9
- @formatters = [BrowserFormatter.new]
10
- else
11
- @formatters = [Formatter.new]
12
- end
15
+ @formatters = [BrowserFormatter.new]
13
16
  end
14
17
 
15
18
  def run
@@ -14,4 +14,4 @@ module ScratchPad
14
14
  def self.recorded
15
15
  @record
16
16
  end
17
- end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module OpalSpec
2
2
  VERSION = "0.0.3"
3
- end
3
+ end
data/opal-spec.gemspec CHANGED
@@ -1,15 +1,14 @@
1
- $:.push File.expand_path('../lib', __FILE__)
2
- require 'opal/spec/version'
1
+ # -*- encoding: utf-8 -*-
3
2
 
4
3
  Gem::Specification.new do |s|
5
4
  s.name = 'opal-spec'
6
- s.version = OpalSpec::VERSION
7
- s.authors = ['Adam Beynon']
8
- s.email = ['adam@adambeynon.com']
9
- s.homepage = 'http://opalscript.org'
10
- s.summary = 'Opal spec lib'
11
- s.description = 'Opal spec lib'
5
+ s.version = '0.1.1'
6
+ s.author = 'Adam Beynon'
7
+ s.email = 'adam@adambeynon.com'
8
+ s.homepage = 'http://opalrb.org'
9
+ s.summary = 'Opal compatible spec'
10
+ s.description = 'Opal compatible spec'
12
11
 
13
- s.files = `git ls-files`.split("\n")
14
- s.require_paths = ['lib']
12
+ s.files = `git ls-files`.split("\n")
13
+ s.require_paths = ['lib']
15
14
  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.0.3
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,16 +9,16 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-21 00:00:00.000000000Z
12
+ date: 2012-05-12 00:00:00.000000000Z
13
13
  dependencies: []
14
- description: Opal spec lib
15
- email:
16
- - adam@adambeynon.com
14
+ description: Opal compatible spec
15
+ email: adam@adambeynon.com
17
16
  executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
20
  - .gitignore
21
+ - Gemfile
22
22
  - README.md
23
23
  - Rakefile
24
24
  - example/bar.rb
@@ -28,20 +28,18 @@ files:
28
28
  - example/nested.rb
29
29
  - example/runner.html
30
30
  - example/spec_helper.rb
31
- - lib/opal/spec.rb
32
- - lib/opal/spec/autorun.rb
33
- - lib/opal/spec/browser_formatter.rb
34
- - lib/opal/spec/example.rb
35
- - lib/opal/spec/example_group.rb
36
- - lib/opal/spec/expectations.rb
37
- - lib/opal/spec/formatter.rb
38
- - lib/opal/spec/kernel.rb
39
- - lib/opal/spec/matchers.rb
40
- - lib/opal/spec/runner.rb
41
- - lib/opal/spec/scratch_pad.rb
42
- - lib/opal/spec/version.rb
31
+ - lib/opal-spec/browser_formatter.rb
32
+ - lib/opal-spec/dom.rb
33
+ - lib/opal-spec/example.rb
34
+ - lib/opal-spec/example_group.rb
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
43
41
  - opal-spec.gemspec
44
- homepage: http://opalscript.org
42
+ homepage: http://opalrb.org
45
43
  licenses: []
46
44
  post_install_message:
47
45
  rdoc_options: []
@@ -61,8 +59,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
59
  version: '0'
62
60
  requirements: []
63
61
  rubyforge_project:
64
- rubygems_version: 1.8.10
62
+ rubygems_version: 1.8.11
65
63
  signing_key:
66
64
  specification_version: 3
67
- summary: Opal spec lib
65
+ summary: Opal compatible spec
68
66
  test_files: []
@@ -1,11 +0,0 @@
1
- require 'opal/spec'
2
-
3
- # If autorun is the main file (entry point), then automatically load all
4
- # specs from spec/
5
- if $0 == __FILE__
6
- Dir['spec/**/*.rb'].each do |spec|
7
- require spec
8
- end
9
- end
10
-
11
- OpalSpec::Runner.autorun
@@ -1,155 +0,0 @@
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
@@ -1,54 +0,0 @@
1
- module OpalSpec
2
- class Formatter
3
- def initialize
4
- @examples = []
5
- @failed_examples = []
6
- end
7
-
8
- def start
9
- end
10
-
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"
29
- end
30
-
31
- def example_group_started group
32
- @example_group = group
33
- end
34
-
35
- def example_group_finished group
36
- end
37
-
38
- def example_started example
39
- @examples << example
40
- @example = example
41
- end
42
-
43
- def example_passed example
44
- end
45
-
46
- def example_failed example
47
- @failed_examples << example
48
- end
49
-
50
- def example_count
51
- @examples.size
52
- end
53
- end
54
- end
data/lib/opal/spec.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'opal/spec/kernel'
2
- require 'opal/spec/runner'
3
- require 'opal/spec/example_group'
4
- require 'opal/spec/example'
5
- require 'opal/spec/expectations'
6
- require 'opal/spec/matchers'
7
- require 'opal/spec/formatter'
8
- require 'opal/spec/browser_formatter'
9
- require 'opal/spec/scratch_pad'