diff --git a/lib/coverband/utils/method_definition_scanner.rb b/lib/coverband/utils/method_definition_scanner.rb index 85216474..f7200c0e 100644 --- a/lib/coverband/utils/method_definition_scanner.rb +++ b/lib/coverband/utils/method_definition_scanner.rb @@ -32,11 +32,23 @@ def coverage?(file_coverage) private def first_line_number - @method_definition.first_line_number + 1 + if multiline? + @method_definition.first_line_number + 1 + else + @method_definition.first_line_number + end end def last_line_number - @method_definition.last_line_number - 1 + if multiline? + @method_definition.last_line_number - 1 + else + @method_definition.last_line_number + end + end + + def multiline? + @method_definition.last_line_number - @method_definition.first_line_number > 1 end end diff --git a/test/coverband/collectors/coverage_test.rb b/test/coverband/collectors/coverage_test.rb index 1fdc9178..a0fe422e 100644 --- a/test/coverband/collectors/coverage_test.rb +++ b/test/coverband/collectors/coverage_test.rb @@ -23,7 +23,7 @@ def teardown file = require_unique_file coverband.report_coverage coverage = Coverband.configuration.store.coverage - assert_equal(coverage[file]["data"], [nil, nil, 1, 1, 0, nil, nil]) + assert_equal(coverage[file]["data"], [nil, nil, 1, 1, 0, nil, nil, 1, nil, 1, nil, nil]) end test "Dog method and class coverage" do @@ -31,7 +31,7 @@ def teardown Dog.new.bark coverband.report_coverage coverage = Coverband.configuration.store.coverage - assert_equal(coverage["./test/dog.rb"]["data"], [nil, nil, 1, 1, 1, nil, nil]) + assert_equal(coverage["./test/dog.rb"]["data"], [nil, nil, 1, 1, 1, nil, nil, 1, nil, 1, nil, nil]) end test "Dog eager load coverage" do @@ -45,7 +45,7 @@ def teardown coverband.eager_loading! coverage = Coverband.configuration.store.coverage[file] refute_nil coverage, "Eager load coverage is present" - assert_equal(coverage["data"], [nil, nil, 1, 1, 0, nil, nil]) + assert_equal(coverage["data"], [nil, nil, 1, 1, 0, nil, nil, 1, nil, 1, nil, nil]) end test "gets coverage instance" do diff --git a/test/coverband/utils/dead_methods_test.rb b/test/coverband/utils/dead_methods_test.rb index 83ed18eb..b45dd750 100644 --- a/test/coverband/utils/dead_methods_test.rb +++ b/test/coverband/utils/dead_methods_test.rb @@ -16,7 +16,7 @@ def setup def test_dog_dead_methods file_path = require_unique_file - coverage = [nil, nil, 1, 1, 0, nil, nil] + coverage = [nil, nil, 1, 1, 0, nil, nil, 1, nil, 1, nil, nil] dead_methods = DeadMethods.scan(file_path: file_path, coverage: coverage) assert_equal(1, dead_methods.length) @@ -56,7 +56,7 @@ def test_output_all def test_dog_methods_not_dead file = require_unique_file - coverage = [nil, nil, 1, 1, 1, nil, nil] + coverage = [nil, nil, 1, 1, 1, nil, nil, 1, nil, 1, nil, nil] assert_empty(DeadMethods.scan(file_path: file, coverage: coverage)) end end diff --git a/test/coverband/utils/method_definition_scanner_test.rb b/test/coverband/utils/method_definition_scanner_test.rb index ed7f434d..04c36123 100644 --- a/test/coverband/utils/method_definition_scanner_test.rb +++ b/test/coverband/utils/method_definition_scanner_test.rb @@ -40,7 +40,7 @@ class MethodDefinitionScannerTest < Minitest::Test def test_scan method_definitions = MethodDefinitionScanner.scan("./test/dog.rb") assert(method_definitions) - assert_equal(1, method_definitions.length) + assert_equal(3, method_definitions.length) method_definition = method_definitions.first # assert_equal(4, method.first_line) assert_equal(4, method_definition.first_line_number) assert_equal(6, method_definition.last_line_number) diff --git a/test/dog.rb b/test/dog.rb index 29c5b8bb..07d6f2ca 100644 --- a/test/dog.rb +++ b/test/dog.rb @@ -4,4 +4,9 @@ class Dog def bark "woof" end + + def single_line; end # rubocop:disable Style + + def empty + end end