Skip to content

Coverage on ERB #38

Closed
Closed

Description

@ryanb

Great work on this gem. Is it possible to check code coverage in ERB templates? In a Rails app there might be an "if" condition in a view which is not covered. It would be great if it were somehow possible to check this.

Activity

  1. colszowka commented on Apr 21, 2011

    @colszowka
    Collaborator

    No, unfortunately it's not since the underlying Ruby 1.9 Stdlib Coverage library only tracks files that are require'd after coverage starts and thus only allows .rb files (since you can only require files ending with .rb ;)

    Templates on the other hand are read from a file and evaluated later on, and thus are out of the visibility of the coverage lib.

    Sorry :/

  2. jamiew commented on Dec 2, 2012

    @jamiew

    Very old ticket, but do you know if this is possible with any other 1.9 coverage tools?

  3. eloyesp commented on Nov 23, 2017

    @eloyesp

    I know it is an old issue, but it might be possible to add a hook on ERB when it read a template file or it compiles it and add those calls to the result set. Does it makes sense? @colszowka ?

  4. dmitry commented on Nov 25, 2017

    @dmitry

    What about HAML / Slim and friends?

  5. eloyesp commented on Nov 25, 2017

    @eloyesp
  6. ioquatix commented on Jan 26, 2018

    @ioquatix

    Any update on using tracepoints?

  7. eloyesp commented on Jan 26, 2018

    @eloyesp
  8. ioquatix commented on Jan 26, 2018

    @ioquatix

    Yeah I tried using trace points and came to the same conclusion. :(

  9. bf4 commented on Jan 28, 2018

    @bf4
    Collaborator
  10. ioquatix commented on Jan 28, 2018

    @ioquatix

    I had a look in the MRI source code and for some reason it doesn't compute coverage for eval code which is being parsed.

    https://github.com/ruby/ruby/blob/582951e2c8995d6bab5ddaf98cd3816310f8d506/parse.y#L4785

    It might just be a matter if being slightly more allowing at that line, i.e. if calling eval with the optional file name argument set to something.

  11. ioquatix commented on May 23, 2019

    @ioquatix

    It works in covered but I don’t use standard coverage library because this bug still applies.

  12. mame commented on Dec 3, 2022

    @mame
    Contributor

    I have created a PR that will solve this issue: #1037

  13. added theissue type on May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions