Using ActionView in standalone tests
When writing Rails plugins I like to be able to test them as a stand-alone library rather than inside a specific Rails project. I find it more productive and it avoids clashes with other plugins. It also allows you to test it against multiple rails versions.
One frustration I have had is when just want to use ActionView in your tests, because you might be writing a view plugin, if you require ‘action_view’ you get the following error:
MissingSourceFile: no such file to load -- html/document
This is because the path to the html-scanner library has not been added to the loadpath. This only happens in ActionController. But if we don’t need or want the overhead of ActionController the following line will include html-scanner in the loadpath and all will be well.
$:.unshift Gem.searcher.find('actionpack').full_gem_path
+ '/lib/action_controller/vendor/html-scanner'
This finds the actionpack gem to get the full path. Then with the path to the html-scanner folder, adds it to the loadpath ($:). Now no more pesky load errors.
If there is a cleaner way, let me know.
2 comments2 Comments so far
Leave a reply

Great solution!
Just what I needed! =)
Have you ever looked at a big block of text that you had no choice but to read? A large block of text is distracting and worst of all, ineffective. Many people find their eyes glazing over when faced with a large block of text and the people looking at your exhibits are no exception vibram.