Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify receivers #453

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
merge Fake{,AnyInstance}Class into FakeClass
nitishr committed Dec 27, 2019
commit 98e70031b2433e62ae93f578805caeb331d79fe0
72 changes: 31 additions & 41 deletions test/unit/receivers_test.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
require File.expand_path('../../test_helper', __FILE__)
require 'mocha/receivers'
module ReceiversTest
class FakeClass
class AnyInstance
def initialize(mocha)
@mocha = mocha
end

class InstanceReceiverTest < Mocha::TestCase
include Mocha
def mocha(_instantiate)
@mocha
end
end

class FakeObject
def initialize(mocha)
attr_reader :superclass

def initialize(superclass, mocha)
@superclass = superclass
@mocha = mocha
end

def mocha(_instantiate)
@mocha
end

def any_instance
AnyInstance.new(@mocha)
end

def is_a?(_klass)
false
true
end
end
end

class FakeClass
attr_reader :superclass
class InstanceReceiverTest < Mocha::TestCase
include Mocha
include ReceiversTest

def initialize(superclass, mocha)
@superclass = superclass
class FakeObject
def initialize(mocha)
@mocha = mocha
end

def mocha(_instantiate)
@mocha
end

def is_a?(klass)
klass == Class
def is_a?(_klass)
false
end
end

@@ -52,38 +68,12 @@ def test_mocks_returns_mocks_for_class_and_its_superclasses

class AnyInstanceReceiverTest < Mocha::TestCase
include Mocha

class FakeAnyInstanceClass
class AnyInstance
def initialize(mocha)
@mocha = mocha
end

def mocha(_instantiate)
@mocha
end
end

attr_reader :superclass

def initialize(superclass, mocha)
@superclass = superclass
@mocha = mocha
end

def any_instance
AnyInstance.new(@mocha)
end

def is_a?(_klass)
true
end
end
include ReceiversTest

def test_mocks_returns_mocks_for_class_and_its_superclasses
grandparent = FakeAnyInstanceClass.new(nil, :grandparent_mocha)
parent = FakeAnyInstanceClass.new(grandparent, :parent_mocha)
klass = FakeAnyInstanceClass.new(parent, :mocha)
grandparent = FakeClass.new(nil, :grandparent_mocha)
parent = FakeClass.new(grandparent, :parent_mocha)
klass = FakeClass.new(parent, :mocha)
receiver = AnyInstanceReceiver.new(klass)
assert_equal [:mocha, :parent_mocha, :grandparent_mocha], receiver.mocks
end