Sha256: 7a7e4ca35bd06cc4d11f5b18d198949a310d5f394e64b0e41a5bcfa51949d091

Contents?: true

Size: 981 Bytes

Versions: 33

Compression:

Stored size: 981 Bytes

Contents

require 'spec_helper'

$OPAL_TOP_LEVEL_OBJECT = self

def self.some_main_method
  3.142
end

def some_top_level_method_is_defined
  42
end

define_method :some_other_main_method do
  0.1618
end

describe "Defining normal methods at the top level" do
  it "should define them on Object, not main" do
    $OPAL_TOP_LEVEL_OBJECT.some_top_level_method_is_defined.should == 42
    Object.new.some_top_level_method_is_defined.should == 42
  end
end

describe "Defining singleton methods on main" do
  it "should define it on main directly" do
    $OPAL_TOP_LEVEL_OBJECT.some_main_method.should == 3.142
  end

  it "should not define the method for all Objects" do
    lambda { Object.new.some_main_method }.should raise_error(NoMethodError)
  end
end

describe "Defining methods on main with define_method" do
  it "should define it on main directly" do
    $OPAL_TOP_LEVEL_OBJECT.some_other_main_method.should == 0.1618
    Object.new.some_other_main_method.should == 0.1618
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

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