Skip to content

Commit

Permalink
Fix Style/Semicolon violations using auto-correct
Browse files Browse the repository at this point in the history
Also disable cop around tests using ExecutionPoint, because the tests
rely on the instantiation of ExecutionPoint being on the same line as
the following statement.
  • Loading branch information
floehopper committed Jul 26, 2018
1 parent b0ac517 commit 2cc5a52
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 20 deletions.
16 changes: 0 additions & 16 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,6 @@ Style/Documentation:
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 32
# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
Exclude:
- 'lib/mocha/debug.rb'
- 'test/acceptance/mocha_test_result_test.rb'
- 'test/acceptance/stubba_test_result_test.rb'
- 'test/acceptance/stubbing_error_backtrace_test.rb'
- 'test/acceptance/stubbing_frozen_object_test.rb'
- 'test/integration/shared_tests.rb'
- 'test/unit/any_instance_method_test.rb'
- 'test/unit/class_method_test.rb'
- 'test/unit/expectation_test.rb'
- 'test/unit/object_inspect_test.rb'

# Offense count: 777
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down
3 changes: 2 additions & 1 deletion lib/mocha/debug.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Mocha
module Debug
OPTIONS = (ENV['MOCHA_OPTIONS'] || '').split(',').inject({}) do |hash, key|
hash[key] = true; hash
hash[key] = true
hash
end.freeze

def self.puts(message)
Expand Down
2 changes: 2 additions & 0 deletions test/acceptance/mocha_test_result_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_should_include_assertion_failure_in_failure_count
assert_equal 1, test_result.failure_count
end

# rubocop:disable Style/Semicolon
def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called
execution_point = nil
test_result = run_as_test do
Expand All @@ -79,4 +80,5 @@ def test_should_display_backtrace_indicating_line_number_where_failing_assertion
assert_equal 1, test_result.failure_count
assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
end
# rubocop:enable Style/Semicolon
end
2 changes: 2 additions & 0 deletions test/acceptance/stubba_test_result_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_should_include_assertion_failure_in_failure_count
assert_equal 1, test_result.failure_count
end

# rubocop:disable Style/Semicolon
def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
execution_point = nil
test_result = run_as_test do
Expand All @@ -67,4 +68,5 @@ def test_should_display_backtrace_indicating_line_number_where_failing_assertion
assert_equal 1, test_result.failure_count
assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
end
# rubocop:enable Style/Semicolon
end
2 changes: 2 additions & 0 deletions test/acceptance/stubbing_error_backtrace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def teardown
teardown_acceptance_test
end

# rubocop:disable Style/Semicolon
def test_should_display_backtrace_indicating_line_number_where_attempt_to_stub_non_existent_method_was_made
execution_point = nil
object = Object.new
Expand Down Expand Up @@ -59,4 +60,5 @@ def test_should_display_backtrace_indicating_line_number_where_method_was_unnece
assert_equal 1, test_result.error_count
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
end
# rubocop:enable Style/Semicolon
end
2 changes: 2 additions & 0 deletions test/acceptance/stubbing_frozen_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def teardown
teardown_acceptance_test
end

# rubocop:disable Style/Semicolon
def test_should_fail_fast_if_attempting_to_stub_method_on_frozen_object
object = Object.new
object.freeze
Expand Down Expand Up @@ -84,4 +85,5 @@ def test_should_fail_fast_if_attempting_to_expect_method_on_any_instance_of_froz
assert_equal 1, test_result.error_count
assert_equal execution_point, ExecutionPoint.new(test_result.errors[0].exception.backtrace)
end
# rubocop:enable Style/Semicolon
end
2 changes: 2 additions & 0 deletions test/integration/shared_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_assertion_satisfied
assert_passed(test_result)
end

# rubocop:disable Style/Semicolon
def test_assertion_unsatisfied
execution_point = nil
test_result = run_as_test do
Expand Down Expand Up @@ -171,4 +172,5 @@ def test_real_object_expectation_does_not_leak_into_subsequent_test
assert_equal execution_point, ExecutionPoint.new(exception.backtrace)
assert_match(/undefined method `foo'/, exception.message)
end
# rubocop:enable Style/Semicolon
end
4 changes: 4 additions & 0 deletions test/unit/expectation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ def test_should_store_provided_backtrace
assert_equal backtrace, expectation.backtrace
end

# rubocop:disable Style/Semicolon
def test_should_default_backtrace_to_caller
execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
end
# rubocop:enable Style/Semicolon

def test_should_not_yield
yielded = false
Expand Down Expand Up @@ -319,10 +321,12 @@ def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_nee
assert_equal 0, assertion_counter.count
end

# rubocop:disable Style/Semicolon
def test_should_store_backtrace_from_point_where_expectation_was_created
execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
end
# rubocop:enable Style/Semicolon

class FakeMock
def initialize(name)
Expand Down
17 changes: 14 additions & 3 deletions test/unit/object_inspect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ class << object
def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed
calls = []
object = Object.new
object.replace_instance_method(:id) { calls << :id; return 1 } if Mocha::PRE_RUBY_V19
object.replace_instance_method(:object_id) { calls << :object_id; return 1 }
object.replace_instance_method(:__id__) { calls << :__id__; return 1 }
if Mocha::PRE_RUBY_V19
object.replace_instance_method(:id) do
calls << :id
return 1
end
end
object.replace_instance_method(:object_id) do
calls << :object_id
return 1
end
object.replace_instance_method(:__id__) do
calls << :__id__
return 1
end
object.replace_instance_method(:inspect) { 'object-description' }

object.mocha_inspect
Expand Down

0 comments on commit 2cc5a52

Please sign in to comment.