Sha256: 1f36b9fa71f354ee42c70c3e92bfa3804a1b15ea4ec2a62b16674e82645b2640

Contents?: true

Size: 1.29 KB

Versions: 52

Compression:

Stored size: 1.29 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

module ModuleSpecs
  class NoInheritance
    def method_to_remove; 1; end

    remove_method :method_to_remove
  end

  class Parent
    def method_to_remove; 1; end
  end

  class Child < Parent
    def method_to_remove; 2; end

    remove_method :method_to_remove
  end

  class First
    def method_to_remove; 1; end
  end

  class Second < First
    def method_to_remove; 2; end
  end
end

describe "Module#remove_method" do
  it "removes the method from a class" do
    x = ModuleSpecs::NoInheritance.new
    x.respond_to?(:method_to_remove).should == false
  end

  it "removes method from subclass, but not parent" do
    x = ModuleSpecs::Child.new
    x.respond_to?(:method_to_remove).should == true
    x.method_to_remove.should == 1
  end

  it "raises a NameError when attempting to remove method further up the inheritance tree" do
    lambda {
      class Third < ModuleSpecs::Second
        remove_method :method_to_remove
      end
    }.should raise_error(NameError)
  end

  it "raises a NameError when attempting to remove a missing method" do
    lambda {
      class Third < ModuleSpecs::Second
        remove_method :blah
      end
    }.should raise_error(NameError)
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/module/remove_method_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/module/remove_method_spec.rb