Skip to content

undefined method `dispatch_method' for nil:NilClass #59

Open
@soylent

Description

class SuperClass
  def method_in_superclass
    puts 'superclass'
  end
end

class SubClass < SuperClass
end

describe 'something' do
  before do
    # If I swap the following stubs, the tests don't fail.
    any_instance_of(SuperClass) do |superclass|
      stub(superclass).method_in_superclass do
        puts 'stubbed in superclass'
      end
    end

    any_instance_of(SubClass) do |subclass|
      stub(subclass).method_in_superclass do
        puts 'stubbed in subclass'
      end
    end
  end

  it 'passes' do
    SubClass.new.method_in_superclass
    SuperClass.new.method_in_superclass
  end
end

describe 'something else' do
  it 'fails' do
    SubClass.new.method_in_superclass
    SuperClass.new.method_in_superclass
  end
end

# .F
#
# Failures:
#
#   1) something else fails
#      Failure/Error: SubClass.new.method_in_superclass
#      NoMethodError:
#        undefined method `dispatch_method' for nil:NilClass
#      # ./spec/rr_spec.rb:35:in `block (2 levels) in <top (required)>'
#      # -e:1:in `<main>'

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions