opal-rspec 0.0.1.beta1 → 0.0.1.beta2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed072aad1768de7d20b2cabb9f11f670976874fc
4
- data.tar.gz: 0a4f28128a5b045a1b0b385d2d4ca38b776075d7
3
+ metadata.gz: aa5a0b75048673c565e4c8d0b008dc55892a4ddd
4
+ data.tar.gz: 60bc477892cc5008bca2f1a766ed590d641ead54
5
5
  SHA512:
6
- metadata.gz: 7ab1aad04e561cc0a8c45701b2edde80be2d5ad00cf3d02c60dcd00f21d7684a74f6d57c69ae4081f3eb2d77be7dd5b8a04712ece70d86485ad87c4bb5715958
7
- data.tar.gz: b086f9fff0bdc56e51a4f9a3f8ef858f9af4116cae085f15ddbda6a26cfafd7fb5215219d62395e57acf7844352b7ba350243cb14135e667ac07e414868b932a
6
+ metadata.gz: 0efbf01ddc93b6964063e6837f03d18bb2f59babbf41099e5f659f79350641b3de6f42b88ce6a6a3d7bc6f7405dec54f0c63d557a457cf5524a25561bcb03bd0
7
+ data.tar.gz: 9f616e0e0e61c5f6a0fe77c0dddfbb989d9cc5f617b1349c629d5d157d83ad09df27bf55dade95dd13681c94ffdb68644e158974100eda24ebed6a3f5f73fb57
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .DS_Store
2
2
  Gemfile.lock
3
3
  opal/opal/rspec/rspec.js
4
+ *.gem
data/README.md CHANGED
@@ -35,44 +35,30 @@ Visit the page in any browser and view the console:
35
35
  ## Things to fix
36
36
 
37
37
  `opal/opal-rspec/fixes.rb` contains a few bug fixes that need to be merged upstream
38
- to opal itself. In app/rspec we have to stub various rspec files.
38
+ to opal itself. `app/rspec-builder.rb` is used to precompile rspec ready to be used
39
+ in `opal-rspec`. All requires from `core.rb` have been inlined as opal cannot require
40
+ dynamically at runtime.
39
41
 
40
- ### rspec/core.rb
42
+ ## License
41
43
 
42
- * **line 1**: `require_rspec` to fake require_relative doesnt work at runtime.
43
- opal has to include all dependencies into build.
44
+ (The MIT License)
44
45
 
45
- * **line 90**: heredoc fails to parse in opal as EOS is used within heredoc
46
+ Copyright (C) 2013 by Adam Beynon
46
47
 
47
- * **line 171**: `&::Time.method(:now)` doesnt work so wrong method is set
48
+ Permission is hereby granted, free of charge, to any person obtaining a copy
49
+ of this software and associated documentation files (the "Software"), to deal
50
+ in the Software without restriction, including without limitation the rights
51
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ copies of the Software, and to permit persons to whom the Software is
53
+ furnished to do so, subject to the following conditions:
48
54
 
49
- ### rspec/core/configuration.rb
55
+ The above copyright notice and this permission notice shall be included in
56
+ all copies or substantial portions of the Software.
50
57
 
51
- * **line ?**: something in that file is causing opal to generate bad javascript.
52
- This is possible a require statement used as an expression which generates empty
53
- code.
54
-
55
- ### rspec/core/example_group.rb
56
-
57
- * **line 434**: cannot parse heredoc as it uses EOS inline before string ends
58
-
59
- * **line 547**: opal cannot use mutable strings (see opal/rspec/fixes.rb)
60
-
61
- * **line 564**: opal cannot use mutable strings (see opal/rspec/fixes.rb)
62
-
63
- ### rspec/core/project_initializer.rb
64
-
65
- * **line 1**: opal cannot parse these heredocs (EOS used before last line of string)
66
-
67
- ### rspec/core/shared_example_group.rb
68
-
69
- * **line 112**: opal cannot parse this heredoc
70
-
71
- ### rspec/core/shared_example_group/collection.rb
72
-
73
- * **line 17**: opal cannot parse command call inside aref
74
-
75
- ### rspec/matchers/built_in/have.rb
76
-
77
- * **line 1**: this is an error in rspec. This autoload does not exist so we must
78
- stub the file.
58
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64
+ THE SOFTWARE.
data/Rakefile CHANGED
@@ -31,6 +31,9 @@ def build_rspec
31
31
  Opal::Processor.stub_file asset
32
32
  end
33
33
 
34
+ # bug in rspec? this autoload doesnt exist so we must stub it
35
+ Opal::Processor.stub_file 'rspec/matchers/built_in/have'
36
+
34
37
  Opal.process('rspec-builder')
35
38
  end
36
39
 
data/app/rspec-builder.rb CHANGED
@@ -1,6 +1,37 @@
1
+ require 'set'
2
+ require 'time'
3
+ require 'rbconfig'
4
+
1
5
  require 'rspec/support'
