简体   繁体   中英

Error When Testing with RSpec and Guard

Trying to get a dev environment set up for a newer site with testing via RSpec / Guard. Everything seems to be working and the tests pass, but they are followed by an error seemingly unrelated to the test itself. Other solutions to similar issues on Stack have proven unsuccessful so far.

09:04:47 - INFO - Guard uses TerminalNotifier to send notifications.
09:04:47 - INFO - Guard uses TerminalTitle to send notifications.
09:04:47 - INFO - Guard::RSpec is running
09:04:47 - INFO - Guard is now watching at '/Users/Dan/Sites/mailapp'
09:04:51 - INFO - Running: spec/models/user_spec.rb
..........................

Finished in 0.92598 seconds
26 examples, 0 failures

Randomized with seed 33813

/Users/Dan/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/test/unit.rb:49:in `process_args': invalid option: -f (OptionParser::InvalidOption)
    from /Users/Dan/.rvm/gems/ruby-1.9.3-p286@mailapp/gems/minitest-4.7.5/lib/minitest/unit.rb:1066:in `_run'
    from /Users/Dan/.rvm/gems/ruby-1.9.3-p286@jurnit/gems/minitest-4.7.5/lib/minitest/unit.rb:1059:in `run'
    from /Users/Dan/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/test/unit.rb:21:in `run'
    from /Users/Dan/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
    from /Users/Dan/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
    from /Users/Dan/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'

Here's my current Gemfile

source 'https://rubygems.org'
ruby '1.9.3'

gem 'rails', '4.0.0.rc2'

gem 'mysql2'
gem 'jquery-rails'
gem 'turbolinks'
gem 'bcrypt-ruby', '3.0.1'

gem 'sass-rails', '~> 4.0.0.rc2'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'bootstrap-sass', '2.3.1.0'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'

group :development, :test do
  gem 'rspec-rails'
  gem 'capybara'
  gem 'guard-rspec'
  gem 'terminal-notifier-guard'
  gem 'rb-fsevent'
end

group :test do
  gem 'factory_girl_rails'
  gem 'database_cleaner', github: 'bmabey/database_cleaner'
end

And Guardfile

guard 'rspec' 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 features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/features/#{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

Since the offending error contained "test" and "unit" I did some searching through the /spec directory and found that at the top of my /spec/spec_helper.rb file I had the following requirement:

require 'test/unit'

Dropped that line and everything fell into place!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM