I am trying to configure SimpleCov to create reports for 3 applications that share most of their code (models, controllers) with a local stone, but the specifications for the code that each application uses are inside each. / spec, not the stone itself.
For a clearer example. When I run the exec rspec spec package inside app_1, which uses common models from the local gem, I want to get (accurate) reports for all the specifications that this app_1 has inside. / spec.
The local gem also has some models that belong exclusively to app_2, inside the namespace, so I want to skip the report for these files when I run the test suite inside app_1.
I am trying to achieve this with the following code in app_1 / spec / spec_helper.
# This couple of lines are needed to generate report for the models, etc. inside the local gem. SimpleCov.adapters.delete(:root_filter) SimpleCov.filters.clear SimpleCov.adapters.define 'my_filter' do root = SimpleCov.root.split("/") root.pop add_filter do |src| !(src.filename =~ /^
This works until some questions arise.
Why do I get 85% coverage of the model that is inside the gem, but the specification is inside app_2 (I run the spec inside app_1).
The first problem was when I tried to improve this model, so I clicked on the report for it and saw which lines were detected, and I tried to fix them by typing tests for them in app_2 / spec / namespace / my_model_spec.rb.
But it didn't matter, I tried a more aggressive test and I deleted all the content in the spec file, but somehow I still got 85% coverage, so my_model_spec.rb is not related to the coverage results my_model.rb. Kind of unexpected.
But since this file was on app_2, I decided to add a filter to the SimpleCov.start block in app_1 spec_helper, for example:
add_filter "/app_2_name_space/"
I then moved to the app_2 folder and began to configure SimpleCov and see what results I would get here. And they were weirder.
For the same model, I got 100% coverage, I did the same test as the empty my_model_spec.rb file, and still got 100%. So this is really f ** ed, or I don’t understand anything.
How it works? ( with the Ruby 1.9 coverage module , you say it’s good when I run the example locally in the official documentation, which I get different results, so I think there is an error or outdated documentation there)
ruby-doc: {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]} locally: {"foo.rb"=>[1, 1, 10, nil, nil, 1, 0, nil, 1, nil]}
I hope that in the reports there are no positive results for lines that are evaluated somewhere in the application code, no matter where.
I think the expected behavior is that the results for the model, for example, are related to spec, the same for controllers, etc.
This is true? If so, why am I getting these strange results.
Or do you think that the structure of my applications might be corrupted with SimpleCov and Coverage?
Thanks for taking the time to read this, if you need more details, just ask.