Sha256: 54c0f37dc581dce3ee32928396cb5eae9ded43e71f28cc94446b4888b56984c4

Contents?: true

Size: 1.44 KB

Versions: 50

Compression:

Stored size: 1.44 KB

Contents

require "spec_helper"

module MethodMissingSpecs
  class A
    def method_missing(mid, *args)
      [mid, args]
    end
  end

  class B
    def method_missing(mid, *args, &block)
      [mid, block]
    end
  end
end

class BridgedClass < `(function NativeConstructor(){})`
end

describe "method_missing" do
  before do
    @obj = MethodMissingSpecs::A.new
  end

  it "should pass the missing method name as first argument" do
    @obj.foo.should == [:foo, []]
  end

  it "should correctly pass arguments to method_missing" do
    @obj.bar(1, 2, 3).should == [:bar, [1, 2, 3]]
  end

  it "calls method missing for operators" do
    obj = Object.new
    obj.should_receive(:method_missing).with(:+, 123).and_return(42)
    (obj + 123).should == 42
  end

  it "should pass blocks to method_missing" do
    obj = MethodMissingSpecs::B.new
    proc = proc { 1 }
    obj.baz(1, 2, &proc).should == [:baz, proc]
  end
end

describe "BasicObject#method_missing" do
  it "raises an error for the missing method" do
    lambda {
      BasicObject.new.foo_bar_baz
    }.should raise_error(Exception)
  end
end

describe "Array#method_missing" do
  it "raises an error for the missing method" do
    lambda {
      BasicObject.new.foo_bar_baz
    }.should raise_error(Exception)
  end
end

describe "<BridgedClass>#method_missing" do
  it "raises an error for the missing method" do
    lambda {
      BridgedClass.new.foo_bar_baz
    }.should raise_error(Exception)
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
opal-1.3.0.alpha1 spec/opal/core/runtime/method_missing_spec.rb
opal-1.2.0 spec/opal/core/runtime/method_missing_spec.rb
opal-1.2.0.beta1 spec/opal/core/runtime/method_missing_spec.rb
opal-1.1.1 spec/opal/core/runtime/method_missing_spec.rb
opal-1.1.1.rc1 spec/opal/core/runtime/method_missing_spec.rb
opal-1.1.0 spec/opal/core/runtime/method_missing_spec.rb
opal-1.1.0.rc1 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.6 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.6.beta spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.5 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.4 spec/opal/core/runtime/method_missing_spec.rb
opal-0.11.0.rc1 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.3 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.2 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.1 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.0 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.0.rc2 spec/opal/core/runtime/method_missing_spec.rb
opal-0.9.4 spec/opal/core/runtime/method_missing_spec.rb
opal-0.9.3 spec/opal/core/runtime/method_missing_spec.rb
opal-0.10.0.rc1 spec/opal/core/runtime/method_missing_spec.rb