opal 0.6.3 → 0.7.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.spectator +2 -0
  4. data/.spectator-mspec +3 -0
  5. data/.travis.yml +8 -11
  6. data/CHANGELOG.md +33 -0
  7. data/CONTRIBUTING.md +8 -43
  8. data/Gemfile +15 -4
  9. data/Guardfile +77 -0
  10. data/README.md +15 -9
  11. data/Rakefile +36 -12
  12. data/benchmarks/operators.rb +11 -0
  13. data/bin/opal +10 -13
  14. data/bin/opal-build +4 -4
  15. data/bin/opal-mspec +10 -0
  16. data/bin/opal-repl +4 -3
  17. data/examples/sinatra/Gemfile +1 -1
  18. data/examples/sinatra/config.ru +3 -3
  19. data/lib/mspec/opal/main.rb.erb +2 -2
  20. data/lib/mspec/opal/rake_task.rb +31 -24
  21. data/lib/mspec/opal/runner.rb +18 -1
  22. data/lib/mspec/opal/sprockets.js +17 -0
  23. data/lib/opal.rb +1 -34
  24. data/lib/opal/builder.rb +92 -58
  25. data/lib/opal/builder_processors.rb +165 -0
  26. data/lib/opal/cli.rb +85 -144
  27. data/lib/opal/cli_options.rb +136 -90
  28. data/lib/opal/cli_runners.rb +10 -0
  29. data/lib/opal/cli_runners/nodejs.rb +56 -0
  30. data/lib/opal/cli_runners/phantom.js +35 -0
  31. data/lib/opal/cli_runners/phantomjs.rb +28 -0
  32. data/lib/opal/cli_runners/server.rb +54 -0
  33. data/lib/opal/compiler.rb +35 -16
  34. data/lib/opal/erb.rb +29 -15
  35. data/lib/opal/hike_path_finder.rb +18 -0
  36. data/lib/opal/nodes.rb +1 -0
  37. data/lib/opal/nodes/call.rb +107 -26
  38. data/lib/opal/nodes/call_special.rb +31 -6
  39. data/lib/opal/nodes/class.rb +2 -2
  40. data/lib/opal/nodes/constants.rb +5 -20
  41. data/lib/opal/nodes/def.rb +4 -4
  42. data/lib/opal/nodes/defined.rb +3 -3
  43. data/lib/opal/nodes/definitions.rb +1 -1
  44. data/lib/opal/nodes/for.rb +35 -0
  45. data/lib/opal/nodes/helpers.rb +2 -2
  46. data/lib/opal/nodes/iter.rb +3 -3
  47. data/lib/opal/nodes/literal.rb +10 -2
  48. data/lib/opal/nodes/masgn.rb +2 -2
  49. data/lib/opal/nodes/module.rb +2 -2
  50. data/lib/opal/nodes/scope.rb +1 -0
  51. data/lib/opal/nodes/singleton_class.rb +2 -2
  52. data/lib/opal/nodes/super.rb +2 -2
  53. data/lib/opal/nodes/top.rb +30 -3
  54. data/lib/opal/parser.rb +15 -1
  55. data/lib/opal/parser/grammar.rb +2571 -2452
  56. data/lib/opal/parser/grammar.y +37 -5
  57. data/lib/opal/parser/keywords.rb +2 -0
  58. data/lib/opal/parser/lexer.rb +21 -11
  59. data/lib/opal/path_reader.rb +28 -0
  60. data/lib/opal/paths.rb +38 -0
  61. data/lib/opal/source_map.rb +32 -15
  62. data/lib/opal/sprockets/environment.rb +9 -2
  63. data/lib/opal/sprockets/erb.rb +1 -2
  64. data/lib/opal/sprockets/path_reader.rb +34 -0
  65. data/lib/opal/sprockets/processor.rb +40 -39
  66. data/lib/opal/sprockets/server.rb +47 -33
  67. data/lib/opal/version.rb +1 -1
  68. data/opal.gemspec +10 -5
  69. data/opal/README.md +6 -0
  70. data/opal/corelib/array.rb +36 -4
  71. data/opal/corelib/array/inheritance.rb +6 -6
  72. data/opal/corelib/basic_object.rb +9 -9
  73. data/opal/corelib/boolean.rb +1 -1
  74. data/opal/corelib/class.rb +12 -12
  75. data/opal/corelib/dir.rb +20 -0
  76. data/opal/corelib/enumerable.rb +42 -42
  77. data/opal/corelib/enumerator.rb +1 -1
  78. data/opal/corelib/error.rb +2 -2
  79. data/opal/corelib/file.rb +56 -0
  80. data/opal/corelib/hash.rb +5 -5
  81. data/opal/corelib/helpers.rb +3 -3
  82. data/opal/corelib/io.rb +13 -10
  83. data/opal/corelib/kernel.rb +44 -68
  84. data/opal/corelib/method.rb +1 -1
  85. data/opal/corelib/module.rb +89 -114
  86. data/opal/corelib/nil_class.rb +1 -1
  87. data/opal/corelib/numeric.rb +27 -23
  88. data/opal/corelib/proc.rb +5 -5
  89. data/opal/corelib/range.rb +8 -4
  90. data/opal/corelib/regexp.rb +5 -5
  91. data/opal/corelib/runtime.js +589 -272
  92. data/opal/corelib/string.rb +52 -37
  93. data/opal/corelib/string/inheritance.rb +5 -5
  94. data/opal/corelib/time.rb +102 -52
  95. data/opal/corelib/variables.rb +3 -3
  96. data/opal/opal.rb +2 -0
  97. data/package.json +9 -0
  98. data/spec/filters/bugs/array.rb +0 -6
  99. data/spec/filters/bugs/language.rb +4 -0
  100. data/spec/filters/bugs/numeric.rb +7 -6
  101. data/spec/filters/bugs/opal.rb +2 -0
  102. data/spec/filters/bugs/regexp.rb +4 -0
  103. data/spec/filters/bugs/string.rb +0 -7
  104. data/spec/filters/bugs/stringscanner.rb +4 -1
  105. data/spec/filters/unsupported/private_methods.rb +2 -0
  106. data/spec/lib/builder_processors_spec.rb +27 -0
  107. data/spec/lib/builder_spec.rb +66 -0
  108. data/spec/{cli → lib}/cli_spec.rb +60 -5
  109. data/spec/{cli → lib}/compiler_spec.rb +66 -5
  110. data/spec/{cli → lib}/dependency_resolver_spec.rb +1 -1
  111. data/spec/lib/fixtures/no_requires.rb +1 -0
  112. data/spec/{cli → lib}/fixtures/opal_file.rb +0 -0
  113. data/spec/lib/fixtures/require_tree_test.rb +3 -0
  114. data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
  115. data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
  116. data/spec/lib/fixtures/requires.rb +7 -0
  117. data/spec/{cli → lib}/fixtures/sprockets_file.js.rb +0 -0
  118. data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
  119. data/spec/lib/hike_path_finder_spec.rb +23 -0
  120. data/spec/{cli → lib}/lexer_spec.rb +1 -1
  121. data/spec/{cli → lib}/parser/alias_spec.rb +1 -1
  122. data/spec/{cli → lib}/parser/and_spec.rb +1 -1
  123. data/spec/{cli → lib}/parser/attrasgn_spec.rb +1 -1
  124. data/spec/{cli → lib}/parser/begin_spec.rb +1 -1
  125. data/spec/{cli → lib}/parser/block_spec.rb +1 -1
  126. data/spec/{cli → lib}/parser/break_spec.rb +1 -1
  127. data/spec/{cli → lib}/parser/call_spec.rb +1 -1
  128. data/spec/{cli → lib}/parser/class_spec.rb +1 -1
  129. data/spec/{cli → lib}/parser/comments_spec.rb +1 -1
  130. data/spec/{cli → lib}/parser/def_spec.rb +1 -1
  131. data/spec/{cli → lib}/parser/if_spec.rb +1 -1
  132. data/spec/{cli → lib}/parser/iter_spec.rb +1 -1
  133. data/spec/{cli → lib}/parser/lambda_spec.rb +1 -1
  134. data/spec/{cli → lib}/parser/literal_spec.rb +1 -1
  135. data/spec/{cli → lib}/parser/masgn_spec.rb +1 -1
  136. data/spec/{cli → lib}/parser/module_spec.rb +1 -1
  137. data/spec/{cli → lib}/parser/not_spec.rb +1 -1
  138. data/spec/{cli → lib}/parser/op_asgn1_spec.rb +1 -1
  139. data/spec/{cli → lib}/parser/op_asgn2_spec.rb +1 -1
  140. data/spec/{cli → lib}/parser/or_spec.rb +1 -1
  141. data/spec/{cli → lib}/parser/return_spec.rb +1 -1
  142. data/spec/{cli → lib}/parser/sclass_spec.rb +1 -1
  143. data/spec/{cli → lib}/parser/string_spec.rb +8 -1
  144. data/spec/{cli → lib}/parser/super_spec.rb +1 -1
  145. data/spec/lib/parser/unary_spec.rb +48 -0
  146. data/spec/{cli → lib}/parser/undef_spec.rb +1 -1
  147. data/spec/{cli → lib}/parser/unless_spec.rb +1 -1
  148. data/spec/{cli → lib}/parser/variables_spec.rb +1 -1
  149. data/spec/{cli → lib}/parser/while_spec.rb +1 -1
  150. data/spec/{cli → lib}/parser/yield_spec.rb +1 -1
  151. data/spec/lib/path_reader_spec.rb +24 -0
  152. data/spec/lib/shared/path_finder_shared.rb +19 -0
  153. data/spec/lib/shared/path_reader_shared.rb +31 -0
  154. data/spec/lib/spec_helper.rb +9 -0
  155. data/spec/lib/sprockets/environment_spec.rb +30 -0
  156. data/spec/{cli → lib}/sprockets/erb_spec.rb +1 -1
  157. data/spec/lib/sprockets/path_reader_spec.rb +25 -0
  158. data/spec/{cli → lib}/sprockets/processor_spec.rb +9 -2
  159. data/spec/lib/sprockets/server_spec.rb +20 -0
  160. data/spec/opal/compiler/irb_spec.rb +11 -11
  161. data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
  162. data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
  163. data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
  164. data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
  165. data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
  166. data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
  167. data/spec/opal/core/kernel/respond_to_spec.rb +2 -2
  168. data/spec/opal/core/runtime/method_missing_spec.rb +19 -0
  169. data/spec/opal/core/source_map_spec.rb +2 -2
  170. data/spec/opal/core/string_spec.rb +11 -0
  171. data/spec/opal/stdlib/erb/erb_spec.rb +0 -1
  172. data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
  173. data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
  174. data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
  175. data/spec/rubyspecs +54 -11
  176. data/spec/spec_helper.rb +18 -3
  177. data/spec/support/mspec_rspec_adapter.rb +33 -0
  178. data/spec/{cli/spec_helper.rb → support/parser_helpers.rb} +10 -10
  179. data/stdlib/README.md +3 -0
  180. data/stdlib/benchmark.rb +10 -0
  181. data/stdlib/date.rb +2 -2
  182. data/stdlib/dir.rb +1 -5
  183. data/stdlib/file.rb +1 -7
  184. data/stdlib/json.rb +10 -1
  185. data/stdlib/native.rb +5 -5
  186. data/stdlib/nodejs.rb +5 -0
  187. data/stdlib/nodejs/dir.rb +13 -0
  188. data/stdlib/nodejs/file.rb +98 -0
  189. data/stdlib/nodejs/fileutils.rb +26 -0
  190. data/stdlib/nodejs/io.rb +2 -0
  191. data/stdlib/nodejs/irb.rb +45 -0
  192. data/stdlib/nodejs/process.rb +16 -0
  193. data/stdlib/nodejs/require.rb +32 -0
  194. data/stdlib/nodejs/rubygems.rb +68 -0
  195. data/stdlib/nodejs/runtime.rb +25 -0
  196. data/stdlib/nodejs/yaml.rb +11 -0
  197. data/stdlib/opal-parser.rb +1 -2
  198. data/stdlib/opal-source-maps.rb +2 -0
  199. data/stdlib/phantomjs.rb +8 -0
  200. data/stdlib/process.rb +10 -0
  201. data/stdlib/promise.rb +12 -4
  202. data/stdlib/set.rb +27 -0
  203. data/stdlib/source_map.rb +5 -63
  204. data/stdlib/source_map/map.rb +220 -0
  205. data/stdlib/source_map/mapping.rb +26 -0
  206. data/stdlib/source_map/offset.rb +88 -0
  207. data/stdlib/source_map/version.rb +3 -0
  208. data/stdlib/source_map/vlq.rb +77 -101
  209. data/stdlib/sourcemap.rb +1 -0
  210. data/stdlib/strscan.rb +7 -1
  211. data/stdlib/template.rb +1 -1
  212. data/stdlib/thread.rb +147 -7
  213. metadata +238 -104
  214. data/lib/mspec/opal/mspec_fixes.rb +0 -87
  215. data/spec/cli/sprockets/environment_spec.rb +0 -14
  216. data/spec/filters/bugs/symbol.rb +0 -5
  217. data/spec/opal/core/kernel/warn_spec.rb +0 -83
  218. data/spec/opal/core/language/numbers_spec.rb +0 -60
  219. data/stdlib/opal-source-maps.js.erb +0 -2
  220. data/stdlib/source_map/generator.rb +0 -251
  221. data/stdlib/source_map/parser.rb +0 -102
