Skip to content

Commit e187f85

Browse files
bjfisheregon
authored andcommitted
Fix coverage results when source contains class_eval
1 parent 76f739f commit e187f85

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

.mspec.constants

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ComparisonTest
4141
ConstantSpecsIncludedModule
4242
ConstantVisibility
4343
Coverage
44+
CoverageSpecs
4445
CustomArgumentError
4546
DRb
4647
DRbIdConv
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
5 + 5
2+
3+
module CoverageSpecs
4+
5+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
6+
attr_reader :ok
7+
RUBY
8+
9+
end
10+
11+
4 + 4

library/coverage/result_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
before :all do
66
@class_file = fixture __FILE__, 'some_class.rb'
77
@config_file = fixture __FILE__, 'start_coverage.rb'
8+
@eval_code_file = fixture __FILE__, 'eval_code.rb'
89
end
910

1011
after :each do
1112
$LOADED_FEATURES.delete(@class_file)
1213
$LOADED_FEATURES.delete(@config_file)
14+
$LOADED_FEATURES.delete(@eval_code_file)
1315
end
1416

1517
it 'gives the covered files as a hash with arrays of count or nil' do
@@ -75,4 +77,16 @@
7577
require @config_file.chomp('.rb')
7678
Coverage.result.should_not include(@config_file)
7779
end
80+
81+
it 'returns the correct results when eval is used' do
82+
Coverage.start
83+
require @eval_code_file.chomp('.rb')
84+
result = Coverage.result
85+
86+
result.should == {
87+
@eval_code_file => [
88+
1, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1
89+
]
90+
}
91+
end
7892
end

0 commit comments

Comments
 (0)