{"action":"created","issue":{"url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/316","repository_url":"https://api.github.com/repos/rodjek/rspec-puppet","labels_url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/316/labels{/name}","comments_url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/316/comments","events_url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/316/events","html_url":"https://github.com/rodjek/rspec-puppet/issues/316","id":97107644,"number":316,"title":"Coverage of functions not working as expected","user":{"login":"bodgit","id":559268,"avatar_url":"https://avatars.githubusercontent.com/u/559268?v=3","gravatar_id":"","url":"https://api.github.com/users/bodgit","html_url":"https://github.com/bodgit","followers_url":"https://api.github.com/users/bodgit/followers","following_url":"https://api.github.com/users/bodgit/following{/other_user}","gists_url":"https://api.github.com/users/bodgit/gists{/gist_id}","starred_url":"https://api.github.com/users/bodgit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bodgit/subscriptions","organizations_url":"https://api.github.com/users/bodgit/orgs","repos_url":"https://api.github.com/users/bodgit/repos","events_url":"https://api.github.com/users/bodgit/events{/privacy}","received_events_url":"https://api.github.com/users/bodgit/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rodjek/rspec-puppet/labels/bug","name":"bug","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-24T18:16:57Z","updated_at":"2016-05-16T09:25:37Z","closed_at":null,"body":"I'm not 100% sure if this is rspec-puppet's fault or not but basically I was trying to add coverage reports to my modules with \"coveralls\" for any custom functions and/or types/providers. However for a given function say, my coverage report only seems to cover the flow from the last expectation, whereas I would expect it would cover the sum of all expectations.\r\n\r\nI've distilled this into a sample test module available at `bodgit/puppet-test`. If I simply reorder the expectations within `spec/functions/test_spec.rb` I can change the coverage percentage anywhere from ~30% upwards whereas I'd expect it to be the same (near 100% I think) no matter the order.\r\n\r\nIs this something specific to rspec-puppet? I'm at a bit of a loss as to where to initially go for help on this however as it seems very Puppet-specific I thought I'd try here first."},"comment":{"url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/comments/219384687","html_url":"https://github.com/rodjek/rspec-puppet/issues/316#issuecomment-219384687","issue_url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/316","id":219384687,"user":{"login":"bodgit","id":559268,"avatar_url":"https://avatars.githubusercontent.com/u/559268?v=3","gravatar_id":"","url":"https://api.github.com/users/bodgit","html_url":"https://github.com/bodgit","followers_url":"https://api.github.com/users/bodgit/followers","following_url":"https://api.github.com/users/bodgit/following{/other_user}","gists_url":"https://api.github.com/users/bodgit/gists{/gist_id}","starred_url":"https://api.github.com/users/bodgit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bodgit/subscriptions","organizations_url":"https://api.github.com/users/bodgit/orgs","repos_url":"https://api.github.com/users/bodgit/repos","events_url":"https://api.github.com/users/bodgit/events{/privacy}","received_events_url":"https://api.github.com/users/bodgit/received_events","type":"User","site_admin":false},"created_at":"2016-05-16T09:25:37Z","updated_at":"2016-05-16T09:25:37Z","body":"I've noticed some annecdotal behaviour when I was testing a custom function that did a bit of patching to work around running on Ruby 1.8.7. The function in question is here: https://github.com/bodgit/puppet-bodgitlib/blob/master/lib/puppet/parser/functions/validate_ldap_uri.rb . Originally on [line 11](https://github.com/bodgit/puppet-bodgitlib/blob/master/lib/puppet/parser/functions/validate_ldap_uri.rb#L11) I was performing a simple `=` assignment however I noticed for multiple tests of that function I would see a Ruby warning for redefining that constant so I changed it to `||=` to silence the warning. So it looks like my function gets re-imported each time it's tested rather than just get loaded once the first time it's invoked.\r\n\r\nWould Puppet (or rspec-puppet) be re-importing the function on each expectation and by doing that it resets the coverage tracking for that function somehow? That might explain the behaviour I'm seeing.\r\n\r\nI'm not going to be able to poke about with this for at least a couple of weeks but I thought I'd mention it in case it gives some inspiration.\r\n"}}