3 ms·
This is an interesting approach. One change I would make is in the testing of the lib directory. I've found it best to separate the testing of the lib directo
by typicalrunt 14y ago
This is an interesting approach.
One change I would make is in the testing of the lib directory. I've found it best to separate the testing of the lib directory contents from the unit and functional tests that are baked into Rails. It requires a bit of custom setup, but it's easy to reuse in other applications.
1. Create a test/lib directory
2. Create a lib/tasks/test_libs.rake file
3. Put the following into the Rake file[1]:
namespace :test do
desc "Test libraries"
Rake::TestTask.new(:libs) do |t|
t.libs << "test"
t.pattern = 'test/lib/**/*_test.rb'
t.verbose = false
end
end
lib_task = Rake::Task["test:libs"]
test_task = Rake::Task[:test]
test_task.enhance { lib_task.invoke }
4. Run `rake test:libs` to test just your lib directory.
[1] Credit goes to http://stackoverflow.com/a/1588496 http://stackoverflow.com/a/1588496 for this Rake task.
- rubyskills 14y agoJust to be clear, the code inside of the lib and test directories is not actually inside of our rails application. They're inside of a different git repository and are packed as a separate gem. It makes more sense to me once you've isolated the code this way that you would then write "use case tests" and then role tests (which I haven't gotten into yet.. next post :))