Actions
Feature #13838
closedAdd the ability to detect Coverage status
Status:
Closed
Assignee:
-
Target version:
-
Description
Description¶
I want to detect current status of Coverage, which is enabled or not.
Now we can detect status only trying Coverage.peek_result
or Coverage.result
and catch RuntimeError.
Attached patch enable us to detect status without any exceptions.
Why¶
My daily work is developing a web application with Ruby.
I am using Coverage.peek_result
to record coverage information on a per-request basis.
When recording coverage information, I want to start Coverage on a part of production servers,
because Coverage tool may have some overhead.
In this case, the code of my program looks like
# Implement as Rack middleware
class CoverageMiddleware
def initialize(app)
@app = app
end
def call(env)
# To ensure return response, rescue exceptions
before = Coverage.peek_result rescue nil
res = @app.call(env)
after = Coverage.peek_result rescue nil
if (before && after)
write_file(diff(before, after))
end
return res
end
end
Example¶
By using `Coverage.enabled?, I can
class CoverageMiddleware
def initialize(app)
@app = app
end
def call(env)
if Coverage.enabled?
before = Coverage.peek_result
res = @app.call(env)
after = Coverage.peek_result
write_file(diff(before, after))
else
res = @app.call(env)
end
return res
end
end
Files
Updated by yui-knk (Kaneko Yuichiro) about 7 years ago
- Tracker changed from Bug to Feature
- Backport deleted (
2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN)
Updated by mame (Yusuke Endoh) about 7 years ago
- Status changed from Open to Closed
I think this is a duplicate of #13667. Let us discuss this issue in that ticket. Thank you!
Updated by yui-knk (Kaneko Yuichiro) about 7 years ago
Sorry I overlooked the issue :)
Actions
Like0
Like0Like0Like0