opal-spec 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,80 +1,78 @@
1
- module Opal
2
- module Spec
3
- class Runner
4
- def self.in_browser?
5
- %x{
6
- if (typeof(window) !== 'undefined' && typeof(document) !== 'undefined') {
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
- def self.in_phantom?
15
- %x{
16
- if (typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined') {
17
- return true;
18
- }
9
+ return false;
10
+ }
11
+ end
19
12
 
20
- return false;
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
- def self.autorun
25
- if in_browser?
26
- %x{
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
- def initialize
37
- if Runner.in_phantom?
38
- @formatter = PhantomFormatter.new
39
- elsif Runner.in_browser?
40
- @formatter = BrowserFormatter.new
41
- end
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
- def run
45
- @groups = ExampleGroup.example_groups.dup
46
- @formatter.start
47
- run_next_group
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
- def run_next_group
51
- if @groups.empty?
52
- @formatter.finish
53
- else
54
- @groups.shift.run self
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
- def example_group_started group
59
- @formatter.example_group_started group
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
- def example_group_finished group
63
- @formatter.example_group_finished group
64
- run_next_group
65
- end
57
+ def example_group_started group
58
+ @formatter.example_group_started group
59
+ end
66
60
 
67
- def example_started example
68
- @formatter.example_started example
69
- end
61
+ def example_group_finished group
62
+ @formatter.example_group_finished group
63
+ run_next_group
64
+ end
70
65
 
71
- def example_passed example
72
- @formatter.example_passed example
73
- end
66
+ def example_started example
67
+ @formatter.example_started example
68
+ end
74
69
 
75
- def example_failed example
76
- @formatter.example_failed example
77
- end
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
- # Compatibility with older versions
13
- OpalSpec = Opal::Spec
13
+ module Opal
14
+ # Compatibility with older versions
15
+ Spec = ::Spec
16
+ end
@@ -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(:config => 'config.ru', :Port => port,
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(File.dirname(__FILE__), '..', '..', '..', 'vendor', 'runner.js')
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
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Spec
3
- VERSION = '0.2.8'
3
+ VERSION = '0.2.9'
4
4
  end
5
5
  end
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
- # Compatibility with old namespace
6
- OpalSpec = Opal::Spec
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(1000) do
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(1000) do
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
  }
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>opal-spec</title>
5
+ </head>
6
+ <body>
7
+ <%= javascript_include_tag 'opal/spec/sprockets_runner' %>
8
+ </body>
9
+ </html>
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.8
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-08 00:00:00.000000000 Z
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/runner.rb
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/runner.js
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:
@@ -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
data/spec/index.html DELETED
@@ -1,9 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>opal-spec specs</title>
5
- </head>
6
- <body>
7
- <script src="../build/specs.js"></script>
8
- </body>
9
- </html>