6
+
7
+ require 'rspec/core/version'
8
+
9
+ require 'rspec/support/caller_filter'
10
+
11
+ require 'rspec/core/flat_map'
12
+ require 'rspec/core/filter_manager'
13
+ require 'rspec/core/dsl'
14
+ require 'rspec/core/warnings'
15
+ require 'rspec/core/reporter'
16
+
17
+ require 'rspec/core/hooks'
18
+ require 'rspec/core/memoized_helpers'
19
+ require 'rspec/core/metadata'
20
+ require 'rspec/core/pending'
21
+ require 'rspec/core/formatters'
22
+ require 'rspec/core/ordering'
23
+
24
+ require 'rspec/core/world'
25
+ require 'rspec/core/configuration'
26
+ require 'rspec/core/option_parser'
27
+ require 'rspec/core/configuration_options'
28
+ require 'rspec/core/command_line'
29
+ require 'rspec/core/runner'
30
+ require 'rspec/core/example'
31
+ require 'rspec/core/shared_example_group/collection'
32
+ require 'rspec/core/shared_example_group'
33
+ require 'rspec/core/example_group'
2
34
  require 'rspec/core'
3
- require 'rspec/mocks'
4
35
  require 'rspec-expectations'
5
36
 
6
37
  # we want access to BaseFormatter
@@ -1,6 +1,6 @@
1
1
  module Opal
2
2
  module RSpec
3
- VERSION = '0.0.1.beta1'
3
+ VERSION = '0.0.1.beta2'
4
4
  end
5
5
  end
6
6
 
@@ -0,0 +1,129 @@
1
+ module Opal
2
+ module RSpec
3
+ module AsyncDefinitions
4
+ def async(desc, *args, &block)
5
+ options = ::RSpec::Core::Metadata.build_hash_from(args)
6
+ Opal::RSpec::AsyncExample.register(self, desc, options, block)
7
+ end
8
+ end
9
+
10
+ module AsyncHelpers
11
+ def run_async(&block)
12
+ ::RSpec.current_example.continue_async(block)
13
+ end
14
+
15
+ def set_timeout(duration, &block)
16
+ `setTimeout(block, duration)`
17
+ self
18
+ end
19
+ end
20
+
21
+ class AsyncRunner
22
+ def initialize(runner, reporter, finish_block)
23
+ @runner = runner
24
+ @reporter = reporter
25
+ @finish_block = finish_block
26
+ end
27
+
28
+ def run
29
+ @examples = AsyncExample.examples.clone
30
+ run_next_example
31
+ end
32
+
33
+ def run_next_example
34
+ if @examples.empty?
35
+ finish
36
+ else
37
+ run_example @examples.pop
38
+ end
39
+ end
40
+
41
+ def run_example(example)
42
+ example_group = example.example_group
43
+
44
+ @reporter.example_group_started example_group
45
+ instance = example_group.new
46
+
47
+ example.run(instance, @reporter) do
48
+ example_finished example
49
+ end
50
+ end
51
+
52
+ def example_finished(example)
53
+ @reporter.example_group_finished example.example_group
54
+ run_next_example
55
+ end
56
+
57
+ # Called once all examples have finished. Just calls back to main
58
+ # runner to inform it
59
+ def finish
60
+ @finish_block.call
61
+ end
62
+ end
63
+
64
+ class AsyncExample < ::RSpec::Core::Example
65
+ def self.register(*args)
66
+ examples << new(*args)
67
+ end
68
+
69
+ def self.examples
70
+ @examples ||= []
71
+ end
72
+
73
+ def run(example_group_instance, reporter, &after_run_block)
74
+ @example_group_instance = example_group_instance
75
+ @reporter = reporter
76
+ @after_run_block = after_run_block
77
+
78
+ should_wait = true
79
+
80
+ ::RSpec.current_example = self
81
+
82
+ start(reporter)
83
+
84
+ begin
85
+ run_before_each
86
+ @example_group_instance.instance_exec(self, &@example_block)
87
+ rescue Exception => e
88
+ set_exception(e)
89
+ should_wait = false
90
+ end
91
+
92
+ async_example_finished unless should_wait
93
+ end
94
+
95
+ def continue_async(block)
96
+ begin
97
+ block.call
98
+ rescue Exception => e
99
+ set_exception(e)
100
+ end
101
+
102
+ async_example_finished
103
+ end
104
+
105
+ def async_example_finished
106
+ begin
107
+ run_after_each
108
+ rescue Exception => e
109
+ set_exception(e)
110
+ ensure
111
+ @example_group_instance.instance_variables.each do |ivar|
112
+ @example_group_instance.instance_variable_set(ivar, nil)
113
+ end
114
+ @example_group_instance = nil
115
+
116
+ begin
117
+ assign_generated_description
118
+ rescue Exception => e
119
+ set_exception(e, "while assigning the example description")
120
+ end
121
+ end
122
+
123
+ finish(@reporter)
124
+ ::RSpec.current_example = nil
125
+ @after_run_block.call
126
+ end
127
+ end
128
+ end
129
+ end
@@ -31,6 +31,7 @@ class RSpec::Matchers::BuiltIn::BePredicate
31
31
  end
32
32
 
33
33
  module RSpec::ExampleGroups
34
+ # opal cannot use mutable strings AND opal doesnt support `\A` or `\z` anchors
34
35
  def self.base_name_for(group)
35
36
  return "Anonymous" if group.description.empty?
36
37
 
@@ -43,11 +44,12 @@ module RSpec::ExampleGroups
43
44
 
44
45
  # Ruby requires first const letter to be A-Z. Use `Nested`
45
46
  # as necessary to enforce that.
46
- name = name.gsub(/\A([^A-Z]|\z)/, 'Nested$1')
47
+ name = name.gsub(/^([^A-Z]|$)/, 'Nested$1')
47
48
 
48
49
  name
49
50
  end
50
51
 
52
+ # opal cannot use mutable strings
51
53
  def self.disambiguate(name, const_scope)
52
54
  return name unless const_scope.const_defined?(name)
53
55