source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
opal/opal
https://github.com/opal/opal
spec/lib/builder_spec.rb
Ruby
mit
4,915
master
8,407
require 'lib/spec_helper' require 'opal/os' require 'opal/builder' require 'opal/builder/scheduler/sequential' require 'opal/builder/scheduler/threaded' require 'tmpdir' RSpec.describe Opal::Builder do subject(:builder) { described_class.new(options) } let(:builder_with_paths) { builder.append_paths(File.expand_pa...
github
opal/opal
https://github.com/opal/opal
spec/lib/cli_spec.rb
Ruby
mit
4,915
master
11,423
require 'lib/spec_helper' require 'opal/cli' require 'opal/cli_options' require 'open3' require 'rbconfig' require 'stringio' require 'tmpdir' RSpec.describe Opal::CLI do let(:file) { File.expand_path('../fixtures/opal_file.rb', __FILE__) } let(:options) { {} } subject(:cli) { described_class.new(options) } ...
github
opal/opal
https://github.com/opal/opal
spec/lib/cli_runners/server_spec.rb
Ruby
mit
4,915
master
590
require 'lib/spec_helper' require 'opal/cli_runners' require 'rack/test' RSpec.describe Opal::CliRunners::Server do include Rack::Test::Methods def app @app end it 'starts a server for the given code' do expect(Rack::Server).to receive(:start) do |options| @app = options[:app] expect(opti...
github
opal/opal
https://github.com/opal/opal
spec/lib/source_map/file_spec.rb
Ruby
mit
4,915
master
4,325
require 'support/source_map_helper' RSpec.describe Opal::SourceMap::File do include SourceMapHelper specify '#as_json' do map = described_class.new([fragment(code: "foo")], 'foo.rb', "foo") expect(map.as_json).to be_a(Hash) expect(map.as_json(ignored: :options)).to be_a(Hash) end it 'correctly ma...
github
opal/opal
https://github.com/opal/opal
spec/lib/source_map/index_spec.rb
Ruby
mit
4,915
master
2,889
require 'support/source_map_helper' RSpec.describe Opal::SourceMap::Index do include SourceMapHelper specify '#as_json' do builder = Opal::Builder.new builder.build_str('foo', 'bar.rb') map = builder.source_map expect(map.as_json).to be_a(Hash) expect(map.as_json(ignored: :options)).to be_a(Ha...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/forward_args_spec.rb
Ruby
mit
4,915
master
1,978
require 'lib/spec_helper' require 'support/rewriters_helper' require 'opal/rewriters/forward_args' RSpec.describe Opal::Rewriters::ForwardArgs do include RewritersHelper before(:each) { Opal::Rewriters::ForRewriter.reset_tmp_counter! } correct_names = proc do |ast| case ast when Opal::AST::Node a...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/block_to_iter_spec.rb
Ruby
mit
4,915
master
492
require 'lib/spec_helper' require 'support/rewriters_helper' RSpec.describe Opal::Rewriters::BlockToIter do include RewritersHelper let(:block_node) do # m { |arg1| 1 } s(:block, s(:send, nil, :m), s(:args, s(:arg, :arg1)), s(:int, 1) ) end let(:iter_node) do s(:send, nil, :...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/base_spec.rb
Ruby
mit
4,915
master
2,192
require 'lib/spec_helper' require 'support/rewriters_helper' require 'opal/rewriters/base' RSpec.describe Opal::Rewriters::Base do include RewritersHelper def body_ast_of(method_source) def_ast = parse_without_rewriting(method_source).children.first _, _, body_ast = *def_ast body_ast end let(:nod...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/opal_engine_check_spec.rb
Ruby
mit
4,915
master
3,102
require 'lib/spec_helper' require 'support/rewriters_helper' RSpec.describe Opal::Rewriters::OpalEngineCheck do include RewritersHelper let(:opal_str_sexp) { s(:str, 'opal') } let(:jruby_str_sexp) { s(:str, 'jruby') } let(:true_branch) { s(:int, 1) } let(:false_branch) { s(:int, 2) } [:RUBY_ENGINE, :RUBY...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/dot_js_syntax_spec.rb
Ruby
mit
4,915
master
2,335
require 'lib/spec_helper' require 'support/rewriters_helper' RSpec.describe Opal::Rewriters::DotJsSyntax do include RewritersHelper context '.JS. syntax' do let(:send_node) do # a.JS.b(1) s(:send, s(:send, s(:lvar, :a), :JS), :b, s(:int, 1) ) end let(:dot_js_...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/logical_operator_assignment_spec.rb
Ruby
mit
4,915
master
7,811
require 'lib/spec_helper' require 'support/rewriters_helper' RSpec.describe Opal::Rewriters::LogicalOperatorAssignment do include RewritersHelper use_only_described_rewriter! before(:each) { Opal::Rewriters::LogicalOperatorAssignment.reset_tmp_counter! } let(:cache_tmp_name) { :$logical_op_recvr_tmp_1 } le...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/numblocks_spec.rb
Ruby
mit
4,915
master
897
require 'lib/spec_helper' require 'support/rewriters_helper' require 'opal/rewriters/numblocks' RSpec.describe Opal::Rewriters::Numblocks do include RewritersHelper extend RewritersHelper # s() in example scope correct_names = proc do |ast| case ast when Opal::AST::Node ast.children.map do |i| ...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/binary_operator_assignment_spec.rb
Ruby
mit
4,915
master
4,608
require 'lib/spec_helper' require 'support/rewriters_helper' RSpec.describe Opal::Rewriters::BinaryOperatorAssignment do include RewritersHelper use_only_described_rewriter! before(:each) { Opal::Rewriters::BinaryOperatorAssignment.reset_tmp_counter! } let(:cache_tmp_name) { :$binary_op_recvr_tmp_1 } let(:...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/returnable_logic_spec.rb
Ruby
mit
4,915
master
1,389
require 'lib/spec_helper' require 'support/rewriters_helper' require 'opal/rewriters/for_rewriter' RSpec.describe Opal::Rewriters::ReturnableLogic do include RewritersHelper extend RewritersHelper include_examples 'it rewrites source-to-AST', 'true or false', s(:if, s(:lvasgn, "$ret_or_1", s(:true)), s...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/for_rewriter_spec.rb
Ruby
mit
4,915
master
2,366
require 'lib/spec_helper' require 'support/rewriters_helper' require 'opal/rewriters/for_rewriter' RSpec.describe Opal::Rewriters::ForRewriter do include RewritersHelper before(:each) { Opal::Rewriters::ForRewriter.reset_tmp_counter! } include_examples 'it rewrites source-to-AST', 'for i in (0..3); for j in (4...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/js_reserved_words_spec.rb
Ruby
mit
4,915
master
3,013
require 'lib/spec_helper' require 'support/rewriters_helper' RSpec.describe Opal::Rewriters::JsReservedWords do include RewritersHelper reserved_lvars = %i( do if in for let new try var case else enum eval false null this true void with break catch class const super throw while yield delete export imp...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/rubyspec/filters_rewriter_spec.rb
Ruby
mit
4,915
master
1,526
require 'lib/spec_helper' require 'opal/rewriters/rubyspec/filters_rewriter' require 'support/rewriters_helper' RSpec.describe Opal::Rubyspec::FiltersRewriter do include RewritersHelper let(:source) do <<-SOURCE describe 'User#email' do context 'when this' do it 'does that' ...
github
opal/opal
https://github.com/opal/opal
spec/lib/rewriters/hashes/key_duplicates_rewriter_spec.rb
Ruby
mit
4,915
master
1,833
require 'lib/spec_helper' require 'support/rewriters_helper' require 'opal/rewriters/hashes/key_duplicates_rewriter' RSpec.describe Opal::Rewriters::Hashes::KeyDuplicatesRewriter do include RewritersHelper shared_examples 'it warns' do |code, key_to_warn| context "for #{code} code" do it "warns about #{...
github
opal/opal
https://github.com/opal/opal
spec/lib/builder/post_processor_spec.rb
Ruby
mit
4,915
master
2,332
require 'lib/spec_helper' require 'opal/os' require 'opal/builder' require 'opal/builder/scheduler/sequential' require 'opal/builder/scheduler/threaded' require 'opal/fragment' require 'tmpdir' RSpec.describe Opal::Builder::PostProcessor do subject(:builder) { Opal::Builder.new(options) } let(:options) { {compiler...
github
opal/opal
https://github.com/opal/opal
spec/lib/builder/post_processor/dce_spec.rb
Ruby
mit
4,915
master
2,231
require 'lib/spec_helper' require 'opal/builder' RSpec.describe Opal::Builder::PostProcessor::DCE do let(:builder) { Opal::Builder.new(compiler_options: {cache_fragments: true}, dce: dce_types) } def build(code) builder.build_str(code, 'input.rb').to_s end context "when dce removes unused instance method...
github
opal/opal
https://github.com/opal/opal
spec/opal/language/predefined_spec.rb
Ruby
mit
4,915
master
391
require 'spec_helper' describe "Predefined global $!" do it "should be set to the new exception after a throwing rescue" do outer = StandardError.new 'outer' inner = StandardError.new 'inner' begin begin raise outer rescue $!.should == outer raise inner end ...
github
opal/opal
https://github.com/opal/opal
spec/opal/language/yield_spec.rb
Ruby
mit
4,915
master
763
require 'spec_helper' fixture = Class.new do def single yield 1 yield 2 end def multiple yield 1, 2 yield 3, 4 end end describe "The yield call" do before :each do ScratchPad.record [] @y = fixture.new end describe "taking a single argument" do it "can yield to a lambda wit...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/opal_raw_spec.rb
Ruby
mit
4,915
master
2,578
# backtick_javascript: true require 'spec_helper' require 'opal/raw' describe 'javascript operations using Opal::Raw module' do it 'Opal::Raw.typeof uses typeof to return underlying javascript type' do [1, `null`, `undefined`, Object.new, [], ""].each do |v| Opal::Raw.typeof(v).should == `typeof #{v}` ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/thread/mutex_spec.rb
Ruby
mit
4,915
master
820
require 'thread' describe Mutex do before do @mutex = Mutex.new end it "cannot be locked twice" do @mutex.lock lambda do @mutex.lock end.should raise_error(ThreadError) end it "reports locked? status" do @mutex.locked?.should be_false @mutex.lock @mutex.locked?.should be_t...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/thread/thread_queue_spec.rb
Ruby
mit
4,915
master
553
require 'thread' describe Thread::Queue do before do @queue = Thread::Queue.new end it "is aliased as ::Queue" do ::Thread::Queue.should == ::Queue end it "will not allow deadlock" do lambda do @queue.pop end.should raise_error(ThreadError) end it "pops in FIFO order" do @que...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/thread/thread_spec.rb
Ruby
mit
4,915
master
1,574
require 'thread' # Our implementation of Thread only supports faux thread-local variables. # Since we can't actually create a thread, nothing in rubyspec will run. describe Thread do it "returns a value for current" do Thread.current.should_not be_nil end it "only has current in list" do Thread.list.sho...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/logger/logger_spec.rb
Ruby
mit
4,915
master
10,827
require 'logger' require 'stringio' # Our implementation of Logger only supports StringIO pipes. # Since we can't portably write a log file, nothing in rubyspec will run. describe Logger do before do @pipe = StringIO.new @logger = Logger.new @pipe end describe "level" do it "should set the level to ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/promise/when_spec.rb
Ruby
mit
4,915
master
467
require 'promise' describe 'Promise.when' do it 'calls the block with all promises results' do a = Promise.new b = Promise.new x = 42 Promise.when(a, b).then {|y, z| x = y + z } a.resolve(1) b.resolve(2) x.should == 3 end it 'can be built lazily' do a = Promise.new ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/promise/value_spec.rb
Ruby
mit
4,915
master
338
require 'promise' describe 'Promise.value' do it 'resolves the promise with the given value' do Promise.value(23).value.should == 23 end it 'marks the promise as realized' do Promise.value(23).realized?.should be_true end it 'marks the promise as resolved' do Promise.value(23).resolved?.should ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/promise/trace_spec.rb
Ruby
mit
4,915
master
895
require 'promise' describe 'Promise#trace' do it 'calls the block with all the previous results' do x = 42 Promise.value(1).then { 2 }.then { 3 }.trace {|a, b, c| x = a + b + c } x.should == 6 end it 'calls the then after the trace' do x = 42 Promise.value(1).then { 2 }.then { 3...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/promise/always_spec.rb
Ruby
mit
4,915
master
1,031
require 'promise' describe 'Promise#always' do it 'calls the block when it was resolved' do x = 42 Promise.value(23).then { |v| x = v }.always { |v| x = 2 } x.should == 2 end it 'calls the block when it was rejected' do x = 42 Promise.error(23).rescue { |v| x = v }.always { |v| x = 2 } x...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/promise/rescue_spec.rb
Ruby
mit
4,915
master
1,060
require 'promise' describe 'Promise#rescue' do it 'calls the block when the promise has already been rejected' do x = 42 Promise.error(23).rescue { |v| x = v } x.should == 23 end it 'calls the block when the promise is rejected' do a = Promise.new x = 42 a.rescue { |v| x = v } a.rej...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/promise/error_spec.rb
Ruby
mit
4,915
master
337
require 'promise' describe 'Promise.error' do it 'rejects the promise with the given error' do Promise.error(23).error.should == 23 end it 'marks the promise as realized' do Promise.error(23).realized?.should be_true end it 'marks the promise as rejected' do Promise.error(23).rejected?.should b...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/promise/then_spec.rb
Ruby
mit
4,915
master
1,569
require 'promise' describe 'Promise#then' do it 'calls the block when the promise has already been resolved' do x = 42 Promise.value(23).then { |v| x = v } x.should == 23 end it 'calls the block when the promise is resolved' do a = Promise.new x = 42 a.then { |v| x = v } a.resolve(2...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/strscan/scan_spec.rb
Ruby
mit
4,915
master
375
require 'strscan' describe "StringScanner#scan" do context "when the regex has multiple alternatives" do it "still anchors to the beginning of the remaining text" do # regression test; see GH issue 1074 scanner = StringScanner.new("10\nb = `2E-16`") scanner.scan(/[\d_]+\.[\d_]+\b|[\d_]+(\.[\d_]...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/template/paths_spec.rb
Ruby
mit
4,915
master
205
require 'spec_helper' require 'template' describe Template do describe ".paths" do it "should be an array of registered templates" do Template.paths.should be_kind_of(Array) end end end
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/erb/erb_spec.rb
Ruby
mit
4,915
master
897
require 'erb' require File.expand_path('../simple', __FILE__) require File.expand_path('../quoted', __FILE__) require File.expand_path('../inline_block', __FILE__) describe "ERB files" do before :each do @simple = Template['opal/stdlib/erb/simple'] @quoted = Template['opal/stdlib/erb/quoted'] @inline_blo...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/json/ext_spec.rb
Ruby
mit
4,915
master
1,302
require 'json' describe "Hash#to_json" do it "returns a string of all key and value pairs" do {}.to_json.should == "{}" {"a" => 1, "b" => 2}.to_json.should == '{"a":1,"b":2}' hash = {"a" => 1, "b" => false, "c" => nil, "d" => true} JSON.parse(hash.to_json).should == hash end end describe "Array#t...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/json/parse_spec.rb
Ruby
mit
4,915
master
1,052
require 'json' describe "JSON.parse" do it "parses null into nil" do JSON.parse("null").should be_nil end it "parses true into true" do JSON.parse("true").should be_true end it "parses false into false" do JSON.parse("false").should be_false end it "parses numbers into numbers" do JSON...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/exposure_spec.rb
Ruby
mit
4,915
master
649
# backtick_javascript: true require 'native' describe 'Native exposure' do describe Class do describe '#native_alias' do it 'exposes a method to javascript' do c = Class.new do def ruby_method :ruby end native_alias :rubyMethod, :ruby_method end ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/struct_spec.rb
Ruby
mit
4,915
master
315
# backtick_javascript: true require 'native' describe Struct do describe '#to_n' do it 'converts a struct with native attributes to a JS object' do klass = Struct.new(:attribute) obj = klass.new(`{ key: 1 }`) native = obj.to_n `#{native}.attribute.key`.should == 1 end end end
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/element_reference_spec.rb
Ruby
mit
4,915
master
430
# backtick_javascript: true require 'native' describe "Native::Object#[]" do it "should return the same value for bridged classes" do Native(`2`).should === 2 Native(`"lol"`).should === "lol" end it "should return functions as is" do Native(`{ a: function(){} }`)[:a].should be_kind_of Proc end ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/array_spec.rb
Ruby
mit
4,915
master
257
# backtick_javascript: true require 'native' describe Array do describe '#to_n' do it 'converts an array with native objects to a JS array' do obj = [`{ key: 1 }`] native = obj.to_n `#{native}[0].key`.should == 1 end end end
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/initialize_spec.rb
Ruby
mit
4,915
master
536
# backtick_javascript: true require 'native' describe "Native#initialize" do it "works when Native is included in a BasicObject" do basic_class = Class.new(BasicObject) basic_object = basic_class.new lambda { basic_object.native? }.should raise_error(NoMethodError) basic_class.send :include, Native...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/hash_spec.rb
Ruby
mit
4,915
master
1,963
# backtick_javascript: true require 'native' describe Hash do it 'turns a native JS object into a hash' do obj = %x{ { a: 1, b: "two", c: { d: 1, }, e: [ { f: 'g', h: [null], }, ], } } h = ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/date_spec.rb
Ruby
mit
4,915
master
286
# backtick_javascript: true require 'native' require 'date' describe Date do describe '#to_n' do it 'returns native JS date object' do date = Date.new(1984, 1, 24) native = date.to_n expect(`#{native}.toDateString()`).to eq 'Tue Jan 24 1984' end end end
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/native_class_spec.rb
Ruby
mit
4,915
master
460
# backtick_javascript: true require 'native' describe "Class#native_class" do class SomeClass end after {`delete Opal.global.SomeClass`} it "adds current constant to the global JS object" do SomeClass.native_class `Opal.global.SomeClass`.should == SomeClass end it 'aliases Class#new to the unpr...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/new_spec.rb
Ruby
mit
4,915
master
2,545
# backtick_javascript: true require 'native' describe "Native()" do it "should return nil for null or undefined" do Native(`null`).should be_nil Native(`undefined`).should be_nil end it "should return String" do Native(`""`).should be_an_instance_of String end it "should return Integer" do ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/ext_spec.rb
Ruby
mit
4,915
master
411
# backtick_javascript: true require 'native' describe Hash do describe '#initialize' do it "returns a hash with a nil value" do h = Hash.new(`{a: null}`) h[:a].should == nil end end describe '#to_n' do it "should return a js object representing hash" do Hash.new({:a => 100, :b => ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/alias_native_spec.rb
Ruby
mit
4,915
master
605
# backtick_javascript: true require 'native' describe "Native.alias_native" do it "refers to an attribute on @native" do Class.new { include Native::Wrapper alias_native :a, :a }.new(`{ a: 2 }`).a.should == 2 end it "refers to an attribute on @native and calls it if it's a function" do ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/native_writer_spec.rb
Ruby
mit
4,915
master
528
# backtick_javascript: true require 'native' describe "Native.native_writer" do it "refers to an attribute on @native" do n = Class.new { include Native::Wrapper native_reader :a native_writer :a }.new(`{ a: 2 }`) n.a = 4 n.a.should == 4 end it "supports multiple names" do ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/deprecated_include_spec.rb
Ruby
mit
4,915
master
231
require 'native' describe "Native inclusion" do it "is deprecated" do Native.should_receive(:warn).with("Including ::Native is deprecated. Please include Native::Wrapper instead.") Class.new { include Native } end end
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/each_spec.rb
Ruby
mit
4,915
master
408
# backtick_javascript: true require 'native' describe "Native::Object#each" do it "enumerates on object properties" do Native(`{ a: 2, b: 3 }`).each {|name, value| ((name == :a && value == 2) || (name == :b && value == 3)).should be_true } end it "accesses the native when no block is given" do ...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/native_module_spec.rb
Ruby
mit
4,915
master
297
# backtick_javascript: true require 'native' describe "Module#native_module" do module SomeModule end after {`delete Opal.global.SomeModule`} it "adds current constant to the global JS object" do SomeModule.native_module `Opal.global.SomeModule`.should == SomeModule end end
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/method_missing_spec.rb
Ruby
mit
4,915
master
1,151
# backtick_javascript: true require 'native' describe "Native::Object#method_missing" do it "should return values" do Native(`{ a: 23 }`).a.should == 23 Native(`{ a: { b: 42 } }`).a.b.should == 42 end it "should call functions" do Native(`{ a: function() { return 42 } }`).a.should == 42 end it...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/native_alias_spec.rb
Ruby
mit
4,915
master
564
# backtick_javascript: true require 'native' describe "Class#native_alias" do it "exposes a method to javascript without the '$' prefix" do klass = Class.new { def a 2 end native_alias :a, :a } instance = klass.new `instance.a()`.should == 2 end it "raises if the alia...
github
opal/opal
https://github.com/opal/opal
spec/opal/stdlib/native/native_reader_spec.rb
Ruby
mit
4,915
master
426
# backtick_javascript: true require 'native' describe "Native.native_reader" do it "refers to an attribute on @native" do Class.new { include Native::Wrapper native_reader :a }.new(`{ a: 2 }`).a.should == 2 end it "uses multiple names" do n = Class.new { include Native::Wrapper ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/module_spec.rb
Ruby
mit
4,915
master
3,473
module ModuleSubclassIncludedSpec class Module1 < ::Module def included(_descendant) $ScratchPad << 'A included' end end class Module2 < Module1 def included(_descendant) $ScratchPad << 'B included' end end M0 = Module.new M1 = Module1.new M2 = Module2.new end module ModuleCV...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/iterable_props_spec.rb
Ruby
mit
4,915
master
1,226
# backtick_javascript: true require 'spec_helper' describe 'Iterable props defined by Opal on core JS objects' do %x{ function iterableKeysOf(obj) { var result = []; for (var key in obj) { result.push(key); } return result; } } it 'is empty for numbers' do `iterabl...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/boolean_spec.rb
Ruby
mit
4,915
master
1,129
require 'spec_helper' describe "TrueClass/FalseClass" do it 'correctly resolves a boolean class' do expect(true.class).to eq(TrueClass) expect(false.class).to eq(FalseClass) expect(true.class).not_to eq(false.class) end it 'correctly resolves a boolean class with #is_a?' do expect(true.is_a? Tr...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language_spec.rb
Ruby
mit
4,915
master
855
# backtick_javascript: true require 'spec_helper' describe "generated method names" do it "does not conflict with local Ruby variables" do Class.new { value = 123 def value 456 end value.should == 123 } end it "does not conflict with local JS variables" do Class.new ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/time_spec.rb
Ruby
mit
4,915
master
2,235
require 'spec_helper' require 'time' # rubyspec does not have specs for these listed methods describe Time do describe '<=>' do it 'returns -1 when self is less than other' do (Time.new(2015, 1, 1) <=> Time.new(2015, 1, 2)).should == -1 end it 'returns 0 when self is equal to other' do (Time...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/object_id_spec.rb
Ruby
mit
4,915
master
1,045
# backtick_javascript: true require 'spec_helper' describe "Opal.uid()" do it "returns even sequential numbers in increments of 2" do %x{ var id0 = Opal.uid(), id1 = Opal.uid(), id2 = Opal.uid(), id3 = Opal.uid(), id4 = Opal.uid(); } modulo = `id0` % 2 ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/hash_spec.rb
Ruby
mit
4,915
master
447
# backtick_javascript: true describe 'Hash' do it 'works with object-strings with regards to deleting' do h = {`new String('a')` => 'a'} k = h.keys.first h.delete(k) h.inspect.should == '{}' end it 'compacts nil and JavaScript null and undefined values' do h = { a: nil, b: `null`, c: `undefi...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/exception_spec.rb
Ruby
mit
4,915
master
237
# backtick_javascript: true require 'spec_helper' describe "Native exception" do it "handles messages for native exceptions" do exception = `new Error("native message")` exception.message.should == "native message" end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/string_spec.rb
Ruby
mit
4,915
master
8,965
# backtick_javascript: true require 'spec_helper' describe 'Encoding' do it 'supports US-ASCII' do skip if OPAL_PLATFORM == 'deno' # see filters/platform/deno "è".encoding.name.should == 'UTF-8' "è".force_encoding('ASCII').should == "\xC3\xA8" "è".force_encoding('ascii').should == "\xC3\xA8" "è"...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/helpers_spec.rb
Ruby
mit
4,915
master
318
require 'spec_helper' describe Opal do context '.instance_variable_name!' do it 'does not use regular expressions on Opal level, so $` stays the same' do 'some string' =~ /string/ post_match = $` Opal.instance_variable_name!(:@ivar_name) expect($`).to eq(post_match) end end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/runtime_spec.rb
Ruby
mit
4,915
master
1,726
# backtick_javascript: true require 'spec_helper' describe 'javascript access using .JS' do it 'should call javascript methods via .JS.method()' do "a1234b5678c".JS.indexOf('c').should == 10 "a1234b5678c".JS.replace(`/[0-9]/g`, '').should == 'abc' end it 'should call javascript methods via .JS.method a...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/enumerator/with_index_spec.rb
Ruby
mit
4,915
master
261
describe "Enumerator#with_index" do it "returns the result of the previously called method" do [1, 2, 3].each.with_index { |item, index| item * 2 }.should == [1, 2, 3] [1, 2, 3].map.with_index { |item, index| item * 2 }.should == [2, 4, 6] end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/module/include_spec.rb
Ruby
mit
4,915
master
1,068
require 'spec_helper' module ModuleIncludeSpecs module A def initialize $ScratchPad << :A super end end module B def initialize $ScratchPad << :B super end end module C def initialize $ScratchPad << :C super end end module D def initializ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/module/define_method_spec.rb
Ruby
mit
4,915
master
664
require 'spec_helper' describe "Module#define_method" do describe "when passed an UnboundMethod object" do it "defines a method taking a block" do klass = Class.new do def foo = yield :bar end klass.define_method(:baz, klass.instance_method(:foo)) klass.new.baz { |a| a }.should ==...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/array/include_spec.rb
Ruby
mit
4,915
master
221
# backtick_javascript: true describe "Array#include" do it "should respect nil values" do nileq = Object.new def nileq.==(other) nil end [nileq].should_not include("no match expected") end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/array/union_spec.rb
Ruby
mit
4,915
master
986
describe "Array#|" do it "relies on Ruby's #hash (not JavaScript's #toString) for identifying array items" do a1 = [ 123, '123'] a2 = ['123', 123 ] (a1 | a2).should == a1 (a2 | a1).should == a2 a1 = [ Time.at(1429521600.1), Time.at(1429521600.9) ] a2 = [ Time.at(1429521600.9), Time.at(1429521...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/array/uniq_spec.rb
Ruby
mit
4,915
master
1,063
describe "Array#uniq" do it "relies on Ruby's #hash (not JavaScript's #toString) for identifying array items" do a = [ 123, '123'] a.uniq.should == a a = [ Time.at(1429521600.1), Time.at(1429521600.9) ] a.uniq.should == a a = [ Object.new, Object.new ] a.uniq.should == a a = [ 1, 2, 3, ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/array/minus_spec.rb
Ruby
mit
4,915
master
818
describe "Array#-" do it "relies on Ruby's #hash (not JavaScript's #toString) for identifying array items" do a1 = [ 123 ] a2 = ['123'] (a1 - a2).should == a1 (a2 - a1).should == a2 a1 = [ Time.at(1429521600.1) ] a2 = [ Time.at(1429521600.9) ] (a1 - a2).should == a1 (a2 - a1).should =...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/array/zip_spec.rb
Ruby
mit
4,915
master
209
describe "Array#zip" do it "respects block arity" do foo = ['A', 'B'] values = [] foo.zip(foo) do | a,b | values << [a, b] end values.should == [['A', 'A'], ['B', 'B']] end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/array/intersection_spec.rb
Ruby
mit
4,915
master
976
describe "Array#&" do it "relies on Ruby's #hash (not JavaScript's #toString) for identifying array items" do a1 = [ 123, '123'] a2 = ['123', 123 ] (a1 & a2).should == a1 (a2 & a1).should == a2 a1 = [ Time.at(1429521600.1), Time.at(1429521600.9) ] a2 = [ Time.at(1429521600.9), Time.at(1429521...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/array/compact_spec.rb
Ruby
mit
4,915
master
265
# backtick_javascript: true describe "Array#compact" do it "compacts nil and JavaScript null and undefined" do a = [1, nil, `null`, `undefined`] expect(a.size).to eq 4 expect(a.compact.size).to eq 1 a.compact! expect(a.size).to eq 1 end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/array/dup_spec.rb
Ruby
mit
4,915
master
828
# backtick_javascript: true describe "Array#dup" do it "should use slice optimization" do a = Array.new `a.slice = function() { return ['sliced'] }` lambda { a.dup }.should_not raise_error a.dup.should == ['sliced'] end it "should use slice optimization on Array subclass" do subclass = Class...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/number/to_i_spec.rb
Ruby
mit
4,915
master
721
# backtick_javascript: true require 'spec_helper' describe 'Number#to_i' do it "should not change huge number" do 1504642339053716000000.to_i.should == 1504642339053716000000 end it "should not change negative huge number" do -1504642339053716000000.to_i.should == -1504642339053716000000 end it "e...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/number/to_s_spec.rb
Ruby
mit
4,915
master
202
require 'spec_helper' describe 'Number#to_s' do it "should convert 0.0 to '0.0'" do 0.0.to_s.should == '0' end it "should convert -0.0 to '-0.0'" do -0.0.to_s.should == '-0.0' end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/struct/dup_spec.rb
Ruby
mit
4,915
master
215
describe "Struct#dup" do it "should return another struct instance" do klass = Struct.new("Klass", :foo) a = klass.new(1) b = a.dup b.foo = 2 a.foo.should == 1 b.foo.should == 2 end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/io/read_spec.rb
Ruby
mit
4,915
master
2,416
require 'spec_helper' describe "IO reading methods" do examples = [ "abc\n|def\n|ghi\n", "ab|c\nd|ef\n|ghi\n", "©©©\n|ŋææ\n|æπ®\n", "🫃🫃🫃\n|🫃🫃🫃\n|🫃🫃🫃\n", "efhasdfhasf|asdfasdfasdf|asdfasdfasdf", "gsdfgsdg🫃|🫃🫃\n|🫃", "a\nb\nc\nd\ne\nf", "abcððefsdf🫃|s\nd", "a|b|c|d|e|f|...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/class/clone_spec.rb
Ruby
mit
4,915
master
780
require 'spec_helper' describe "Class#clone" do it "should copy an instance method including super call" do parent = Class.new do def hello "hello" end end child = Class.new(parent) do def hello super + " world" end end child.clone.new.hello.should == "hel...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/class/inherited_spec.rb
Ruby
mit
4,915
master
388
module ModuleInheritedTestModule class A def self.inherited(subclass) $ScratchPad << subclass.name end end end describe 'Class#inherited' do it 'gets called after setting a base scope of the subclass' do $ScratchPad = [] module ModuleInheritedTestModule class B < A end end ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/string_spec.rb
Ruby
mit
4,915
master
565
describe "Ruby string interpolation" do it "uses an internal representation when #to_s doesn't return a String" do obj = Object.new def obj.to_s BasicObject.new end str = "#{obj}" str.should be_an_instance_of(String) str.should =~ /\A#<Object:0x[0-9a-fA-F]+>\z/ end it "uses Ruby's ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/forward_args_spec.rb
Ruby
mit
4,915
master
1,279
describe "Forward arguments" do it "forwards args, kwargs and blocks" do def fwd_t1_pass1(...) fwd_t1_pass2(...) end def fwd_t1_pass2(*args, **kwargs, &block) [args.count, kwargs.count, block_given?] end fwd_t1_pass1(1, 2, 3, a: 1, b: 2).should == [3, 2, false] fwd_t1_pass1(1, 2,...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/xstring_send_spec.rb
Ruby
mit
4,915
master
375
# backtick_javascript: false describe "The x-string expression for send" do def `(command) "Linux x86_64" if command == "uname -a" end it "compiles as send if backtick_javascript is false" do `uname -a`.should == "Linux x86_64" end it "compiles as send with dstr if backtick_javascript is false" do ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/infinite_range_spec.rb
Ruby
mit
4,915
master
269
describe "Infinite ranges" do it "supports endless ranges" do range = (10..) range.begin.should == 10 range.end.should == nil end it "supports beginless ranges" do range = (..10) range.begin.should == nil range.end.should == 10 end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/safe_navigator_spec.rb
Ruby
mit
4,915
master
383
# backtick_javascript: true describe 'Safe navigator' do it "handles also null and undefined" do [`null`, `undefined`].each do |value| value&.unknown.should == nil end end it "calls a receiver exactly once" do def receiver @calls += 1 end @calls = 0 receiver&.itself.should ==...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/case_spec.rb
Ruby
mit
4,915
master
207
describe "Case statement" do it "works with JS object-wrapped values" do a = false objwr = `new String("abc")` case objwr when "abc" a = true end a.should == true end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/pattern_matching_spec.rb
Ruby
mit
4,915
master
2,292
require 'spec_helper' describe "pattern matching" do it "supports basic assignment" do 5 => a a.should == 5 end it "supports array pattern" do [1,2,3,4] => [1,2,*rest] rest.should == [3,4] [1,2,3,4] => [*rest,3,x] rest.should == [1,2] x.should == 4 end it "supports hash pattern"...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/numblocks_spec.rb
Ruby
mit
4,915
master
382
require 'spec_helper' describe "numblocks" do it "supports numblocks" do [1,2,3].map { _1 * 2 }.should == [2,4,6] [[1,2],[3,4]].map { _1 * _2 }.should == [2,12] end it "reports correct arity" do proc { [_1, _2] + [_3] }.arity.should == 3 end it "reports correct parameters" do proc { [_1, _2...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/memoization_spec.rb
Ruby
mit
4,915
master
476
describe "memoization" do it "memoizes a value with complex internal logic" do klass = Class.new do def memoized_value(dependency: nil) @memoized_value ||= begin return nil if dependency.nil? dependency.call end...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/keyword_arguments_spec.rb
Ruby
mit
4,915
master
203
describe "Keyword arguments" do it 'works with keys that are reserved words in JS' do o = Object.new def o.foo(default:) default end o.foo(default: :bar).should == :bar end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/while_spec.rb
Ruby
mit
4,915
master
559
describe "The while expression" do it "restarts the current iteration without reevaluating condition with redo" do a = [] i = 0 j = 0 while (i+=1)<3 a << i j+=1 redo if j<3 a << 5 end a.should == [1, 1, 1, 5, 2, 5] end it "restarts the current iteration without eva...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/xstring_spec.rb
Ruby
mit
4,915
master
265
# backtick_javascript: true describe "The x-string expression" do it "works with multiline, case and assignment" do a = case 1 when 1 %x{ var b = 5; return b; } end a.should == 5 end end
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/super_spec.rb
Ruby
mit
4,915
master
1,328
describe 'super without explicit argument' do it 'passes arguments named with js reserved word' do parent = Class.new do def test_args(*args) = args def test_rest_args(*args) = args def test_kwargs(**args) = args def test_rest_kwargs(**args) = args end klass = Class.new(parent) do ...
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/DATA/characters_support_spec.rb
Ruby
mit
4,915
master
211
describe "characters support of the DATA contstant" do it "supports all characters" do DATA.read.should == "azAZ09`~!@#$%^&*(\n)_+{}\\|;:'\",<.>/?\n" end end __END__ azAZ09`~!@#$%^&*( )_+{}\|;:'",<.>/?
github
opal/opal
https://github.com/opal/opal
spec/opal/core/language/DATA/characters_support_crlf_spec.rb
Ruby
mit
4,915
master
224
describe "characters support of the DATA contstant" do it "supports all characters" do DATA.read.should == "azAZ09`~!@#$%^&*(\r\n)_+{}\\|;:'\",<.>/?\r\n" end end __END__ azAZ09`~!@#$%^&*( )_+{}\|;:'",<.>/?