Why is autotest not working? - ruby-on-rails

I changed my .autotest file to use it with a Ruby-based project.
After that, when I wanted to use it for Rails, it is using the .autotest configuration settings I used for the Ruby project.
I uninstalled autotest and reinstalled it with no luck.
I also removed the .autotest file in the root directory but it is not working.

I'm trying to get autotest up and running as well. I just installed the gem. Running autotest or autotest --rails inside my rails app starts autotest, but it doesn't runs a single test. It reports that there aren't any.
UPDATE:
Just discovered I needed to install autotest-rails as well.
You should also install autotest-fsevent to make sure that autotest isn't polling all the time.
I've posted the results of my day of autotest at http://ryanbooker.com/archive/autotest-your-rails-apps.
The Short story:
sudo gem install ZenTest autotest-rails autotest-fsevent autotest-growl redgreen
Edit your ~/.autotest
# Include plugins
require 'autotest/fsevent'
require 'autotest/growl'
require 'redgreen/autotest' # yes this is correct
# Skip some paths
Autotest.add_hook :initialize do |autotest|
%w{.git .DS_Store ._* vendor}.each { |exception| autotest.add_exception(exception) }
false
end
You can launch autotest with:
cd myrailsapp
autotest

how are you launching autotest? If you use autotest --rails it should definitely work.

If you are using Rails 3.1 or higher, I highly recommend using guard for TDD with rspec. It works like magic. https://github.com/guard/guard

Related

Rspec: Could not find minitest-4.7.5 in any of the sources

This is bizarre because I am relatively certain that minitest is an independent testing framework from rspec.
In any case, what is happening is that when I run.
rspec at my rails root directory, I get this error:
Could not find minitest-4.7.5 in any of the sources
However in my Gemfile I have the following:
gem 'minitest', '~> 4.7.5'
I have tried running bundle update and bundle install to no avail. Also I feel weird even adding the gem file as I only added it after I got the error but had no intention of using the gem to begin with.
For reference here is my spec_helper.rb file.
require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
Hard to know w/o more information, it's likely something else is bringing it in if you aren't... Do this:
Revert to a clean state in your repository
Remove minutest from Gemfile
Run bundle (not update)
Look in your Gemfile.lock and see what is depending upon minitest
Post the information here if the answer doesn't become clear.
You may also want re-run rails generate rspec:install, that spec_helper.rb you posted looks pretty thin.
It turns out I just needed to run bundle exec rspec to run my tests.

How autotest in rails can run integration tests?

I have this in .autotest:
Autotest.add_hook :initialize do |autotest|
autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) do
autotest.files_matching(/^spec\/requests\/.*_spec\.rb$/)
end
end
when I run autotest it initially runs all unit and integration (\requests) tests. Then when I change a file it runs only its unit tests and not the integrations.
any idea?
You need to install and require the fsevent gem.
So:
sudo gem install autotest-fsevent
Or just gem install depending if you are using RVM
Then in your .autotest put the following require:
require 'autotest/fsevent'
You should also insure that it isn't running the whole test suite by going into the window/tab that is running autotest and hit ctrl-c once. That will restart your autotest and run all the tests that autotest is covering. I have found that autotest runs the most recent spec first then all the tests.
Hope this helps!

I can't get autotest working with Rails 3.0.4 and MongoID 2.0.0.rc.7

I'm not able to get autotest started. It just hangs after it clears the console screen:
$ autotest
loading autotest/rails_rspec2
--------------------------------------------------------------------------------
there is nothing in test.log. Other searches for this problem on S.O. don't provide an answer.
autotest 4.4.6
ZenTest 4.4.2
Rails 3.0.4
MongoID 2.0.0.rc.7
Maybe there is another place I could be looking for autotest errors?
It appears that an update to autotest (or rspec?) something somewhere made the config info in my ~/.autotest file obsolete. So i commented everything out except for:
require 'autotest/fsevent'
require 'autotest/growl'
and now it appears to be working!
no more: Autotest.add_hook(:initialize) {|autotest| ...

How to combine autotest and spork in Rails testing?

Autotest increases the speed at which tests run by running only the changed tests.
But I want to push it even further by using spork to preload the Rails environment, so that I will get even faster feedback.
Is this possible?
Autotest : https://github.com/grosser/autotest
Spork : http://github.com/timcharper/spork
ARTICLE1 mikbe has you covered! I would attempt to rephrase it here, but the post does such a great job.
If you happen to be on OSX, there are also instructions to utilize Growl for tray notifications.
ARTICLE2 Ruby Inside also has a walkthrough for Rails 3 and RSpec 2.
If you use Ruby 1.9 and want to use spork and autotest together with Test::Unit (actually MiniTest) try this:
Gemfile:
group :test do
# Newer version of test::unit:
gem 'minitest'
# spork preloads a rails instance which is forked every time the tests are
# run, removing test startup time.
gem 'spork'
# Run 'spork minitest' to start drb server (test server). Use 'testdrb' to
# run individual tests via spork.
gem 'spork-minitest'
# Run 'bundle exec autotest' to rerun relevant tests whenever a file/test is
# changed. '.autotest' makes sure the tests are run via test server (spork).
gem 'autotest-standalone'
# -pure gives us autotest without ZenTest gem.
gem 'autotest-rails-pure'
end
.autotest:
class Autotest
# run tests over drb server (spork)
def make_test_cmd files_to_test
if files_to_test.empty?
"" # no tests to run
else
"testdrb #{files_to_test.keys.join(' ')}"
end
end
end
(Note: Instructions says bin/testdrb, but I changed it to testdrb to make it work for me.)
In a terminal:
spork minitest --bootstrap
Edit test/test_helper.rband follow instructions.
After the above setup is done once, you can start the test server:
spork minitest
Finally start autotest in another terminal:
bundle exec autotest
And (hopefully) enjoy really fast autotesting with MiniTest.
I haven't tried it yet, but there's a section in chapter 3 of the RailsTutorial that tells some "hacks" to set up spork. The tutorial currently says:
... as of this writing Spork doesn’t officially support Rails 3
The chapter goes on to tell how to set it up with autotest. One thing to know is that you'll need
--drb
in your .rspec file.

autotest shows blank

I installed the autotest gem and intend to use it with rspec. The problem is, when I run autotest under my rails app, all I see is :
railsapp$ autospec
loading autotest/rails_rspec
And its stuck there until I Ctrl-C out of it. Nothing changes even if I change a rspec test or code.
Here's my ~/.autotest
require "autotest/restart"
require 'redgreen/autotest'
require 'autotest/fsevent'
require "autotest/growl"
I had the same problem. I was eventually able to get everything working by making sure I was on the latest (beta, if necessary) versions of rspec, rspec-rails, autotest, and autotest-rails, and putting the following in autotest/discovery.rb:
Autotest.add_discovery { "rails" }
Autotest.add_discovery { "rspec2" }
Here's the blog post that got me started in the right direction.
I had the same problem, and this fixed it:
"Make sure you have a .rspec file in the project root. That tells RSpec to tell Autotest to load RSpec’s autotest extension."
ref: https://github.com/rspec/rspec/wiki/autotest
It seems as if my .rspec file had gotten deleted when messing around with git.
Cd into app directory and run the command: AUTOFEATURE=true autospec
To stop this process ^C twice
I had the same problem with Rails 2.3.2 except that I'm not using RSpec. In my case, installing the autotest-rails-pure gem got it working for me. Maybe autotest requires the correct plugin in order to detect a test within a file.

Resources