opal-spec 0.2.10 → 0.3.2

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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -5
  3. data/README.md +33 -41
  4. data/config.ru +5 -2
  5. data/example/Gemfile +4 -0
  6. data/example/README.md +8 -0
  7. data/example/Rakefile +10 -0
  8. data/example/opal/stack.rb +2 -0
  9. data/example/spec/spec_helper.rb +2 -0
  10. data/example/spec/stack_spec.rb +17 -0
  11. data/lib/opal/spec/rake_task.rb +17 -24
  12. data/lib/opal/spec/version.rb +1 -1
  13. data/lib/opal/spec.rb +1 -7
  14. data/opal/opal/spec/browser_formatter.rb +218 -0
  15. data/opal/opal/spec/expectations.rb +128 -0
  16. data/opal/opal/spec/matchers.rb +61 -0
  17. data/opal/opal/spec/object.rb +21 -0
  18. data/{lib/assets/javascripts → opal}/opal/spec/phantom_formatter.rb +6 -6
  19. data/{lib/assets/javascripts → opal}/opal/spec/runner.rb +6 -21
  20. data/opal/opal/spec/spec.rb +185 -0
  21. data/{lib/assets/javascripts → opal}/opal/spec/sprockets_runner.rb.erb +3 -3
  22. data/{lib/assets/javascripts → opal}/opal/spec.rb +3 -5
  23. data/opal-spec.gemspec +5 -0
  24. data/spec/matchers/be_empty_spec.rb +9 -0
  25. data/spec/matchers/respond_to_spec.rb +15 -0
  26. data/spec/specs_spec.rb +149 -0
  27. metadata +69 -25
  28. data/lib/assets/javascripts/opal/spec/browser_formatter.rb +0 -192
  29. data/lib/assets/javascripts/opal/spec/example.rb +0 -76
  30. data/lib/assets/javascripts/opal/spec/example_group.rb +0 -92
  31. data/lib/assets/javascripts/opal/spec/expectations.rb +0 -54
  32. data/lib/assets/javascripts/opal/spec/kernel.rb +0 -9
  33. data/lib/assets/javascripts/opal/spec/matchers.rb +0 -104
  34. data/lib/assets/javascripts/opal/spec/scratch_pad.rb +0 -17
  35. data/lib/opal/spec/server.rb +0 -63
  36. data/spec/specs.rb +0 -73
  37. data/vendor/spec_runner.html.erb +0 -9
  38. /data/{lib/assets/javascripts → opal}/opal-spec.rb +0 -0
@@ -1,4 +1,4 @@
1
- module Spec
1
+ module OpalSpec
2
2
  class PhantomFormatter
3
3
  def initialize
4
4
  @examples = []
@@ -34,7 +34,7 @@ module Spec
34
34
 
35
35
  exception = example.exception
36
36
  case exception
37
- when Spec::ExpectationNotMetError
37
+ when OpalSpec::ExpectationNotMetError
38
38
  output = exception.message
39
39
  else
40
40
  output = "#{exception.class.name}: #{exception.message}\n"
@@ -48,14 +48,14 @@ module Spec
48
48
  finish_with_code(1)
49
49
  end
50
50
  end
51
-
51
+
52
52
  def finish_with_code(code)
