Sha256: 2b257db5d97f2baff0b850f7a56e7c3213fd21a2640133841e197918862d7780

Contents?: true

Size: 1.3 KB

Versions: 19

Compression:

Stored size: 1.3 KB

Contents

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
      def test_args(native) = super
      def test_rest_args(*native) = super
      def test_kwargs(native:) = super
      def test_rest_kwargs(**native) = super
    end

    klass.new.test_args(1).should == [1]
    klass.new.test_rest_args(2).should == [2]
    klass.new.test_kwargs(native: 3).should == {native: 3}
    klass.new.test_rest_kwargs(native: 4).should == {native: 4}
  end
end

class ABlockWithSuperSpec
  BLOCK = proc {
    return [self, super()]
  }
  def foo; :foo; end
  def bar; :bar; end
  def foo_bar; [foo, bar]; end
end

describe "a block with super" do
  it "can be used to define multiple methods" do
    block = nil

    c = Class.new(ABlockWithSuperSpec) {
      define_method :foo, ABlockWithSuperSpec::BLOCK
      define_method :bar, ABlockWithSuperSpec::BLOCK
      define_method :foo_bar, ABlockWithSuperSpec::BLOCK
    }

    obj = c.new
    obj.foo.should == [obj, :foo]
    obj.bar.should == [obj, :bar]
    obj.foo_bar.should == [obj, [[obj, :foo], [obj, :bar]]]
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 spec/opal/core/language/super_spec.rb
opal-1.8.2 spec/opal/core/language/super_spec.rb
opal-1.8.1 spec/opal/core/language/super_spec.rb
opal-1.8.0 spec/opal/core/language/super_spec.rb
opal-1.8.0.beta1 spec/opal/core/language/super_spec.rb
opal-1.7.4 spec/opal/core/language/super_spec.rb
opal-1.8.0.alpha1 spec/opal/core/language/super_spec.rb
opal-1.7.3 spec/opal/core/language/super_spec.rb
opal-1.7.2 spec/opal/core/language/super_spec.rb
opal-1.7.1 spec/opal/core/language/super_spec.rb
opal-1.7.0 spec/opal/core/language/super_spec.rb
opal-1.7.0.rc1 spec/opal/core/language/super_spec.rb
opal-1.6.1 spec/opal/core/language/super_spec.rb
opal-1.6.0 spec/opal/core/language/super_spec.rb
opal-1.6.0.rc1 spec/opal/core/language/super_spec.rb
opal-1.6.0.alpha1 spec/opal/core/language/super_spec.rb
opal-1.5.1 spec/opal/core/language/super_spec.rb
opal-1.5.0 spec/opal/core/language/super_spec.rb
opal-1.5.0.rc1 spec/opal/core/language/super_spec.rb