Skip to content

Commit

Permalink
Refactor: extract method run_test_with_check
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishr committed Jan 16, 2020
1 parent 2b58fe2 commit 7737927
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions test/acceptance/stubbing_method_unnecessarily_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def test_should_default_to_allow_stubbing_method_unnecessarily
end

def test_should_allow_stubbing_method_when_stubbed_method_is_invoked
Mocha.configure { |c| c.stubbing_method_unnecessarily = :prevent }
test_result = run_as_test do
test_result = run_test_with_check(:prevent) do
mock = mock('mock')
mock.stubs(:public_method)
mock.public_method
Expand All @@ -47,13 +46,17 @@ def test_should_allow_stubbing_method_when_stubbed_method_is_invoked
end

def stub_method_unnecessarily(treatment = :default)
Mocha.configure { |c| c.stubbing_method_unnecessarily = treatment } unless treatment == :default
run_as_test do
run_test_with_check(treatment) do
mock = mock('mock')
mock.stubs(:public_method)
end
end

def run_test_with_check(treatment = :default, &block)
Mocha.configure { |c| c.stubbing_method_unnecessarily = treatment } unless treatment == :default
run_as_test(&block)
end

def violation_message
'stubbing method unnecessarily: #<Mock:mock>.public_method(any_parameters)'
end
Expand Down

0 comments on commit 7737927

Please sign in to comment.