Rspec2, Rails3, не могу запустить спецификацию rspec

Я только что установил Rspec2 в свой проект Rails3 (3.0.3). Когда я запускаю спецификацию rspec из корня рельсов, я получаю:

No examples were matched. Perhaps {:if=>#<Proc:0x00000100933388@/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:50 (lambda)>, :unless=>#<Proc:0x00000100933360@/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:51 (lambda)>} is excluding everything?


Finished in 0.00004 seconds
0 examples, 0 failures

Я могу запустить rspec name_of_spec_test.rb напрямую, и это, кажется, работает, но не общая команда «rspec spec». Кроме того, если я добавлю require 'spec_helper.rb' в начало моего файла name_of_spec_test.rb, я получаю:

/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
    from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644:in `open'
    from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644:in `block in connect'
    from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
    from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
    from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644:in `connect'
    from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
    from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:626:in `start'
    from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1168:in `request'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/connection.rb:15:in `execute'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/client.rb:151:in `execute'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/client.rb:146:in `send_and_receive'
    from (eval):2:in `post'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/client.rb:55:in `update'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/client.rb:75:in `add'
    from /Users/ivan/Documents/Projects/catalog_service.git/app/models/search/cake_to_solr.rb:39:in `<class:Playlist>'
    from /Users/ivan/Documents/Projects/catalog_service.git/app/models/search/cake_to_solr.rb:11:in `<top (required)>'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `block in require'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:227:in `load_dependency'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:346:in `require_or_load'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:300:in `depend_on'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:216:in `require_dependency'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:137:in `each'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:137:in `block in eager_load!'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:135:in `each'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:135:in `eager_load!'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application.rb:108:in `eager_load!'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
    from /Users/ivan/Documents/Projects/catalog_service.git/config/environment.rb:5:in `<top (required)>'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from /Users/ivan/Documents/Projects/catalog_service.git/spec/spec_helper.rb:3:in `<top (required)>'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from /Users/ivan/Documents/Projects/catalog_service.git/spec/models/search_test.rb:1:in `<top (required)>'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
    from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'

Я использую RVM для управления своей средой rails.

Я не знаю, имеет ли это значение, но когда я изначально запускал script/rails generate rspec:install, он только устанавливал .rspec, создавал каталог спецификаций и spec/spec_helper.rb.

Кроме того, я не использую миграции rails, потому что у нас есть множество баз данных, к которым мы подключаемся. Итак, когда я создаю модель и тестирую ее, я вручную создаю каталог spec/models и помещаю в него свой файл *_test.rb rspec.

Буду очень признателен за любые идеи о том, что мне здесь не хватает!

Вот мой Gemfile, файл spec_helper.rb и файлы test.rb.

Gemfile:

source 'http://rubygems.org'

gem 'rails'
gem 'mysql2', '0.2.6'
gem 'legacy_data'
gem 'htmlentities'
gem 'httparty'
gem 'net-ssh'
gem 'net-sftp'
gem 'rsolr'
gem 'activerecord-import'
gem 'ar-extensions'


# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Gems for RSpec
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
   gem 'rspec-rails'
   gem 'webrat'
   gem 'rspec'
end
gem 'autotest'

spec_helper.rb:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  # == Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # 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"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = false
end

тест.rb:

CatalogService::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # The test environment is used exclusively to run your application's
  # test suite.  You never need to work with it otherwise.  Remember that
  # your test database is "scratch space" for the test suite and is wiped
  # and recreated between test runs.  Don't rely on the data there!
  config.cache_classes = true

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Raise exceptions instead of rendering exception templates
  config.action_dispatch.show_exceptions = false

  # Disable request forgery protection in test environment
  config.action_controller.allow_forgery_protection    = false

  # Tell Action Mailer not to deliver emails to the real world.
  # The :test delivery method accumulates sent emails in the
  # ActionMailer::Base.deliveries array.
  config.action_mailer.delivery_method = :test

  # Use SQL instead of Active Record's schema dumper when creating the test database.
  # This is necessary if your schema can't be completely dumped by the schema dumper,
  # like if you have constraints or database-specific column types
  # config.active_record.schema_format = :sql

  # Print deprecation notices to the stderr
  config.active_support.deprecation = :stderr

end

Спасибо за любые мысли заранее!


person Sly    schedule 06.05.2011    source источник
comment
Разве rspec обычно не предпочитает, чтобы файлы спецификаций назывались *_spec.rb, а не *_test.rb, которые вы используете?   -  person Brian    schedule 06.05.2011
comment
Брайан - в этом ты прав! Спасибо что подметил это. Как только я переименовал свои файлы в *_spec.rb, запуск rspec spec находит все файлы _spec в папке spec. Спасибо!   -  person Sly    schedule 09.05.2011
comment
Рад, что эта часть работает для вас   -  person Brian    schedule 09.05.2011


Ответы (2)


Похоже, вы были правы, добавив spec_helper и, возможно, поместив rsolr в группу => [: development, : production], потому что похоже, что тестовая среда загружает Solr и по какой-то причине дает сбой?

person RyanWilcox    schedule 06.05.2011
comment
Привет, Райан, спасибо за идею... к сожалению, в этом случае мне действительно нужен rsolr во время теста, поскольку часть того, что я тестирую, является интерфейсом для Solr, и для этого требуется библиотека rsolr. Тем не менее, продолжая эту идею... поток ошибок указывает, что скрипт cake_to_solr.rb вызывается как одна из моих моделей, хотя в этом тесте я вообще не использую эту модель... следуя этому, чтобы понять, почему rspec попробуй использовать эту модель... - person Sly; 09.05.2011

Вы можете проверить шаблон по умолчанию. Похоже, вы сказали, что ваши файлы были названы «spec/models/XXXX_test.rb», а rspec по умолчанию ищет окончание «_spec.rb».

person wesgarrison    schedule 11.07.2011