@@ -0,0 +1,7 @@
1
+ require 'foo'
2
+
3
+ puts 'hello'
4
+
5
+ require 'bar'
6
+
7
+ puts 'goodbye'
File without changes
@@ -0,0 +1,3 @@
1
+ #=require_tree ./required_tree_test
2
+
3
+ puts 5
@@ -0,0 +1,23 @@
1
+ require 'lib/spec_helper'
2
+ require 'lib/shared/path_finder_shared'
3
+ require 'opal/hike_path_finder'
4
+
5
+ describe Opal::HikePathFinder do
6
+ subject(:path_finder) { described_class.new(root) }
7
+ let(:root) { File.expand_path('..', __FILE__) }
8
+ let(:path) { 'fixtures/opal_file' }
9
+ let(:full_path) { File.join(root, path + ext) }
10
+ let(:ext) { '.rb' }
11
+
12
+ include_examples :path_finder
13
+
14
+ context 'with absolute paths' do
15
+ it 'returns the path if exists' do
16
+ expect(path_finder.find(full_path)).to eq(full_path)
17
+ end
18
+
19
+ it 'gives nil if it is missing' do
20
+ expect(path_finder.find(full_path+'/not-real')).to eq(nil)
21
+ end
22
+ end
23
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
  require 'opal/parser'
