Spork with Capybara on Windows 7 - ruby-on-rails

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.

Related

Problems with Guard, Spork, Rspec & Rails 3

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

Testing one Cucumber feature takes minutes?

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.

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!

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.

How can I get Capybara #javascript tags executing correctly in Cucumber on a Rails 3 project?

I've swapped out Webrat for Capybara on a new Rails 3 project. I ran through Tim Riley's great post on it here ( http://openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara ), and also cloned his repository, executed the example cucumber feature, and saw the browser window fire open. So the whole Cucumber, Capybara, Selenium stack seems to work fine in that instance.
However if I create a new Rails 3 project, run through setting up a similar example project, and annotate a Scenario with #javascript the browser window does not fire, and the Cucumber Scenario just fails with the usual Command failed with status (1) event (which, in the instance of failing or pending steps, Cucumber triggers by design for the benefit of CI tools).
Apart from the #javascript functionality provided by Capybara, all other features work fine.
Am I missing something incredibly obvious? Is there a way for a BDD newcomer to look deeper into the issues (the stack trace just shows the standard rake error when Cucumber fails).
rvm 1.9.2-head
gem 'rails', '3.0.0.rc'
gem 'cucumber'
gem 'cucumber-rails'
gem 'capybara'
gem 'culerity'
gem 'celerity', :require => nil
The issue is actually with cucumber-rails and a missing dependency on DatabaseCleaner: http://github.com/aslakhellesoy/cucumber-rails/issues#issue/36
The issue is manifested when adding a #javascript tag to a cucumber feature. By default the cucumber options suppress the warnings that would have alerted me to the fact. By updating config/cucumber.yml to:
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~#wip"
the error is shown when running cucumber: uninitialized constant DatabaseCleaner (NameError)
The quick fix in this case is to add gem 'database_cleaner' to the project's Gemfile.
Capybara is "lazy" in that it will open the browser window first when it is actually needed. If you're actually doing something that would require a browser, Capybara won't open one.
Maybe you have not installed the mongrel gem. The browser automation is somehow not working with webrick and i have experienced the same silent failing the you describe here.
Adding
gem 'mongrel', '>= 1.2.0.beta.1'
to my Gemfile solved it.
I made an example app on how to configure that: github.com/lailsonbm/contact_manager_app/

Resources