rspec-simplecov 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec/simplecov/setup.rb +80 -45
- data/lib/rspec/simplecov/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2a352c8f5e4e438ff423a2d92a353154d16b29f
|
4
|
+
data.tar.gz: cd15528861cfa879636264b77369851817176210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2768133262ac5edd6cba44927daad346280ec8f32069eab8c7be098203c99ef7e450c296fd3ec513f80d6449cc849a1afb19d4018de78b4b5f316511de76c54
|
7
|
+
data.tar.gz: 3c6535d2d507401b363169f2bcbba37229fc4a869294497b294fa77242d1f88afa9720c5edf8d68a02a97f46f56ec785f103817367a13868b08322bad85acf1c
|
@@ -1,61 +1,96 @@
|
|
1
1
|
module RSpec
|
2
2
|
module SimpleCov
|
3
|
+
class Container
|
4
|
+
attr_accessor :example_group, :example_context, :example
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@example_group = nil
|
8
|
+
@example_context = nil
|
9
|
+
@example = nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
module Setup
|
4
14
|
|
5
15
|
class << self
|
6
16
|
|
7
|
-
|
8
|
-
def with_metadata_key_location_unreserved
|
17
|
+
def remove_location_from_reserver_keys
|
9
18
|
RSpec::Core::Metadata::RESERVED_KEYS.delete(:location)
|
10
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
def reinstate_location_in_reserved_keys
|
11
22
|
RSpec::Core::Metadata::RESERVED_KEYS.push(:location)
|
12
23
|
end
|
13
24
|
|
25
|
+
def build_example( context, configuration )
|
26
|
+
context.it configuration.test_case_text do
|
27
|
+
result = configuration.described_thing.result
|
28
|
+
minimum_coverage = configuration.described_thing.minimum_coverage
|
29
|
+
configuration.described_thing.running = true
|
30
|
+
|
31
|
+
expect( result.covered_percent ).to be >= minimum_coverage
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_contexts_and_example( coverage, configuration )
|
36
|
+
remove_location_from_reserver_keys
|
37
|
+
|
38
|
+
coverage.example_group = RSpec.describe( configuration.described_thing, location: 'spec_helper_spec.rb')
|
39
|
+
coverage.example_context = coverage.example_group.context configuration.context_text
|
40
|
+
coverage.example = build_example( coverage.example_context, configuration )
|
41
|
+
|
42
|
+
reinstate_location_in_reserved_keys
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_example( coverage )
|
46
|
+
RSpec.configuration.reporter.example_group_started coverage.example_group
|
47
|
+
RSpec.configuration.reporter.example_group_started coverage.example_context
|
48
|
+
RSpec.configuration.reporter.example_started coverage.example
|
49
|
+
coverage.example_group.run
|
50
|
+
end
|
51
|
+
|
52
|
+
def reset_example_group_paths( example_group, path )
|
53
|
+
example_group.metadata[ :absolute_file_path ] = path
|
54
|
+
example_group.metadata[ :rerun_file_path ] = path
|
55
|
+
example_group.metadata[ :file_path ] = path
|
56
|
+
end
|
57
|
+
|
58
|
+
def fix_example_backtrace( example, backtrace )
|
59
|
+
return unless example.execution_result.exception
|
60
|
+
|
61
|
+
example.execution_result.exception.backtrace.push( *backtrace )
|
62
|
+
end
|
63
|
+
|
64
|
+
def evaluate_and_report_result( example )
|
65
|
+
passed = example.execution_result.status == :passed
|
66
|
+
failed = !passed
|
67
|
+
|
68
|
+
RSpec.configuration.reporter.example_failed example if failed
|
69
|
+
RSpec.configuration.reporter.example_passed example if passed
|
70
|
+
end
|
71
|
+
|
72
|
+
def mark_contexts_as_finished( coverage )
|
73
|
+
RSpec.configuration.reporter.example_group_finished coverage.example_context
|
74
|
+
RSpec.configuration.reporter.example_group_finished coverage.example_group
|
75
|
+
end
|
76
|
+
|
77
|
+
def setup_execute_and_analyse_coverage_example( configuration )
|
78
|
+
include RSpec::SimpleCov
|
79
|
+
|
80
|
+
coverage = Container.new
|
81
|
+
|
82
|
+
Setup.build_contexts_and_example( coverage, configuration )
|
83
|
+
Setup.run_example( coverage )
|
84
|
+
Setup.reset_example_group_paths( coverage.example_group, configuration.caller_path )
|
85
|
+
Setup.fix_example_backtrace( coverage.example, configuration.backtrace )
|
86
|
+
Setup.evaluate_and_report_result( coverage.example )
|
87
|
+
Setup.mark_contexts_as_finished( coverage )
|
88
|
+
end
|
89
|
+
|
14
90
|
def do( configuration )
|
15
91
|
RSpec.configure do |config|
|
16
|
-
|
17
92
|
config.after(:suite) do
|
18
|
-
|
19
|
-
coverage_example_group = nil
|
20
|
-
coverage_example_context = nil
|
21
|
-
coverage_example = nil
|
22
|
-
|
23
|
-
# Build the fake test for coverage
|
24
|
-
RSpec::SimpleCov::Setup.with_metadata_key_location_unreserved do
|
25
|
-
coverage_example_group = RSpec.describe( configuration.described_thing, location: 'spec_helper_spec.rb') do
|
26
|
-
coverage_example_context = context configuration.context_text do
|
27
|
-
coverage_example = it configuration.test_case_text do
|
28
|
-
expect( configuration.described_thing.result.covered_percent ).to be >= configuration.described_thing.minimum_coverage
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Run the test
|
35
|
-
RSpec.configuration.reporter.example_group_started coverage_example_group
|
36
|
-
RSpec.configuration.reporter.example_group_started coverage_example_context
|
37
|
-
RSpec.configuration.reporter.example_started coverage_example
|
38
|
-
coverage_example_group.run
|
39
|
-
|
40
|
-
coverage_example_group.metadata[ :absolute_file_path ] = configuration.caller_path
|
41
|
-
coverage_example_group.metadata[ :rerun_file_path ] = configuration.caller_path
|
42
|
-
coverage_example_group.metadata[ :file_path ] = configuration.caller_path
|
43
|
-
|
44
|
-
if coverage_example.execution_result.exception
|
45
|
-
coverage_example.execution_result.exception.backtrace.push( *configuration.backtrace )
|
46
|
-
end
|
47
|
-
|
48
|
-
# Evaluate the result
|
49
|
-
passed = coverage_example.execution_result.status == :passed
|
50
|
-
failed = !passed
|
51
|
-
|
52
|
-
# Message the reporter to have it show up in the results
|
53
|
-
RSpec.configuration.reporter.example_failed coverage_example if failed
|
54
|
-
RSpec.configuration.reporter.example_passed coverage_example if passed
|
55
|
-
|
56
|
-
# Close out the reporter groups
|
57
|
-
RSpec.configuration.reporter.example_group_finished coverage_example_context
|
58
|
-
RSpec.configuration.reporter.example_group_finished coverage_example_group
|
93
|
+
Setup.setup_execute_and_analyse_coverage_example( configuration )
|
59
94
|
end
|
60
95
|
end
|
61
96
|
end
|