3
3
 
4
4
  describe Opal::Lexer do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The alias keyword" do
4
4
  describe "with fitem" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The and statement" do
4
4
  it "should always return s(:and)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Attribute assignments" do
4
4
  it "should return a s(:attrasgn) for simple assignments" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The begin keyword" do
4
4
  it "should be removed when used without a resuce or enusre body" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Block statements" do
4
4
  it "should return the direct expression if only one expresssion in block" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The break keyword" do
4
4
  it "should return s(:break) when given no args" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Method calls" do
4
4
  it "should use 'nil' for calls without a receiver" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The class keyword" do
4
4
  it "returns an empty s(:block) when given an empty body" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Multiline comments" do
4
4
  it "parses multiline comments and ignores them" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The def keyword" do
4
4
  describe "for normal definitions" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The if keyword" do
4
4
  it "should return an s(:if) with given truthy and falsy bodies" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Iters" do
4
4
  describe "Iter on a command" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Lambda literals" do
4
4
  it "should parse with either do/end construct or curly braces" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe Opal::Parser do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Masgn" do
4
4
  describe "with a single lhs splat" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The module keyword" do
4
4
  it "returns an empty s(:block) when given an empty body" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The not keyword" do
4
4
  it "returns a call sexp" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "op_asgn1" do
4
4
  it "returns s(:op_asgn1)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "op_asgn2" do
4
4
  it "returns s(:op_asgn2)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The or statement" do
4
4
  it "should always return s(:or)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The return keyword" do
4
4
  it "should return s(:return) when given no arguments" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Singleton classes" do
4
4
  it "returns an empty s(:block) when given an empty body" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "Strings" do
4
4
  it "parses empty strings" do
@@ -237,6 +237,13 @@ describe "x-strings" do
237
237
  }.should raise_error(Exception)
238
238
  end
239
239
  end
240
+
241
+ describe "contiguous strings" do
242
+ it "concatenates parts" do
243
+ parsed('"a" "b"').should == [:dstr, "a", [:str, "b"]]
244
+ end
245
+ end
246
+
240
247
  end
241
248
 
242
249
  describe "Heredocs" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The super keyword" do
4
4
  it "should return s(:super) for any arguments" do
@@ -0,0 +1,48 @@
1
+ require 'support/parser_helpers'
2
+
3
+ describe Opal::Parser do
4
+ describe '-@' do
5
+ context 'with an integer' do
6
+ it "parses unary op. with the right precedence" do
7
+ parsed("-1.hello").should == [:call, [:int, -1], :hello, [:arglist]]
8
+ end
9
+
10
+ it "parses unary op. as a method call" do
11
+ parsed("-1").should == [:int, -1]
12
+ end
13
+
14
+ end
15
+
16
+ context 'with a float' do
17
+ it "parses unary op. with the right precedence" do
18
+ parsed("-1.23.hello").should == [:call, [:float, -1.23], :hello, [:arglist]]
19
+ end
20
+
21
+ it "parses unary op. as a method call" do
22
+ parsed("-1.23").should == [:float, -1.23]
23
+ end
24
+ end
25
+ end
26
+
27
+ describe '+@' do
28
+ context 'with an integer' do
29
+ it "parses unary op. with the right precedence" do
30
+ parsed("+1.hello").should == [:call, [:int, 1], :hello, [:arglist]]
31
+ end
32
+
33
+ it "parses unary op. as a method call" do
34
+ parsed("-1").should == [:int, -1]
35
+ end
36
+ end
37
+
38
+ context 'with a float' do
39
+ it "parses unary op. with the right precedence" do
40
+ parsed("+1.23.hello").should == [:call, [:float, 1.23], :hello, [:arglist]]
41
+ end
42
+
43
+ it "parses unary op. as a method call" do
44
+ parsed("-1.23").should == [:float, -1.23]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The undef keyword" do
4
4
  it "returns s(:undef) with the argument as an s(:lit)" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The unless keyword" do
4
4
  it "returns s(:if) with reversed true and false bodies" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe Opal::Parser do
4
4
  it "parses instance variables" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The while keyword" do
4
4
  it "returns an s(:while) with the given expr, body and true for head" do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../spec_helper', __FILE__)
1
+ require 'support/parser_helpers'
2
2
 
3
3
  describe "The yield keyword" do
4
4
  it "should return s(:yield) when no arguments given" do
@@ -0,0 +1,24 @@
1
+ require 'lib/spec_helper'
2
+ require 'lib/shared/path_reader_shared'
3
+ require 'lib/shared/path_finder_shared'
4
+ require 'opal/path_reader'
5
+
6
+
7
+ describe Opal::PathReader do
8
+ subject(:file_reader) { described_class.new(path_finder) }
9
+ let(:path_finder) { double('path_finder') }
10
+ let(:path) { 'opal_file' }
11
+ let(:full_path) { File.expand_path('../fixtures/opal_file.rb', __FILE__) }
12
+ let(:contents) { File.read(full_path) }
13
+
14
+ before do
15
+ path_finder.stub(:find) {|path| nil}
16
+ path_finder.stub(:find).with(path).and_return(full_path)
17
+ path_finder.stub(:paths).and_return(Opal.paths)
18
+ end
19
+
20
+ include_examples :path_finder
21
+ include_examples :path_reader do
22
+ let(:path_reader) { file_reader }
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'lib/spec_helper'
2
+
3
+ shared_examples :path_finder do
4
+ # @param path
5
+ # the path we want to read
6
+ #
7
+ # @param full_path
8
+ # the expanded path that should be found
9
+ #
10
+ it 'returns the full path if the path exists' do
11
+ expect(path_finder.find(path)).to eq(full_path)
12
+ end
13
+
14
+ it 'returns nil if the path is missing' do
15
+ expect(path_finder.find('unexpected-path')).to eq(nil)
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,31 @@
1
+ require 'lib/spec_helper'
2
+
3
+ # Below the helpers expected from a spec that
4
+ # includes these shared examples:
5
+ #
6
+ # @object [PathReader] path_reader the object under test
7
+ # @method [String] path the path we want to read
8
+ # @method [String] contents the contents we expect to be read
9
+ #
10
+ shared_examples :path_reader do
11
+ describe '#paths' do
12
+ it 'is an Enumberable' do
13
+ expect(path_reader.paths).to be_an(Enumerable)
14
+ end
15
+
16
+ it 'includes Opal.paths' do
17
+ paths = path_reader.paths.to_a
18
+ Opal.paths.each { |path| expect(paths).to include(path) }
19
+ end
20
+ end
21
+
22
+ describe '#read' do
23
+ it 'responds to #path' do
24
+ expect(path_reader.read(path)).to eq(contents)
25
+ end
26
+
27
+ it 'returns nil if the file is missing' do
28
+ expect(path_reader.read('unexpected-path!')).to be_nil
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ require 'opal'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+ config.before { Opal.instance_variable_set('@paths', nil) }
9
+ end
@@ -0,0 +1,30 @@
1
+ require 'lib/spec_helper'
2
+ require 'opal/sprockets/environment'
3
+
4
+ describe Opal::Environment do
5
+ let(:env) { described_class.new }
6
+ let(:logical_path) { 'sprockets_file' }
7
+
8
+ before { env.append_path File.expand_path('../../fixtures/', __FILE__) }
9
+
10
+ it 'compiles Ruby to JS' do
11
+ expect(env[logical_path].source).to include('$puts(')
12
+ expect(env[logical_path+'.js'].source).to include('$puts(')
13
+ end
14
+
15
+ describe 'require_tree sprockets directive' do
16
+ it 'is still supported' do
17
+ source = env['sprockets_require_tree_test'].source
18
+ expect(source).to include('required_file1')
19
+ expect(source).to include('required_file2')
20
+ end
21
+ end
22
+
23
+ describe 'require_tree helper' do
24
+ it 'is handled by the processor' do
25
+ source = env['require_tree_test'].source
26
+ expect(source).to include('required_file1')
27
+ expect(source).to include('required_file2')
28
+ end
29
+ end
30
+ end