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!
Related
Here is my problem: I have started spork on my Windows 7 and it just works fine (2 magazine_slave_service are setup -- after several attempts though). But when I run bundle exec rspec spec to execute my RSpec tests on another console, it gives me this error message:
undefined method 'read_all' for nil:NilClass <NoMethodError>
It's in 1.8/gems/...../lib/spork/run_strategy/magazine.rb:89:in 'run'
P.S: When I run rake spec it just does what's expected, my problem shows up when I want to use spork to speed up my BDD.
I'm running spork on Win7-x86/Ruby1.8.7.
Any ideas?
And the answer is:
Add gem 'spork', '> 0.9.0.rc9' (Instead of gem 'spork', '~> 0.9.0.rc9')
Run "rspec spec/models" (for models)
Although, in general spork seems like doesn't work fine in windows ..sometimes it can't fork the processes properly. It works fine randomly (at least for me!)..You should try again and again to get it working.
I've got the following gems installed for testing:
gem 'rspec-rails'
gem 'spork'
gem "factory_girl_rails"
gem "capybara"
gem "guard-rspec"
gem 'cucumber-rails'
gem 'database_cleaner'
All my tests take forever to run - testing one feature with Cucumber takes a good two minutes, and this is with Spork running with nearly everything in prefork.
The test itself took 0.544s on the last run, but it seems to be running cron.rake, rakefile, and I don't know what else. I checked these two files and they don't seem to have anything significant going on. Do you have any pointers for how I can improve this situation?
The readout:
San-iMac:app san$ rake cucumber features/user_sessions.feature
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
Running cron.rake
begin Rakefile
/Users/san/.rvm/rubies/ruby-1.9.2-p0/bin/ruby -S bundle exec cucumber --profile default
Using the default profile...
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
Feature: User Sessions
...
I suspect Rake is the problem. Try running cucumber directly instead, with "bundle exec cucumber" if you are using Bundler, or just "cucumber".
Are you using windows? We've noticed it takes much longer to spin up cucumber on windows than linux or mac.
I appreciate it might not be that easy to switch, but it'll typically save a couple of minutes per spin up.
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.
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.
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