Though I'm used to follow this strategy, I feel uncomfortable when I have a source-file and I can't see where the spec, covering this code, is located.
I'm using Guard which runs the tests for changed files automatically. Guard then has the same problem as I do, it doesn't know where the tests are and does nothing when the file is modified.
Although, running the full test-suite, of course will cover the "helper-class".
Today I found a way out of this dilemma. I'm not sure if I'll do this from now on, but I'll give it a try for a while.
When I extract a helper-class which is fully covered by an existing test, I create a spec-file for this class at the place where I (and Guard) will expect it to be.
But I don't move the tests, I just add one spec to it:
describe "HelperClass" do
it "is covered by SomeController" do
expect( cover_source_by( "some_controller_spec.rb" ) ).to be_true
end
end
cover_source_by touches 'some_controller_spec.rb' if it's older than 'helper_class.rb'.
Now, I can easily find the related spec_file for my helper-class and guard will run the right spec immediately whenever helper_class.rb is modified.
Creating the helper-spec can be appended to the refactoring-script which I use to extract the class itself; so I'm not wasting a second on this.
And even more. Should I ever delete "some_controller" SimpleCov will mark the source of HelperClass as not covered and give me the hint to remove this, now unused, code.
Which wouldn't happen if I move the tests too.
I think that's a cool approach. Or do you see any smell?