53
53
  %x{
54
- if (typeof(phantom) !== 'undefined') {
55
- return phantom.exit(code);
54
+ if (typeof(phantom) !== "undefined") {
55
+ phantom.exit(code);
56
56
  }
57
57
  else {
58
- window.OPAL_SPEC_CODE = code;
58
+ Opal.global.OPAL_SPEC_CODE = code;
59
59
  }
60
60
  }
61
61
  end
@@ -1,32 +1,17 @@
1
- module Spec
1
+ module OpalSpec
2
2
  class Runner
3
3
  def self.in_browser?
4
- %x{
5
- if (typeof(window) !== 'undefined' && typeof(document) !== 'undefined') {
6
- return true;
7
- }
8
-
9
- return false;
10
- }
4
+ $global[:document]
5
+ `typeof(document) !== 'undefined'`
11
6
  end
12
7
 
13
8
  def self.in_phantom?
14
- %x{
15
- if (typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined') {
16
- return true;
17
- }
18
-
19
- return false;
20
- }
9
+ `typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined'`
21
10
  end
22
11
 
23
12
  def self.autorun
24
13
  if in_browser?
25
- %x{
26
- setTimeout(function() {
27
- #{ Runner.new.run };
28
- }, 0);
29
- }
14
+ `setTimeout(function() { #{ Runner.new.run } }, 0)`
30
15
  else
31
16
  Runner.new.run
32
17
  end
@@ -41,7 +26,7 @@ module Spec
41
26
  end
42
27
 
43
28
  def run
44
- @groups = ExampleGroup.example_groups.dup
29
+ @groups = Example.groups.dup
45
30
  @formatter.start
46
31
  run_next_group
47
32
  end
@@ -0,0 +1,185 @@
1
+ module OpalSpec
2
+ class Example
3
+ include Expectations
4
+
5
+ def self.groups
6
+ @groups ||= []
7
+ end
8
+
9
+ def self.stack
10
+ @stack ||= []
11
+ end
12
+
13
+ def self.create(desc, block)
14
+ stack = Example.stack
15
+ parent = stack.last
16
+
17
+ group = Class.new(parent || Example) do
18
+ @desc = desc
19
+ @parent = parent
20
+ @examples = []
21
+ @before_hooks = []
22
+ @after_hooks = []
23
+ end
24
+
25
+ Example.groups << group
26
+ stack << group
27
+ group.class_eval(&block)
28
+ stack.pop
29
+
30
+ group
31
+ end
32
+
33
+ def self.description
34
+ @parent ? "#{@parent.description} #{@desc}" : @desc
35
+ end
36
+
37
+ def self.it desc, &block
38
+ @examples << [desc, block]
39
+ end
40
+
41
+ def self.async(desc, &block)
42
+ self.it desc do
43
+ self.async!
44
+ instance_eval(&block)
45
+ end
46
+ end
47
+
48
+ def self.pending(*); end
49
+
50
+ def self.let(name, &block)
51
+ define_method(name) do
52
+ @_memoized ||= {}
53
+ @_memoized.fetch(name) { |n| @_memoized[n] = instance_eval(&block) }
54
+ end
55
+ end
56
+
57
+ def self.subject(&block)
58
+ let(:subject, &block)
59
+ end
60
+
61
+ def self.before(type = nil, &block)
62
+ @before_hooks << block
63
+ end
64
+
65
+ def self.after(type = nil, &block)
66
+ @after_hooks << block
67
+ end
68
+
69
+ def self.run runner
70
+ @runner = runner
71
+ @runner.example_group_started self
72
+
73
+ @running_examples = @examples ? @examples.dup : []
74
+ run_next_example
75
+ end
76
+
77
+ def self.run_next_example
78
+ if @running_examples.empty?
79
+ @runner.example_group_finished self
80
+ else
81
+ new(@running_examples.shift).run @runner
82
+ end
83
+ end
84
+
85
+ def self.example_started example
86
+ @runner.example_started example
87
+ end
88
+
89
+ def self.example_passed example
90
+ @runner.example_passed example
91
+ run_next_example
92
+ end
93
+
94
+ def self.example_failed example
95
+ @runner.example_failed example
96
+ run_next_example
97
+ end
98
+
99
+ def self.after_hooks
100
+ @parent ? @parent.after_hooks + @after_hooks : @after_hooks
101
+ end
102
+
103
+ def self.before_hooks
104
+ @parent ? @parent.before_hooks + @before_hooks : @before_hooks
105
+ end
106
+
107
+ attr_reader :example_group, :exception
108
+
109
+ def initialize info
110
+ @description = info[0]
111
+ @__block__ = info[1]
112
+ @example_group = self.class
113
+ end
114
+
115
+ def description
116
+ @description
117
+ end
118
+
119
+ def async!
120
+ @asynchronous = true
121
+ end
122
+
123
+ def run runner
124
+ @runner = runner
125
+ begin
126
+ @example_group.example_started self
127
+ run_before_hooks
128
+ instance_eval(&@__block__)
129
+ rescue => e
130
+ @exception = e
131
+ ensure
132
+ unless @asynchronous
133
+ run_after_hooks
134
+ end
135
+ end
136
+
137
+ if @asynchronous
138
+ # must wait..
139
+ else
140
+ finish_running
141
+ end
142
+ end
143
+
144
+ def finish_running
145
+ if @exception
146
+ @example_group.example_failed self
147
+ else
148
+ @example_group.example_passed self
149
+ end
150
+ end
151
+
152
+ def run_before_hooks
153
+ @example_group.before_hooks.each do |before|
154
+ instance_eval(&before)
155
+ end
156
+ end
157
+
158
+ def run_after_hooks
159
+ begin
160
+ @example_group.after_hooks.each do |after|
161
+ instance_eval(&after)
162
+ end
163
+ rescue => e
164
+ @exception = e
165
+ end
166
+ end
167
+
168
+ def run_async(&block)
169
+ begin
170
+ block.call
171
+ rescue => e
172
+ @exception = e
173
+ ensure
174
+ run_after_hooks
175
+ end
176
+
177
+ finish_running
178
+ end
179
+
180
+ def set_timeout(duration, &block)
181
+ `setTimeout(#{block}, #{duration})`
182
+ self
183
+ end
184
+ end
185
+ end
@@ -1,11 +1,11 @@
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
 
11
- Spec::Runner.autorun
11
+ OpalSpec::Runner.autorun
@@ -1,15 +1,13 @@
1
1
  require 'opal'
2
2
 
3
- require 'opal/spec/example'
4
- require 'opal/spec/example_group'
5
3
  require 'opal/spec/matchers'
6
4
  require 'opal/spec/runner'
7
- require 'opal/spec/scratch_pad'
8
5
  require 'opal/spec/expectations'
6
+ require 'opal/spec/spec'
9
7
  require 'opal/spec/browser_formatter'
10
8
  require 'opal/spec/phantom_formatter'
11
- require 'opal/spec/kernel'
9
+ require 'opal/spec/object'
12
10
 
13
11
  module Opal
14
- Spec = ::Spec # Compatibility with older versions
12
+ Spec = OpalSpec # compatibility
15
13
  end
data/opal-spec.gemspec CHANGED
@@ -12,4 +12,9 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.require_paths = ['lib']
15
+
16
+ s.add_dependency 'opal', '~> 0.5.0'
17
+ s.add_dependency 'opal-sprockets', '~> 0.3.0'
18
+
19
+ s.add_development_dependency 'rake'
15
20
  end
@@ -0,0 +1,9 @@
1
+ describe "be_empty" do
2
+ it "should pass if the object is empty?" do
3
+ [].should be_empty
4
+ end
5
+
6
+ it "should fail if the object is not empty?" do
7
+ lambda { [1].should be_empty }.should raise_error(Exception)
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ class RespondToSpecs
2
+ def foo; end
3
+ end
4
+
5
+ describe "respond_to" do
6
+ it "should pass if the object responds to method" do
7
+ RespondToSpecs.new.should respond_to(:foo)
8
+ end
9
+
10
+ it "should fail if the object does not respond to method" do
11
+ lambda {
12
+ RespondToSpecs.new.should respond_to(:bar)
13
+ }.should raise_error(Exception)
14
+ end
15
+ end
@@ -0,0 +1,149 @@
1
+ describe "PositiveOperatorMatcher" do
2
+ it "matches should operators" do
3
+ 1.should == 1
4
+ end
5
+
6
+ it "matches negative operators" do
7
+ 1.should_not == 2
8
+ end
9
+ end
10
+
11
+ describe 'Normal group' do
12
+ it 'exceptions can be thrown' do
13
+ err = nil
14
+
15
+ begin
16
+ 1.should == 2
17
+ rescue Exception => e
18
+ err = e
19
+ end
20
+
21
+ raise "exception not thrown" unless err
22
+ end
23
+ end
24
+
25
+ describe "New eql" do
26
+ it "these should both pass" do
27
+ 1.should eq(1)
28
+ 1.should_not eq(2)
29
+ end
30
+
31
+ it "and this should fail" do
32
+ lambda { 1.should eq(:adam) }.should raise_error(Exception)
33
+ end
34
+ end
35
+
36
+ describe Object do
37
+ it "should output a nice name for classes" do
38
+ 1.should eq(1)
39
+ end
40
+ end
41
+
42
+ describe 'Another group' do
43
+ it 'this should pass' do
44
+ 1.should == 1
45
+ end
46
+
47
+ it 'this should pass' do
48
+ true.should be_true
49
+ false.should be_false
50
+ nil.should be_nil
51
+ end
52
+
53
+ async 'this should pass (in 0.1 second time)' do
54
+ set_timeout(100) do
55
+ run_async {
56
+ 1.should == 1
57
+ }
58
+ end
59
+ end
60
+
61
+ async 'this should fail (in 0.1 second time)' do
62
+ set_timeout(100) do
63
+ run_async {
64
+ lambda { 1.should == 5 }.should raise_error(Exception)
65
+ }
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "let" do
71
+ $opal_spec_let_count = 0
72
+
73
+ let(:count) { $opal_spec_let_count = $opal_spec_let_count + 1 }
74
+
75
+ it "caches the method for the example" do
76
+ count.should eq(1)
77
+ count.should eq(1)
78
+ end
79
+
80
+ it "does not cache values between different examples" do
81
+ count.should eq(2)
82
+ end
83
+ end
84
+
85
+ describe "before" do
86
+ before do
87
+ @foo = 100
88
+ end
89
+
90
+ before do
91
+ @bar = 200
92
+ end
93
+
94
+ it "should be run before each group" do
95
+ @foo.should == 100
96
+ end
97
+
98
+ it "should run multiple before blocks" do
99
+ @bar.should == 200
100
+ end
101
+
102
+ describe "nested" do
103
+ before { @nested = 300 }
104
+
105
+ it "should inherit before blocks" do
106
+ @foo.should eq(100)
107
+ end
108
+
109
+ it "should also run nested before blocks" do
110
+ @nested.should eq(300)
111
+ end
112
+ end
113
+ end
114
+
115
+ describe "pending" do
116
+ pending "these tests are not run" do
117
+ raise "otherwise this error would be raised"
118
+ end
119
+ end
120
+
121
+ describe "A nested group" do
122
+ describe "inherits group names" do
123
+ it "examples should pass" do
124
+ 1.should eq(1)
125
+ end
126
+ end
127
+ end
128
+
129
+ OpalSpec.matcher :custom_matcher do
130
+ def match expected
131
+ unless expected == 42
132
+ failure "foo"
133
+ end
134
+ end
135
+ end
136
+
137
+ describe "Custom Matchers" do
138
+ it "is defined in spec scope" do
139
+ respond_to?(:custom_matcher).should be_true
140
+ end
141
+
142
+ it "passes the expected value to the matcher" do
143
+ 42.should custom_matcher
144
+ end
145
+
146
+ it "can raise error when not maching expectation" do
147
+ lambda { 43.should custom_matcher }.should raise_error(Exception)
148
+ end
149
+ end if false
metadata CHANGED
@@ -1,16 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
5
- prerelease:
4
+ version: 0.3.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Beynon
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-16 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: opal-sprockets
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
14
55
  description: Opal compatible spec library
15
56
  email: adam.beynon@gmail.com
16
57
  executables: []
@@ -22,49 +63,52 @@ files:
22
63
  - README.md
23
64
  - Rakefile
24
65
  - config.ru
25
- - lib/assets/javascripts/opal-spec.rb
26
- - lib/assets/javascripts/opal/spec.rb
27
- - lib/assets/javascripts/opal/spec/browser_formatter.rb
28
- - lib/assets/javascripts/opal/spec/example.rb
29
- - lib/assets/javascripts/opal/spec/example_group.rb
30
- - lib/assets/javascripts/opal/spec/expectations.rb
31
- - lib/assets/javascripts/opal/spec/kernel.rb
32
- - lib/assets/javascripts/opal/spec/matchers.rb
33
- - lib/assets/javascripts/opal/spec/phantom_formatter.rb
34
- - lib/assets/javascripts/opal/spec/runner.rb
35
- - lib/assets/javascripts/opal/spec/scratch_pad.rb
36
- - lib/assets/javascripts/opal/spec/sprockets_runner.rb.erb
66
+ - example/Gemfile
67
+ - example/README.md
68
+ - example/Rakefile
69
+ - example/opal/stack.rb
70
+ - example/spec/spec_helper.rb
71
+ - example/spec/stack_spec.rb
37
72
  - lib/opal-spec.rb
38
73
  - lib/opal/spec.rb
39
74
  - lib/opal/spec/rake_task.rb
40
- - lib/opal/spec/server.rb
41
75
  - lib/opal/spec/version.rb
42
76
  - opal-spec.gemspec
43
- - spec/specs.rb
44
- - vendor/spec_runner.html.erb
77
+ - opal/opal-spec.rb
78
+ - opal/opal/spec.rb
79
+ - opal/opal/spec/browser_formatter.rb
80
+ - opal/opal/spec/expectations.rb
81
+ - opal/opal/spec/matchers.rb
82
+ - opal/opal/spec/object.rb
83
+ - opal/opal/spec/phantom_formatter.rb
84
+ - opal/opal/spec/runner.rb
85
+ - opal/opal/spec/spec.rb
86
+ - opal/opal/spec/sprockets_runner.rb.erb
87
+ - spec/matchers/be_empty_spec.rb
88
+ - spec/matchers/respond_to_spec.rb
89
+ - spec/specs_spec.rb
45
90
  - vendor/spec_runner.js
46
91
  homepage: http://opalrb.org
47
92
  licenses: []
93
+ metadata: {}
48
94
  post_install_message:
49
95
  rdoc_options: []
50
96
  require_paths:
51
97
  - lib
52
98
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
99
  requirements:
55
- - - ! '>='
100
+ - - '>='
56
101
  - !ruby/object:Gem::Version
57
102
  version: '0'
58
103
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
104
  requirements:
61
- - - ! '>='
105
+ - - '>='
62
106
  - !ruby/object:Gem::Version
63
107
  version: '0'
64
108
  requirements: []
65
109
  rubyforge_project:
66
- rubygems_version: 1.8.23
110
+ rubygems_version: 2.1.9
67
111
  signing_key:
68
- specification_version: 3
112
+ specification_version: 4
69
113
  summary: Opal compatible spec
70
114
  test_files: []