opal-spec 0.2.13 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,16 +23,6 @@ describe MyClass do
23
23
  end
24
24
  ```
25
25
 
26
- ### Running specs
27
-
28
- Loading these specs in a browser won't just work. You need to run them.
29
- The best place to do this is inside `spec/spec_helper.rb`, and with a
30
- simple call:
31
-
32
- ```ruby
33
- Opal::Spec::Runner.autorun
34
- ```
35
-
36
26
  ### Async examples
37
27
 
38
28
  Examples can be async, and need to be defined as so:
data/Rakefile CHANGED
@@ -2,4 +2,6 @@ require 'bundler'
2
2
  Bundler.require
3
3
 
4
4
  require 'opal/spec/rake_task'
5
- Opal::Spec::RakeTask.new(:default)
5
+ Opal::Spec::RakeTask.new(:default) do |s|
6
+ # ..
7
+ end
data/config.ru CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
- require 'opal/spec/server'
5
- run Opal::Spec::Server.new
4
+ run Opal::Server.new { |s|
5
+ s.main = 'opal/spec/sprockets_runner'
6
+ s.append_path 'spec'
7
+ s.debug = false
8
+ }
@@ -0,0 +1,12 @@
1
+ module OpalTest
2
+ module Assertions
3
+
4
+ def assert(test, msg = "Failed assertion, no message given.")
5
+ unless test
6
+ msg = msg.call if Proc === msg
7
+ raise ExpectationNotMetError, msg
8
+ end
9
+ true
10
+ end
11
+ end
12
+ end
@@ -1,6 +1,6 @@
1
1
  module OpalTest
2
2
  class BrowserFormatter
3
- CSS = <<-EOS
3
+ CSS = <<-CSS
4
4
 
5
5
  body {
6
6
  font-size: 14px;
@@ -48,7 +48,7 @@ module OpalTest
48
48
  .examples {
49
49
  list-style-type: none;
50
50
  }
51
- EOS
51
+ CSS
52
52
 
53
53
  def initialize
54
54
  @examples = []
@@ -1,10 +1,10 @@
1
- # This file is used by Opal::Spec::Server to basically load all spec files that
1
+ # This file is used by Opal::Server to basically load all spec files that
2
2
  # can be found in the spec/ directory.
3
3
 
4
4
  <% require_asset 'opal' %>
5
5
  <% require_asset 'opal-spec' %>
6
6
 
7
- <% Dir.glob('spec/**/*.{rb,opal}').each do |s| %>
7
+ <% Dir.glob('spec/**/*_spec.{rb,opal}').each do |s| %>
8
8
  <% require_asset s.sub(/^spec\//, '').sub(/\.(rb|opal)$/, '') %>
9
9
  <% end %>
10
10
 
@@ -1,5 +1,8 @@
1
+ require 'opal/spec/assertions'
2
+
1
3
  module OpalTest
2
4
  class TestCase
5
+ include Assertions
3
6
 
4
7
  def self.test_cases
5
8
  @test_cases ||= []
@@ -1,30 +1,34 @@
1
1
  require 'opal/spec'
2
- require 'opal/spec/server'
3
2
 
4
3
  module Opal
5
4
  module Spec
6
5
  class RakeTask
7
6
  include Rake::DSL if defined? Rake::DSL
8
7
 
9
- attr_accessor :name
8
+ RUNNER = File.expand_path('../../../../vendor/spec_runner.js', __FILE__)
9
+ PORT = 9999
10
+ URL = "http://localhost:9999/"
10
11
 
11
- def initialize(name = 'opal:spec')
12
- @name = name
13
- define_tasks
14
- end
15
-
16
- def define_tasks
12
+ def initialize(name = 'opal:test', &block)
17
13
  desc "Run opal specs in phantomjs"
18
- task @name do
14
+ task name do
19
15
  require 'rack'
20
16
  require 'webrick'
21
17
 
22
18
  server = fork do
23
- Rack::Server.start(:app => Opal::Spec::Server.new(false), :Port => port,
24
- :Logger => WEBrick::Log.new("/dev/null"), :AccessLog => [])
19
+ s = Opal::Server.new { |s|
20
+ s.main = 'opal/spec/sprockets_runner'
21
+ s.append_path 'spec'
22
+ s.debug = false
23
+
24
+ block.call s if block
25
+ }
26
+
27
+ Rack::Server.start(:app => s, :Port => PORT, :AccessLog => [],
28
+ :Logger => WEBrick::Log.new("/dev/null"))
25
29
  end
26
30
 
27
- system "phantomjs #{runner_path} \"#{url_path}\""
31
+ system "phantomjs #{RUNNER} \"#{URL}\""
28
32
  success = $?.success?
29
33
 
30
34
  Process.kill(:SIGINT, server)
@@ -33,18 +37,6 @@ module Opal
33
37
  exit 1 unless success
34
38
  end
35
39
  end
36
-
37
- def runner_path
38
- File.join(VENDOR_PATH, 'spec_runner.js')
39
- end
40
-
41
- def url_path
42
- "http://localhost:9999/"
43
- end
44
-
45
- def port
46
- 9999
47
- end
48
40
  end
49
41
  end
50
42
  end
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Spec
3
- VERSION = '0.2.13'
3
+ VERSION = '0.2.14'
4
4
  end
5
5
  end
data/lib/opal/spec.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  require 'opal'
2
2
  require 'opal/spec/version'
3
3
 
4
- module Opal
5
- module Spec
6
- VENDOR_PATH = File.join(File.dirname(__FILE__), '..', '..', 'vendor')
7
- end
8
- end
9
-
10
4
  # Just register our opal code path with opal build tools
11
5
  Opal.append_path File.join(File.dirname(__FILE__), '..', 'assets', 'javascripts')
@@ -107,3 +107,11 @@ describe "pending" do
107
107
  raise "otherwise this error would be raised"
108
108
  end
109
109
  end
110
+
111
+ describe "A nested group" do
112
+ describe "inherits group names" do
113
+ it "examples should pass" do
114
+ 1.should eq(1)
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,17 @@
1
+ class SimpleTest < OpalTest::TestCase
2
+ def test_this_should_be_tested
3
+ :pass.should eq(:pass)
4
+ end
5
+
6
+ def test_should_also_pass
7
+ 1.should == 1
8
+ end
9
+
10
+ def test_simple_assertion
11
+ assert true
12
+ assert 42
13
+
14
+ lambda { assert nil }.should raise_error(Exception)
15
+ lambda { assert false }.should raise_error(Exception)
16
+ end
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.13
4
+ version: 0.2.14
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-23 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Opal compatible spec library
15
15
  email: adam.beynon@gmail.com
@@ -25,6 +25,7 @@ files:
25
25
  - config.ru
26
26
  - lib/assets/javascripts/opal-spec.rb
27
27
  - lib/assets/javascripts/opal/spec.rb
28
+ - lib/assets/javascripts/opal/spec/assertions.rb
28
29
  - lib/assets/javascripts/opal/spec/browser_formatter.rb
29
30
  - lib/assets/javascripts/opal/spec/expectations.rb
30
31
  - lib/assets/javascripts/opal/spec/kernel.rb
@@ -41,13 +42,12 @@ files:
41
42
  - lib/opal-spec.rb
42
43
  - lib/opal/spec.rb
43
44
  - lib/opal/spec/rake_task.rb
44
- - lib/opal/spec/server.rb
45
45
  - lib/opal/spec/version.rb
46
46
  - opal-spec.gemspec
47
47
  - spec/matchers/be_empty_spec.rb
48
48
  - spec/matchers/respond_to_spec.rb
49
- - spec/specs.rb
50
- - spec/tests.rb
49
+ - spec/specs_spec.rb
50
+ - spec/tests_spec.rb
51
51
  - vendor/spec_runner.js
52
52
  homepage: http://opalrb.org
53
53
  licenses: []
@@ -1,23 +0,0 @@
1
- require 'opal/spec'
2
- require 'opal'
3
-
4
- module Opal
5
- module Spec
6
-
7
- # Custom Opal::Server subclass which adds the 'spec' dir as a
8
- # directory for testing (adds to load path). Specs run through this
9
- # server are not run in debug mode (all scripts loaded in a single
10
- # file). This can be overriden in the supplied block.
11
- class Server < Opal::Server
12
- def initialize(*args, &block)
13
- super(*args) do |s|
14
- s.append_path 'spec'
15
- s.main = 'opal/spec/sprockets_runner'
16
- s.debug = false
17
-
18
- yield s if block_given?
19
- end
20
- end
21
- end
22
- end
23
- end
data/spec/tests.rb DELETED
@@ -1,9 +0,0 @@
1
- class SimpleTest < OpalTest::TestCase
2
- def test_this_should_be_tested
3
- :pass.should eq(:pass)
4
- end
5
-
6
- def test_should_also_pass
7
- 1.should == 1
8
- end
9
- end