Problems with Guard, Spork, Rspec & Rails 3 - ruby-on-rails

I've followed the spork railscast video and it gives me the following error when I try to run guard:
Guard is now watching at '/Users/m/work/'
Starting Spork for Test::Unit & RSpec
Couldn't find a supported test framework that begins with 'testunit'
Supported test frameworks:
( ) Cucumber
(*) RSpec
Legend: ( ) - not detected in project (*) - detected
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
--> ERROR: Could not start Spork server for Test::Unit & RSpec. Make sure you can use it manually first.
Guard::RSpec is running, with RSpec 2!
Running all specs
It looks like The spork server starts up fine and then errors and tries to carry on. I've tried making the :wait option 120 seconds and it still has the same issue.
Spork works fine if I execute the tests without guard & guard-spork
Environment:
Mac OSX
rails (3.1.1)
guard (0.8.8)
guard-rspec (0.5.4)
spork (0.9.0.rc9)
guard-spork (0.3.1)
How would I go about debugging this issue? I have no idea where to start.

I had exactly this issue on Ubuntu. My solution was simple enough:
1) I stopped guard
2) I deleted the test folder
3) started guard
This time, instead of seeing Starting Spork for Test::Unit & RSpec, I got Starting Spork for RSpec. So spork automatically recognised that my test folder was no longer needed and everything ran sweetly.
Interestingly enough the
Supported test frameworks:
( ) Cucumber
(*) RSpec
message also disappeared and I got exactly the expected results as per railscast.
The only conclusions I can come up with are:
1) This is not an OS dependant issue.
2) spork, rspec and test unit don't play nicely on Rails > v3.x apps which makes sense. You don't need both. UPDATE - Please see updated answer below if you want both.
Obviously I followed the Railscast instructions very closely but I seriously suggest that you look at deleting the test folder.
UPDATE
It should be noted that it is possible to get both to play nicely together as per the comment below from #yuvilio, a quote of which follows:
I don't think the issue is that they don't get along. I got Cucumber/Rspec/testunit to play nice with each other in spork. In my gemfile, in addition to rspec/cucumber/guard related gems, I added spork-testunit, guard-test, ruby-prof gems and ran bundle install. Then, I bootstrapped testunit: bundle exec spork testunit --bootstrap.Then customized test/test_helper.rb. Then updated the guard file watching for testunit: bundle exec guard init test. When I ran guard, I got output including Spork server for RSpec, Cucumber, Test::Unit successfully started

If you don't want to delete the test folder, you can simply tell guard to ignore it:
guard 'spork', test_unit: false do
# ...
end

Related

Spork with Capybara on Windows 7

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.

cucumber / rails error uninitialized constant DatabaseCleaner (NameError)

Anyone have any idea what is causing this error when running cucumber features?
uninitialized constant DatabaseCleaner (NameError)
Add this line to your Gemfile:
gem 'database_cleaner'
This is because cucumber-rails doesn't automatically depend on database_cleaner because you may be building a Rails application without a database, and so you must explicitly require it.
DatabaseCleaner is a library for 'cleaning' your db. Cucumber will use it between running features to ensure your db is in a testable state (ie. empty).
The idea is that you build up the proper data in your Given clauses for each test
This error just means that DatabaseCleaner hasn't been required properly.
Different versions of Rails/Cucumber have different ways of configuring everything and provide different functionality with this regard so it's hard to actually give you the right solution without knowing your setup.
A couple of tips though:
Look at the cucumber-rails gem. It gives you lots of nice stuff such as generators and also rake tasks so you can run rake cucumber instead of using cucumber directly. Often times the generators will build a config file that requires database_cleaner for you.
Otherwise, add database_cleaner to your list of dependencies and put a require 'database_cleaner' somewhere in your test suite code.
I just experienced the problem. I downgraded my cucumber gems to version 1.0.6, and I got this message:
uninitialized constant Cucumber::Rails::Database (NameError)
when I use cucumber 1.0.6 (not the latest version) and database_cleaner v. 1.7.0. For fixing the error, I just run this command (on Rails 3.1.3):
rails g cucumber:install
It will prompt you to replace file features/support/env.rb. Just answer with Y and you can run rake cucumber:ok again.
I am using spring, and spring stop work for me

How do you load Machinist's blueprints when using Spork?

How do you load Machinist's blueprints when using Spork?
Gems:
mongoid (2.0.0.rc.6)
capybara (0.4.1.1)
steak (1.1.0)
spork (0.9.0.rc2)
rspec (2.4.0)
machinist (2.0.0.beta2)
I get this error in every acceptance test:
Machinist::NoBlueprintError:
No master blueprint defined for class School
All test fail, because it doesn't find any blueprint. I some of these errors on V2(I still get a couple of No master blueprint..), but I get another error too:
Professor Create a new professor
Failure/Error: click_link("Profesores")
RangeError:
0x000000821461e4 is recycled object
I got config.cache_classes = false in test environment for this one.
Both spec_helper versions:
https://gist.github.com/801814
I'd been bashing my head against a brick wall trying to run tests on windows with all the gems you've mentioned. I wrote an article on my blog in case anyone's interested, and yes I already know, windows is balls, but I'm having to use it out of necessity:
Setting up a fast efficient testing environment using Ruby192, Rails 3.0.4, RSpec 2.5.0, Cucumber 0.10.0 and Spork!
The blog itself doesn't mention machinist but I'm actually using that 2.0.0.beta2 gem myself with spork to run my cucumber tests.
Just to rule out the obvious have you included something like this in your application.rb file:
config.generators do |g|
g.fixture_replacement :machinist
end
Also have you set up your blueprints files in:
features/support/blueprints.rb for cucumber
spec/support/blueprints.rb for rspec
and made sure you've included:
require 'machinist/active_record'
in the top of your blueprints.
Also just on another note for when you get it up and running. Machinist caches a lot of objects to make it run faster, but it may occasionally trip you up when constantly trying to clear out the database. If you run into problems you can turn off Machinists caching by adding this to your config/environments/test.rb file:
Machinist.configure do |config|
config.cache_objects = false
end

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