Skip to content

Commit

Permalink
stubbed_instance -> callee, stub_owner -> stubbee
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishr committed Jan 17, 2020
1 parent df249eb commit dd3c458
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ class StubAnyInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
include StubMethodSharedTests

def method_owner
stubbed_instance.class.superclass
callee.class.superclass
end

def stubbed_instance
@stubbed_instance ||= Class.new(Class.new).new
def callee
@callee ||= Class.new(Class.new).new
end

def stub_owner
stubbed_instance.class.any_instance
def stubbee
callee.class.any_instance
end

def test_expect_method_on_any_instance_of_superclass_even_if_preceded_by_test_expecting_method_on_any_instance_of_subclass
Expand Down Expand Up @@ -52,14 +52,14 @@ class StubSuperclassAnyInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
include StubMethodSharedTests

def method_owner
stubbed_instance.class.superclass
callee.class.superclass
end

def stubbed_instance
@stubbed_instance ||= Class.new(Class.new).new
def callee
@callee ||= Class.new(Class.new).new
end

def stub_owner
def stubbee
method_owner.any_instance
end
end
8 changes: 4 additions & 4 deletions test/acceptance/stub_any_instance_method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def method_owner
@method_owner ||= Class.new
end

def stubbed_instance
def callee
method_owner.new
end

def stub_owner
def stubbee
method_owner.any_instance
end

Expand Down Expand Up @@ -128,11 +128,11 @@ def method_owner
@method_owner ||= Class.new.send(:include, module_with_private_method)
end

def stubbed_instance
def callee
method_owner.new
end

def stub_owner
def stubbee
method_owner.any_instance
end

Expand Down
6 changes: 3 additions & 3 deletions test/acceptance/stub_class_method_defined_on_class_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class StubClassMethodDefinedOnClassTest < Mocha::TestCase
include StubMethodSharedTests

def method_owner
stubbed_instance.singleton_class
callee.singleton_class
end

def stubbed_instance
@stubbed_instance ||= Class.new
def callee
@callee ||= Class.new
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def method_owner
@method_owner ||= Module.new
end

def stubbed_instance
def callee
Class.new.extend(method_owner)
end
end
16 changes: 8 additions & 8 deletions test/acceptance/stub_class_method_defined_on_superclass_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
include StubMethodSharedTests

def method_owner
stubbed_instance.superclass.singleton_class
callee.superclass.singleton_class
end

def stubbed_instance
@stubbed_instance ||= Class.new(Class.new)
def callee
@callee ||= Class.new(Class.new)
end

def test_stub_on_earliest_receiver_should_take_priority
Expand Down Expand Up @@ -65,14 +65,14 @@ class StubSuperclassClassMethodDefinedOnSuperclassTest < Mocha::TestCase
include StubMethodSharedTests

def method_owner
stubbed_instance.superclass.singleton_class
callee.superclass.singleton_class
end

def stubbed_instance
@stubbed_instance ||= Class.new(Class.new)
def callee
@callee ||= Class.new(Class.new)
end

def stub_owner
stubbed_instance.superclass
def stubbee
callee.superclass
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def method_owner
@method_owner ||= Class.new
end

def stubbed_instance
def callee
method_owner.new
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def method_owner
Kernel
end

def stubbed_instance
def callee
Class.new.new
end
end
Expand All @@ -15,7 +15,7 @@ def method_owner
Kernel
end

def stubbed_instance
def callee
Module.new
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def method_owner
@method_owner ||= Module.new
end

def stubbed_instance
def callee
Class.new.send(:include, method_owner).new
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def method_owner
Object
end

def stubbed_instance
def callee
Class.new.new
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class StubInstanceMethodDefinedOnSingletonClassTest < Mocha::TestCase
include StubMethodSharedTests

def method_owner
stubbed_instance.singleton_class
callee.singleton_class
end

def stubbed_instance
@stubbed_instance ||= Class.new.new
def callee
@callee ||= Class.new.new
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def method_owner
@method_owner ||= Class.new
end

def stubbed_instance
def callee
Class.new(method_owner).new
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def method_owner
@method_owner ||= Module.new
end

def stubbed_instance
def callee
Class.new.extend(method_owner)
end

Expand Down
16 changes: 8 additions & 8 deletions test/acceptance/stub_method_shared_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ def test_should_stub_private_method_and_leave_it_unchanged_after_test
def assert_snapshot_unchanged_on_stubbing(visibility)
method_owner.send(visibility, stubbed_method_name)
method_owner.send(:alias_method, :my_aliased_method, stubbed_method_name) if alias_method?
instance = stubbed_instance
stub_owner_in_scope = stub_owner || instance
callee_in_scope = callee
stubbee_in_scope = stubbee || callee_in_scope
method = alias_method? ? :my_aliased_method : stubbed_method_name
assert_snapshot_unchanged_on_pass(instance) do
stub_owner_in_scope.stubs(method).returns(:new_return_value)
assert_method_visibility instance, method, visibility
assert_equal :new_return_value, instance.send(method)
assert_snapshot_unchanged_on_pass(callee_in_scope) do
stubbee_in_scope.stubs(method).returns(:new_return_value)
assert_method_visibility callee_in_scope, method, visibility
assert_equal :new_return_value, callee_in_scope.send(method)
end
assert_equal :original_return_value, instance.send(method)
assert_equal :original_return_value, callee_in_scope.send(method)
end

def alias_method?
false
end

def stub_owner
def stubbee
nil
end

Expand Down
6 changes: 3 additions & 3 deletions test/acceptance/stub_module_method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ class StubModuleMethodTest < Mocha::TestCase
include StubMethodSharedTests

def method_owner
stubbed_instance.singleton_class
callee.singleton_class
end

def stubbed_instance
@stubbed_instance ||= Module.new
def callee
@callee ||= Module.new
end

# rubocop:disable Lint/DuplicateMethods
Expand Down

0 comments on commit dd3c458

Please sign in to comment.