-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Acceptance test for stubbing method implemented by method_missing
See #634.
- Loading branch information
1 parent
ce31b54
commit 0a33bc1
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
test/acceptance/stubbing_method_implemented_by_method_missing_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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require File.expand_path('../acceptance_test_helper', __FILE__) | ||
|
||
class StubbingMethodImplementedByMethodMissingTest < Mocha::TestCase | ||
include AcceptanceTest | ||
|
||
def setup | ||
setup_acceptance_test | ||
end | ||
|
||
def teardown | ||
teardown_acceptance_test | ||
end | ||
|
||
def test_stubs_method_implemented_using_method_missing | ||
object = Class.new do | ||
def method_missing(symbol, *) | ||
symbol == :foo ? :method_missing_value : super | ||
end | ||
|
||
def respond_to_missing?(symbol, *) | ||
symbol == :foo | ||
end | ||
end.new | ||
test_result = run_as_test do | ||
object.stubs(:foo).returns(:stubbed_value) | ||
assert_equal :stubbed_value, object.foo | ||
end | ||
assert_passed(test_result) | ||
end | ||
|
||
def test_stubs_method_implemented_using_method_missing_when_private_method_with_same_name_exists_on_superclass | ||
superclass = Class.new do | ||
def foo | ||
:superclass_value | ||
end | ||
private :foo | ||
end | ||
object = Class.new(superclass) do | ||
def method_missing(symbol, *) | ||
symbol == :foo ? :method_missing_value : super | ||
end | ||
|
||
def respond_to_missing?(symbol, *) | ||
symbol == :foo | ||
end | ||
end.new | ||
test_result = run_as_test do | ||
object.stubs(:foo).returns(:stubbed_value) | ||
assert_equal :stubbed_value, object.foo | ||
assert_equal :stubbed_value, object.public_send(:foo) | ||
assert_equal :superclass_value, object.send(:foo) | ||
end | ||
assert_passed(test_result) | ||
end | ||
end |