Question

SOLVED: Took out the spork code in the guardfile and copy and pasted a working guardfile from another one of my apps that works with spork and guard.

I installed Guard and Spork into my app. Guard works fine but when I run Spork, Spork loads and says ready and listening. As soon as I open a new terminal and start rspec, the Spork is killed in the first terminal, and this appears...

jason@jason:~/ror/blog$ guard
14:57:44 - INFO - Guard here! It looks like your project has a Gemfile, yet you are 
running
> [#] `guard` outside of Bundler. If this is your intent, feel free to ignore this
> [#] message. Otherwise, consider using `bundle exec guard` to ensure your
> [#] dependencies are loaded correctly.
> [#] (You can run `guard` with --no-bundler-warning to get rid of this message.)
14:57:45 - INFO - Guard uses NotifySend to send notifications.
14:57:45 - INFO - Guard uses TerminalTitle to send notifications.
14:57:45 - INFO - Guard is now watching at '/home/jason/ror/blog'
14:57:45 - INFO - Starting Spork for RSpec
Using RSpec
Preloading Rails environment
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 
2.8.0
Loading Spork.prefork block...
Spork is ready and listening on 8989!
14:58:02 - INFO - Spork server for RSpec successfully started
14:58:03 - INFO - Guard::RSpec is running, with RSpec 2!
14:58:03 - INFO - Running all specs

On the original terminal this appears...

jason@jason:~/ror/blog$ spork
Using RSpec
Preloading Rails environment
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 
2.8.0
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Killed
jason@jason:~/ror/blog$ 

Here is my spec_helper file

require 'rubygems'
require 'spork'

Spork.prefork do

  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|

    # config.mock_with :mocha
    # config.mock_with :flexmock
    # config.mock_with :rr
    config.mock_with :rspec

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    config.use_transactional_fixtures = true

    config.infer_base_class_for_anonymous_controllers = false

    config.treat_symbols_as_metadata_keys_with_true_values = true
    config.filter_run :focus => true
    config.run_all_when_everything_filtered = true

  end
end

Spork.each_run do
  FactoryGirl.reload
end

Here is my Guardfile

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

require 'active_support/core_ext'

guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' 
=> 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch(%r{^config/environments/.+\.rb$})
  watch(%r{^config/initializers/.+\.rb$})
  watch('spec/spec_helper.rb')
  watch(%r{^spec/support/.+\.rb$})
end


guard 'rspec', :version => 2, :all_after_pass => false do
 watch(%r{^spec/.+_spec\.rb$})
 watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
 watch('spec/spec_helper.rb')  { "spec" }


  # Rails example
watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }  
watch(%r{^app/(.*)(\.erb|\.haml)$})                { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing
/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance
/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
watch('config/routes.rb')                           { "spec/routing" }
watch('app/controllers/application_controller.rb')  { "spec/controllers" }


  # Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests
/#{m[1]}_spec.rb" }


# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#
{m[1]}.feature")][0] || 'spec/acceptance' }
end

My gemfile contains

group :test do
  gem 'capybara', '1.1.2'
  gem 'rb-inotify', '0.8.8'
  gem 'libnotify', '0.5.9'
  gem 'factory_girl_rails', '4.1.0'
  gem 'cucumber-rails', '1.2.1', :require => false
  gem 'database_cleaner', '0.7.0'
end

group :development, :test do
  gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '1.2.1'
  gem 'guard-spork', '1.2.0'
  gem 'spork', '0.9.2'
end

Although it looks like it is working, the tests take the same amount of time so I know spork can't be working.

Was it helpful?

Solution 2

Took out the spork code in the guardfile and copy and pasted a working guardfile from another one of my apps that works with spork and guard. In the end, I didn't need the spork section in my guardfile.

OTHER TIPS

Why you have two guard 'rspec', :version => 2 do in your guard file? You should remove the first one. And try add this in your guard file:

guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch(%r{^config/environments/.+\.rb$})
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb')
  watch('test/test_helper.rb')
  watch('spec/support/')
end

But, you need to remember: place Spork guard before RSpec/Cucumber/Test::Unit guards!) . You can take a loot a my blog hkthanh89, i have sum up some information to create spork and guard.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top