Skip to content

Commit

Permalink
Refactor:extract stubbee_with_method to lower diff
Browse files Browse the repository at this point in the history
... between
test_should_allow_stubbing_existing_*_any_instance_{,super}class_method
  • Loading branch information
nitishr committed Jan 16, 2020
1 parent bbcdb07 commit 6f95b2f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test/acceptance/stubbing_non_existent_any_instance_method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def teardown
end

def test_should_allow_stubbing_existing_public_any_instance_method
assert_allows_stubbing_existing_any_instance_method(class_with_method(:public))
assert_allows_stubbing_existing_any_instance_method(stubbee_with_method(:public))
end

def test_should_allow_stubbing_method_to_which_any_instance_responds
Expand Down Expand Up @@ -66,11 +66,11 @@ def respond_to?(method, _include_private = false)
end

def test_should_allow_stubbing_existing_protected_any_instance_method
assert_allows_stubbing_existing_any_instance_method(class_with_method(:protected))
assert_allows_stubbing_existing_any_instance_method(stubbee_with_method(:protected))
end

def test_should_allow_stubbing_existing_private_any_instance_method
assert_allows_stubbing_existing_any_instance_method(class_with_method(:private))
assert_allows_stubbing_existing_any_instance_method(stubbee_with_method(:private))
end

def assert_allows_stubbing_existing_any_instance_method(klass)
Expand All @@ -88,6 +88,10 @@ def existing_method; end
klass.send(visibility, :existing_method)
klass
end

def stubbee_with_method(visibility)
class_with_method(visibility)
end
end

class AllowStubbingExistingAnyInstanceSuperclassMethodTest < Mocha::TestCase
Expand All @@ -102,15 +106,15 @@ def teardown
end

def test_should_allow_stubbing_existing_public_any_instance_superclass_method
assert_allows_stubbing_existing_any_instance_method(Class.new(class_with_method(:public)))
assert_allows_stubbing_existing_any_instance_method(stubbee_with_method(:public))
end

def test_should_allow_stubbing_existing_protected_any_instance_superclass_method
assert_allows_stubbing_existing_any_instance_method(Class.new(class_with_method(:protected)))
assert_allows_stubbing_existing_any_instance_method(stubbee_with_method(:protected))
end

def test_should_allow_stubbing_existing_private_any_instance_superclass_method
assert_allows_stubbing_existing_any_instance_method(Class.new(class_with_method(:private)))
assert_allows_stubbing_existing_any_instance_method(stubbee_with_method(:private))
end

def assert_allows_stubbing_existing_any_instance_method(klass)
Expand All @@ -128,4 +132,8 @@ def existing_method; end
klass.send(visibility, :existing_method)
klass
end

def stubbee_with_method(visibility)
Class.new(class_with_method(visibility))
end
end

0 comments on commit 6f95b2f

Please sign in to comment.