The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Using autotest when developing Rails plugins

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jamie Hill

Posts: 161
Nickname: jamie007
Registered: Nov, 2006

Jamie Hill is Managing Director of SonicIQ Limited in the UK specialising in XHTML, CSS and Rails.
Using autotest when developing Rails plugins Posted: Jul 24, 2007 10:26 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jamie Hill.
Original Post: Using autotest when developing Rails plugins
Feed Title: The Lucid
Feed URL: http://feeds.feedburner.com/thelucid
Feed Description: Lightweight ramblings and tips on Ruby and Rails.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jamie Hill
Latest Posts From The Lucid

Advertisement

I am a great fan of ZenTest’s ‘autotest’ tool and use it continuously whilst developing Rails apps. Up until now I’d not found a way to use autotest while developing plugins.

The problem

After some digging around in the ZenTest source, it turns out that autotest looks for files that are prefixed with test_ however the standard convention in Rails is to use a suffix e.g. base_test.rb. You could simply prefix your tests instead of using suffixes and modify the test file pattern in the Rakefile, however this feels wrong.

I noticed that autotest looks for a .autotest file in the current directory before looking in the home directory meaning that getting autotest to run for plugins is surprisingly simple.

The solution

Create an .autotest file in the root of the plugin directory containing the following:

global_autotest_file = File.expand_path('~/.autotest')
load(global_autotest_file) if File.exists?(global_autotest_file)

class Autotest
 def tests_for_file(filename)
 Dir['test/**/*_test.rb']
 end
end

You can now cd into the plugin dir, run autotest and all works as it does in a Rails app1. Also as this file loads the .autotest file in the home directory, any Growl notifiers etc. setup there will all work fine.

1 The only difference is that all tests are re-loaded when a test file is saved. This is not an issue for the majority of plugins, if it is, then it’s probably a sign that the tests need optimising.

Read: Using autotest when developing Rails plugins

Topic: First Drop of the IronRuby Sourcecode Previous Topic   Next Topic Topic: Agile: Estimating

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use