3

I'm using autotest with ruby on rails. I have passing 2 passing tests when I run. rspec spec/; however, when I try to use autotest this is the output:

matt@matt-laptop:~/sample_app$ autotest
loading autotest/rails_rspec2
style: RailsRspec2
matt@matt-laptop:~/sample_app$

I get no output about the results of the tests. The same thing works with bundle exec autotest. I saw a post recommending autospec but that command is deprecated with rspec2. My Gemfile is

source 'http://rubygems.org'

gem 'rails', '3.0.5'
gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3'

group :development do
  gem 'rspec-rails', '2.5.0'
  gem 'autotest','4.4.4'
end

group :test do
  gem 'rspec', '2.5.0'
  gem 'webrat', '0.7.1'
  gem 'autotest', '4.4.4'
  gem 'redgreen', '1.2.2'
end

I have tried putting the .autotest config file in the root directory of my project as well as the home directory and neither makes a difference on the output. My .autotest file looks like this

#!/bin/ruby
require 'autotest/timestamp'

module Autotest::GnomeNotify
  def self.notify title, msg, img
    system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000"
  end

  Autotest.add_hook :ran_command do |at|
    image_root = "~/.autotest_images"
    results = [at.results].flatten.join("\n")
    results.gsub!(/\\e\[\d+m/,'')
    output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spending?|)/)
    full_sentence, green, failures, garbage, pending = $~.to_a.map(&:to_i)
  if output
    if failures > 0
      notify "FAIL", "#{output}", "#{image_root}/fail.png"
    elsif pending > 0
      notify "Pending", "#{output}", "#{image_root}/pending.png"
    else
      notify "Pass", "#{output}", "#{image_root}/pass.png"
    end
  end
 end
end

I've also checked that libnotify-bin is installed and functioning.

2 Answers 2

1

To get verbose results from rspec, create a .rspec file in your root project folder and write :

--format documentation

If i may, allow me to suggest watchr instead of autotest (with spork as well). Very easy to set up and very effective.

Take a look at

http://www.rubyinside.com/how-to-rails-3-and-rspec-2-4336.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+RubyInside+%28Ruby+Inside%29

if you like.

Sign up to request clarification or add additional context in comments.

Comments

0

I've had much the same problem with Autotest. I'm not certain, but I believe it may be very finicky about dependency versions. I'm a bit of a Rails noob, but since I so recently shared your troubles, let me show you what I did to fix the problem:

I was able to get it working by getting rid of all the code in the .autotest file and replacing it with:

require 'autotest/growl'
require 'autotest/fsevent'

To be clear, that second line should only apply if you're using OSX. I think you can safely get rid of all the "code" in your .autotest file because it relates to manual "red/green" growl notifications, which is no longer necessary once you have the "redgreen" gem installed. In short, you'll end up with a one or two line .autotest file.

Here are some files I installed via gem (some, like rspec-expectations, should be automatically installed as dependencies). The following files are the ones I believe should be relevant to your Autotest setup, the versions are the latest as of 10 minutes prior to writing this response.

  • autotest (4.4.6, 4.3.2)
  • autotest-fsevent (0.2.5, 0.2.2)
  • autotest-growl (0.2.9, 0.2.4)
  • autotest-rails-pure (4.1.2, 4.1.0)
  • redgreen (1.2.2)
  • rspec-core (2.5.1, 2.0.0.beta.18)
  • rspec-expectations (2.5.0, 2.0.0.beta.18)
  • rspec-mocks (2.5.0, 2.0.0.beta.18)
  • rspec-rails (2.5.0, 2.0.0.beta.18)
  • spork (0.8.4)
  • webrat (0.7.3)
  • ZenTest (4.5.0)

Do a gem list command to see which ones you have installed. It might be a simple matter of updating your versions and simplifying your .autotest file (I have mine in my home directory, if you care about location). Also, don't forget that the autotest-fsevent file only applies to OSX.

P.S. You'll probably STILL end up with unexplained autotest errors unless you put some additional code at the very end of your spec/controllers/spec_helper.rb file:

# Webrat configuration
Webrat.configure do |config|
config.mode = :rails
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.