-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
nitishr
wants to merge
33
commits into
freerange:main
Choose a base branch
from
nitishr:stub-method-shared-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 36888e8
replace module_eval with send
nitishr c455732
prep to DRY by using send instead of direct invocation
nitishr d2362c5
DRY up public, protected and private checks
nitishr 26de50e
Prep to DRY - use send & extract visibility to a var
nitishr 6fe3702
DRY up Module public, protected and private checks
nitishr fec664a
prep to DRY by making assert methods near identical
nitishr 9c47db1
DRY up assert_snapshot_unchanged_on_stubbing*
nitishr 90570ec
inline delegating methods
nitishr 32562f1
rename assert_snapshot_unchanged_on_stubbing_method
nitishr 2e425af
extract & reuse StubInstanceMethodSharedTests
nitishr 0d024d4
allow instantiation to be parameterized by subclassing
nitishr 44037fe
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnCla…
nitishr 388c608
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnMod…
nitishr b8505d1
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnSup…
nitishr 60036df
more expressive name: stubbed_module -> method_owner
nitishr e9cfc66
split StubInstanceMethodDefinedOnKernelModuleTest into two
nitishr eef3880
return stubbed instance instead of stubbed class
nitishr a84b186
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnSin…
nitishr adc1d2f
check aliased method stubbing if stub_aliased_method
nitishr bffb23d
reuse StubInstanceMethodSharedTests in StubInstanceMethodDefinedOnCla…
nitishr 1180f77
reuse StubInstanceMethodSharedTests in StubMethodDefinedOnModuleAndAl…
nitishr ba0617b
reuse StubInstanceMethodSharedTests in StubClassMethod*Test
nitishr 6d3b047
allow stub_owner to be different from stubbed_instance
nitishr 0ea322e
split superclass test into super & child
nitishr 6a0bbc3
remove 'instance' qualifier from shared tests
nitishr 060ebb7
reuse StubMethodSharedTests in StubModuleMethodTest
nitishr 1b5af22
reuse StubMethodSharedTests in StubAnyInstanceMethodTest
nitishr fdc2e2b
use shared tests for method private in owning module
nitishr 620ff24
use shared tests for AnyInstance superclass checks
nitishr 99ca183
delete test_should_be_able_to_stub_a_superclass_method
nitishr aad1b3f
extract assert_passed_with_snapshot_unchanged
nitishr 18c8c49
stubbed_instance -> callee, stub_owner -> stubbee
nitishr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
reuse StubInstanceMethodSharedTests in StubMethodDefinedOnModuleAndAl…
…iasedTest
- Loading branch information
commit 1180f772ef769c080065b0d5b98ca6b271cb1b10
There are no files selected for viewing
35 changes: 8 additions & 27 deletions
35
test/acceptance/stub_method_defined_on_module_and_aliased_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,19 @@ | ||
require File.expand_path('../acceptance_test_helper', __FILE__) | ||
require File.expand_path('../stub_instance_method_shared_tests', __FILE__) | ||
|
||
unless Mocha::PRE_RUBY_V19 | ||
class StubMethodDefinedOnModuleAndAliasedTest < Mocha::TestCase | ||
include AcceptanceTest | ||
include StubInstanceMethodSharedTests | ||
|
||
def setup | ||
setup_acceptance_test | ||
def method_owner | ||
@method_owner ||= Module.new | ||
end | ||
|
||
def teardown | ||
teardown_acceptance_test | ||
def stubbed_instance | ||
Class.new.extend(method_owner) | ||
end | ||
|
||
def test_stubbing_class_method_defined_by_aliasing_module_instance_method | ||
mod = Module.new do | ||
def module_instance_method | ||
'module-instance-method' | ||
end | ||
end | ||
|
||
klass = Class.new do | ||
extend mod | ||
class << self | ||
alias_method :aliased_module_instance_method, :module_instance_method | ||
end | ||
end | ||
|
||
assert_snapshot_unchanged(klass) do | ||
test_result = run_as_test do | ||
klass.stubs(:aliased_module_instance_method).returns('stubbed-aliased-module-instance-method') | ||
assert_equal 'stubbed-aliased-module-instance-method', klass.aliased_module_instance_method | ||
end | ||
assert_passed(test_result) | ||
end | ||
def alias_method? | ||
true | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Covered by https://github.com/freerange/mocha/pull/458/files#diff-309245e2d37e36b0941ba90100ab52a0R4