Tag-Archive for » autotest «

Tuesday, December 09th, 2008 | Author: viking

In one of my Rails projects, I have some views that are rendered through ERB and others through HAML. This makes it annoying to jump to a view’s spec via rails.vim, since it currently doesn’t handle custom Rcommand’s that accept multiple suffixes.

When I asked tpope today about this, he brought up a good point. Why are view specs associated with an engine type (such as ERB or HAML) by default? You should be able to convert an ERB view to a HAML view and use the same tests.

Per his tip, I renamed my views from names like new.html.haml_spec.rb to just new.html_spec.rb. Unfortunately, autotest stopped recognizing the correlation between my views and my view specs. Putting this in my .autotest file fixed the issue:

Autotest.add_hook :initialize do |at|
  at.remove_mapping(%r%^app/views/(.*)$%)
  at.add_mapping(%r%^app/views/(.*)$%) do |f, md|
    # strip off engine name
    path = md[1].sub(/\.(erb|haml)$/, "")
    at.files_matching(%r{spec/views/#{path}_spec.rb})
  end
end

I hope that helps someone. :)

Category: rails  | Tags: , ,  | Leave a Comment
Friday, November 21st, 2008 | Author: viking

I recently decided to write a Ruby wrapper for the oRTP library so I can eventually implement a little RTSP server in Ruby. I wanted to use autotest for my testing, but it didn’t work out of the box since I’m testing code that lives in the ext/ directory. I wanted autotest to rebuild my extension after each change to the source file. So I came up with an .autotest file that looks like this:

Autotest.add_hook :run_command do |at|
  puts "Re-building extensions..."
  Dir.chdir(File.dirname(__FILE__) + "/ext") do
    `make`
  end
end
 
Autotest.add_hook :initialize do |at|
  at.add_mapping(%r{^ext/(\w+)\.c$}) do |f, md|
    at.files_matching(%r{test/test_#{md[1]}.rb})
  end
end

The beginnings of my code for this project is on teh Githubz.

Category: ruby  | Tags: ,  | Leave a Comment