Skip to content

Commit

Permalink
use StubbingPublicMethodIsAllowed in StubbingExistingMethodIsAllowed
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishr committed Jan 16, 2020
1 parent d2932ce commit 8f6a9b4
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions test/acceptance/stubbing_existing_method_is_allowed.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
require File.expand_path('../acceptance_test_helper', __FILE__)
require File.expand_path('../stubbing_public_method_is_allowed', __FILE__)

module StubbingExistingMethodIsAllowed
include AcceptanceTest

def setup
setup_acceptance_test
end

def teardown
teardown_acceptance_test
end

def test_should_allow_stubbing_existing_public_method
assert_allows_stubbing_existing_method(:public)
end
include StubbingPublicMethodIsAllowed

def test_should_allow_stubbing_existing_protected_method
assert_allows_stubbing_existing_method(:protected)
Expand All @@ -23,28 +11,12 @@ def test_should_allow_stubbing_existing_private_method
assert_allows_stubbing_existing_method(:private)
end

def test_should_allow_stubbing_method_responded_to
method_owner.send(:define_method, :respond_to?) do |method|
(method == :method_responded_to)
end
assert_allows_stubbing_method(:method_responded_to)
end

def assert_allows_stubbing_existing_method(visibility)
method_owner.send(:define_method, :existing_method) {}
method_owner.send(visibility, :existing_method)
assert_allows_stubbing_method(:existing_method)
end

def assert_allows_stubbing_method(stubbed_method)
Mocha.configure { |c| configure_violation(c, :prevent) }
stub_owner_in_scope = stub_owner
test_result = run_as_test do
stub_owner_in_scope.stubs(stubbed_method)
end
assert_passed(test_result)
end

def configure_violation(config, treatment)
config.stubbing_non_existent_method = treatment
end
Expand Down

0 comments on commit 8f6a9b4

Please sign in to comment.