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 +2 -24
- data/config.ru +5 -0
- data/lib/assets/javascripts/opal/spec/browser_formatter.rb +154 -156
- data/lib/assets/javascripts/opal/spec/example.rb +59 -61
- data/lib/assets/javascripts/opal/spec/example_group.rb +70 -72
- data/lib/assets/javascripts/opal/spec/expectations.rb +38 -39
- data/lib/assets/javascripts/opal/spec/kernel.rb +3 -3
- data/lib/assets/javascripts/opal/spec/matchers.rb +68 -70
- data/lib/assets/javascripts/opal/spec/phantom_formatter.rb +71 -73
- data/lib/assets/javascripts/opal/spec/runner.rb +59 -61
- data/lib/assets/javascripts/opal/spec/sprockets_runner.js.erb +11 -0
- data/lib/assets/javascripts/opal/spec.rb +5 -2
- data/lib/opal/spec/rake_task.rb +3 -2
- data/lib/opal/spec/server.rb +49 -0
- data/lib/opal/spec/version.rb +1 -1
- data/lib/opal/spec.rb +5 -3
- data/spec/specs.rb +4 -7
- data/vendor/spec_runner.html.erb +9 -0
- data/vendor/{runner.js → spec_runner.js} +0 -0
- metadata +7 -5
- data/lib/opal/spec/runner.rb +0 -12
- data/spec/index.html +0 -9
@@ -1,80 +1,78 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
return true;
|
8
|
-
}
|
9
|
-
|
10
|
-
return false;
|
1
|
+
module Spec
|
2
|
+
class Runner
|
3
|
+
def self.in_browser?
|
4
|
+
%x{
|
5
|
+
if (typeof(window) !== 'undefined' && typeof(document) !== 'undefined') {
|
6
|
+
return true;
|
11
7
|
}
|
12
|
-
end
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
return true;
|
18
|
-
}
|
9
|
+
return false;
|
10
|
+
}
|
11
|
+
end
|
19
12
|
|
20
|
-
|
13
|
+
def self.in_phantom?
|
14
|
+
%x{
|
15
|
+
if (typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined') {
|
16
|
+
return true;
|
21
17
|
}
|
22
|
-
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
setTimeout(function() {
|
28
|
-
#{ Runner.new.run };
|
29
|
-
}, 0);
|
30
|
-
}
|
31
|
-
else
|
32
|
-
Runner.new.run
|
33
|
-
end
|
34
|
-
end
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
end
|
35
22
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
42
32
|
end
|
33
|
+
end
|
43
34
|
|
44
|
-
|
45
|
-
|
46
|
-
@formatter.
|
47
|
-
|
35
|
+
def initialize
|
36
|
+
if Runner.in_phantom?
|
37
|
+
@formatter = PhantomFormatter.new
|
38
|
+
elsif Runner.in_browser?
|
39
|
+
@formatter = BrowserFormatter.new
|
48
40
|
end
|
41
|
+
end
|
49
42
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
43
|
+
def run
|
44
|
+
@groups = ExampleGroup.example_groups.dup
|
45
|
+
@formatter.start
|
46
|
+
run_next_group
|
47
|
+
end
|
57
48
|
|
58
|
-
|
59
|
-
|
49
|
+
def run_next_group
|
50
|
+
if @groups.empty?
|
51
|
+
@formatter.finish
|
52
|
+
else
|
53
|
+
@groups.shift.run self
|
60
54
|
end
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
57
|
+
def example_group_started group
|
58
|
+
@formatter.example_group_started group
|
59
|
+
end
|
66
60
|
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
def example_group_finished group
|
62
|
+
@formatter.example_group_finished group
|
63
|
+
run_next_group
|
64
|
+
end
|
70
65
|
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
def example_started example
|
67
|
+
@formatter.example_started example
|
68
|
+
end
|
74
69
|
|
75
|
-
|
76
|
-
|
77
|
-
|
70
|
+
def example_passed example
|
71
|
+
@formatter.example_passed example
|
72
|
+
end
|
73
|
+
|
74
|
+
def example_failed example
|
75
|
+
@formatter.example_failed example
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/*
|
2
|
+
This file is used by Opal::Spec::Server to basically load all spec files that
|
3
|
+
can be found in the spec/ directory.
|
4
|
+
*/
|
5
|
+
|
6
|
+
<% require_asset 'opal' %>
|
7
|
+
<% require_asset 'opal-spec' %>
|
8
|
+
|
9
|
+
<% Dir.glob('spec/**/*.{rb,opal}').each do |s| %>
|
10
|
+
<% require_asset s.sub(/^spec\//, '').sub(/\.(rb|opal)$/, '') %>
|
11
|
+
<% end %>
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'opal'
|
2
|
+
|
2
3
|
require 'opal/spec/example'
|
3
4
|
require 'opal/spec/example_group'
|
4
5
|
require 'opal/spec/matchers'
|
@@ -9,5 +10,7 @@ require 'opal/spec/browser_formatter'
|
|
9
10
|
require 'opal/spec/phantom_formatter'
|
10
11
|
require 'opal/spec/kernel'
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
module Opal
|
14
|
+
# Compatibility with older versions
|
15
|
+
Spec = ::Spec
|
16
|
+
end
|
data/lib/opal/spec/rake_task.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'opal/spec'
|
2
|
+
require 'opal/spec/server'
|
2
3
|
|
3
4
|
module Opal
|
4
5
|
module Spec
|
@@ -22,7 +23,7 @@ module Opal
|
|
22
23
|
require 'webrick'
|
23
24
|
|
24
25
|
server = fork do
|
25
|
-
Rack::Server.start(:
|
26
|
+
Rack::Server.start(:app => Opal::Spec::Server.new, :Port => port,
|
26
27
|
:Logger => WEBrick::Log.new("/dev/null"), :AccessLog => [])
|
27
28
|
end
|
28
29
|
|
@@ -37,7 +38,7 @@ module Opal
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def runner_path
|
40
|
-
@runner_path || File.join(
|
41
|
+
@runner_path || File.join(VENDOR_PATH, 'spec_runner.js')
|
41
42
|
end
|
42
43
|
|
43
44
|
def url_path
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'opal/spec'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Opal
|
5
|
+
module Spec
|
6
|
+
class Server
|
7
|
+
class Index
|
8
|
+
def initialize(app, sprockets)
|
9
|
+
@app = app
|
10
|
+
@sprockets = sprockets
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
if env['PATH_INFO'] == '/'
|
15
|
+
[200, { 'Content-Type' => 'text/html' }, [self.html]]
|
16
|
+
else
|
17
|
+
@app.call env
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def html
|
22
|
+
source = File.read File.join(VENDOR_PATH, 'spec_runner.html.erb')
|
23
|
+
ERB.new(source).result binding
|
24
|
+
end
|
25
|
+
|
26
|
+
def javascript_include_tag(source)
|
27
|
+
paths = @sprockets[source].to_a.map { |d| "#{d.logical_path}?body=1" }
|
28
|
+
tags = paths.map { |p| "<script src=\"/assets/#{p}\"></script>" }
|
29
|
+
tags.join "\n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@sprockets = sprockets = Opal::Environment.new
|
35
|
+
sprockets.append_path 'spec'
|
36
|
+
|
37
|
+
@app = Rack::Builder.app do
|
38
|
+
map('/assets') { run sprockets }
|
39
|
+
use Index, sprockets
|
40
|
+
run Rack::Directory.new('spec')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def call(env)
|
45
|
+
@app.call env
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/opal/spec/version.rb
CHANGED
data/lib/opal/spec.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'opal'
|
2
|
-
require 'opal/spec/runner'
|
3
2
|
require 'opal/spec/version'
|
4
3
|
|
5
|
-
|
6
|
-
|
4
|
+
module Opal
|
5
|
+
module Spec
|
6
|
+
VENDOR_PATH = File.join(File.dirname(__FILE__), '..', '..', 'vendor')
|
7
|
+
end
|
8
|
+
end
|
7
9
|
|
8
10
|
# Just register our opal code path with opal build tools
|
9
11
|
Opal.append_path File.join(File.dirname(__FILE__), '..', 'assets', 'javascripts')
|
data/spec/specs.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'opal'
|
2
|
-
require 'opal-spec'
|
3
|
-
|
4
1
|
@passed = 0
|
5
2
|
@failures = []
|
6
3
|
|
@@ -54,16 +51,16 @@ describe 'Another group' do
|
|
54
51
|
nil.should be_nil
|
55
52
|
end
|
56
53
|
|
57
|
-
async 'this should pass (in 1 second time)' do
|
58
|
-
set_timeout(
|
54
|
+
async 'this should pass (in 0.1 second time)' do
|
55
|
+
set_timeout(100) do
|
59
56
|
run_async {
|
60
57
|
1.should == 1
|
61
58
|
}
|
62
59
|
end
|
63
60
|
end
|
64
61
|
|
65
|
-
async 'this should fail (in 1 second time)' do
|
66
|
-
set_timeout(
|
62
|
+
async 'this should fail (in 0.1 second time)' do
|
63
|
+
set_timeout(100) do
|
67
64
|
run_async {
|
68
65
|
1.should == 5
|
69
66
|
}
|
File without changes
|
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.
|
4
|
+
version: 0.2.9
|
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-02-
|
12
|
+
date: 2013-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Opal compatible spec library
|
15
15
|
email: adam.beynon@gmail.com
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- Gemfile
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
24
|
+
- config.ru
|
24
25
|
- lib/assets/javascripts/opal-spec.rb
|
25
26
|
- lib/assets/javascripts/opal/spec.rb
|
26
27
|
- lib/assets/javascripts/opal/spec/browser_formatter.rb
|
@@ -32,15 +33,16 @@ files:
|
|
32
33
|
- lib/assets/javascripts/opal/spec/phantom_formatter.rb
|
33
34
|
- lib/assets/javascripts/opal/spec/runner.rb
|
34
35
|
- lib/assets/javascripts/opal/spec/scratch_pad.rb
|
36
|
+
- lib/assets/javascripts/opal/spec/sprockets_runner.js.erb
|
35
37
|
- lib/opal-spec.rb
|
36
38
|
- lib/opal/spec.rb
|
37
39
|
- lib/opal/spec/rake_task.rb
|
38
|
-
- lib/opal/spec/
|
40
|
+
- lib/opal/spec/server.rb
|
39
41
|
- lib/opal/spec/version.rb
|
40
42
|
- opal-spec.gemspec
|
41
|
-
- spec/index.html
|
42
43
|
- spec/specs.rb
|
43
|
-
- vendor/
|
44
|
+
- vendor/spec_runner.html.erb
|
45
|
+
- vendor/spec_runner.js
|
44
46
|
homepage: http://opalrb.org
|
45
47
|
licenses: []
|
46
48
|
post_install_message:
|
data/lib/opal/spec/runner.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
module Opal
|
2
|
-
module Spec
|
3
|
-
|
4
|
-
# Run tests on the command line using phantomjs. Phantomjs **must** be
|
5
|
-
# installed, and the runner assumes you have an HTML file at
|
6
|
-
# ./spec/index.html which will be run.
|
7
|
-
def self.runner
|
8
|
-
runner = File.join File.dirname(__FILE__), '..', '..', '..', 'vendor', 'runner.js'
|
9
|
-
system "phantomjs #{runner} spec/index.html"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|