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

Stub method shared tests #458

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c203058
move define/remove method to setup/teardown
nitishr Jan 3, 2020
36888e8
replace module_eval with send
nitishr Jan 3, 2020
c455732
prep to DRY by using send instead of direct invocation
nitishr Jan 3, 2020
d2362c5
DRY up public, protected and private checks
nitishr Jan 3, 2020
26de50e
Prep to DRY - use send & extract visibility to a var
nitishr Jan 3, 2020
6fe3702
DRY up Module public, protected and private checks
nitishr Jan 3, 2020
fec664a
prep to DRY by making assert methods near identical
nitishr Jan 3, 2020
9c47db1
DRY up assert_snapshot_unchanged_on_stubbing*
nitishr Jan 3, 2020
90570ec
inline delegating methods
nitishr Jan 3, 2020
32562f1
rename assert_snapshot_unchanged_on_stubbing_method
nitishr Jan 3, 2020
2e425af
extract & reuse StubInstanceMethodSharedTests
nitishr Jan 3, 2020
0d024d4
allow instantiation to be parameterized by subclassing
nitishr Jan 3, 2020
44037fe
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnCla…
nitishr Jan 3, 2020
388c608
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnMod…
nitishr Jan 3, 2020
b8505d1
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnSup…
nitishr Jan 3, 2020
60036df
more expressive name: stubbed_module -> method_owner
nitishr Jan 3, 2020
e9cfc66
split StubInstanceMethodDefinedOnKernelModuleTest into two
nitishr Jan 3, 2020
eef3880
return stubbed instance instead of stubbed class
nitishr Jan 3, 2020
a84b186
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnSin…
nitishr Jan 3, 2020
adc1d2f
check aliased method stubbing if stub_aliased_method
nitishr Jan 3, 2020
bffb23d
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnCla…
nitishr Jan 3, 2020
1180f77
reuse StubInstanceMethodSharedTests in StubMethodDefinedOnModuleAndAl…
nitishr Jan 3, 2020
ba0617b
reuse StubInstanceMethodSharedTests in StubClassMethod*Test
nitishr Jan 5, 2020
6d3b047
allow stub_owner to be different from stubbed_instance
nitishr Jan 5, 2020
0ea322e
split superclass test into super & child
nitishr Jan 5, 2020
6a0bbc3
remove 'instance' qualifier from shared tests
nitishr Jan 5, 2020
060ebb7
reuse StubMethodSharedTests in StubModuleMethodTest
nitishr Jan 3, 2020
1b5af22
reuse StubMethodSharedTests in StubAnyInstanceMethodTest
nitishr Jan 5, 2020
fdc2e2b
use shared tests for method private in owning module
nitishr Jan 5, 2020
620ff24
use shared tests for AnyInstance superclass checks
nitishr Jan 6, 2020
99ca183
delete test_should_be_able_to_stub_a_superclass_method
nitishr Jan 6, 2020
aad1b3f
extract assert_passed_with_snapshot_unchanged
nitishr Jan 6, 2020
18c8c49
stubbed_instance -> callee, stub_owner -> stubbee
nitishr Jan 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove 'instance' qualifier from shared tests
... since it is now used for instance as well as class methods
  • Loading branch information
nitishr committed Feb 16, 2020
commit 6a0bbc33d7f5fda5cdd60f66e51d015c62fc586b
4 changes: 2 additions & 2 deletions test/acceptance/stub_class_method_defined_on_class_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubClassMethodDefinedOnClassTest < Mocha::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include StubInstanceMethodSharedTests
include StubMethodSharedTests

def method_owner
stubbed_instance.singleton_class
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/stub_class_method_defined_on_module_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubClassMethodDefinedOnModuleTest < Mocha::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include StubInstanceMethodSharedTests
include StubMethodSharedTests

def method_owner
@method_owner ||= Module.new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubClassMethodDefinedOnSuperclassTest < Mocha::TestCase
include StubMethodSharedTests
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/stub_instance_method_defined_on_class_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubInstanceMethodDefinedOnClassTest < Mocha::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include StubInstanceMethodSharedTests
include StubMethodSharedTests

def method_owner
@method_owner ||= Class.new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubInstanceMethodDefinedOnKernelStubbedOnAnObjectTest < Mocha::TestCase
def method_owner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubInstanceMethodDefinedOnModuleTest < Mocha::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include StubInstanceMethodSharedTests
include StubMethodSharedTests

def method_owner
@method_owner ||= Module.new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubInstanceMethodDefinedOnObjectClassTest < Mocha::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include StubInstanceMethodSharedTests
include StubMethodSharedTests

def method_owner
Object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubInstanceMethodDefinedOnSingletonClassTest < Mocha::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include StubInstanceMethodSharedTests
include StubMethodSharedTests

def method_owner
stubbed_instance.singleton_class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

class StubInstanceMethodDefinedOnSuperclassTest < Mocha::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include StubInstanceMethodSharedTests
include StubMethodSharedTests

def method_owner
@method_owner ||= Class.new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require File.expand_path('../stub_instance_method_shared_tests', __FILE__)
require File.expand_path('../stub_method_shared_tests', __FILE__)

unless Mocha::PRE_RUBY_V19
class StubMethodDefinedOnModuleAndAliasedTest < Mocha::TestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include StubInstanceMethodSharedTests
include StubMethodSharedTests

def method_owner
@method_owner ||= Module.new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require File.expand_path('../acceptance_test_helper', __FILE__)

module StubInstanceMethodSharedTests
module StubMethodSharedTests
include AcceptanceTest

def setup
setup_acceptance_test
method_owner.send(:define_method, :my_instance_method) { :original_return_value }
method_owner.send(:define_method, :my_method) { :original_return_value }
end

def teardown
method_owner.send(:remove_method, :my_aliased_method) if method_owner.method_defined?(:my_aliased_method)
method_owner.send(:remove_method, :my_instance_method)
method_owner.send(:remove_method, :my_method)
teardown_acceptance_test
end

Expand All @@ -27,11 +27,11 @@ def test_should_stub_private_method_and_leave_it_unchanged_after_test
end

def assert_snapshot_unchanged_on_stubbing(visibility)
method_owner.send(visibility, :my_instance_method)
method_owner.send(:alias_method, :my_aliased_method, :my_instance_method) if alias_method?
method_owner.send(visibility, :my_method)
method_owner.send(:alias_method, :my_aliased_method, :my_method) if alias_method?
instance = stubbed_instance
stub_owner_in_scope = stub_owner || instance
method = alias_method? ? :my_aliased_method : :my_instance_method
method = alias_method? ? :my_aliased_method : :my_method
assert_snapshot_unchanged(instance) do
test_result = run_as_test do
stub_owner_in_scope.stubs(method).returns(:new_return_value)
Expand Down