From 74068baa7c2d55c5be4a9d8912b5d2d47ad9993c Mon Sep 17 00:00:00 2001 From: OKURA Masafumi Date: Tue, 23 Apr 2024 02:06:27 +0900 Subject: [PATCH] Add spec to the result of Coverage lib for `begin` Ref: https://github.com/jruby/jruby/issues/8173 This commit is intended to make sure `Coverage` library behaves the same for the code with `begin`. JRuby had an issue so this change will help JRuby and other implementations to avoid it. --- library/coverage/code_with_begin_spec.rb | 24 ++++++++++++++++++++ library/coverage/fixtures/code_with_begin.rb | 3 +++ 2 files changed, 27 insertions(+) create mode 100644 library/coverage/code_with_begin_spec.rb create mode 100644 library/coverage/fixtures/code_with_begin.rb diff --git a/library/coverage/code_with_begin_spec.rb b/library/coverage/code_with_begin_spec.rb new file mode 100644 index 0000000000..3d5fc49637 --- /dev/null +++ b/library/coverage/code_with_begin_spec.rb @@ -0,0 +1,24 @@ +require_relative '../../spec_helper' +require 'coverage' + +describe 'Coverage for the code with begin' do + before :all do + @file = fixture __FILE__, 'code_with_begin.rb' + end + + after :each do + $LOADED_FEATURES.delete(@file) + end + + it 'covers 100% lines' do + Coverage.start + require @file.chomp('.rb') + result = Coverage.result + + result.should == { + @file => [ + nil, 1, nil + ] + } + end +end diff --git a/library/coverage/fixtures/code_with_begin.rb b/library/coverage/fixtures/code_with_begin.rb new file mode 100644 index 0000000000..9a6384e337 --- /dev/null +++ b/library/coverage/fixtures/code_with_begin.rb @@ -0,0 +1,3 @@ +begin + 'coverage with begin' +end