Swombat

wombat + s 
« Back to blog

Testing your plugin code without running rails

Scenario: you need to write a test script that should run independently from Rails, to test that your plugin hangs together.

 Of course, you can install RSpec or another test framework, create a test directory, and start gathering tests. And you should do that. But at first, you may want to just write a teeny little .rb script that will call some method in your plugin to give you a reality check that the thing is working. Yes, yes, that's not true TDD/BDD, but hey, we're not all perfect.

 So how to do that? Simple. If the script you want to run is in your plugin's root directory, just put this at the top:

 

 
require 'rubygems' 
require 'activesupport' 
 
$LOAD_PATH << "lib" 
 
ActiveSupport::Dependencies.load_paths = $LOAD_PATH 

 And bingo... you'll have all the railsy auto-loading goodness that you need to write the rest of the script.

Comments (0)

Leave a comment...

 
Got an account with one of these? Login here, or just enter your comment below.
Posterous-login    twitter