Rspec2,Rails3,无法运行rspec规范

时间:2011-05-06 18:54:10

标签: ruby-on-rails rspec2

我刚在Rails3(3.0.3)项目中安装了Rspec2。当我从rails root运行rspec spec时,我得到:

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”命令。另外,如果我将'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环境。

我不知道这是否相关,但是当我最初运行脚本/ rails生成rspec时:安装它只安装.rspec,创建spec dir和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

test.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

提前感谢您的任何想法!

2 个答案:

答案 0 :(得分:0)

通过添加spec_helper看起来你是正确的,也许把rsolr放在一个组=&gt; [:development,:production],因为看起来测试环境正在加载Solr并因某种原因而失败?

答案 1 :(得分:0)

您可以检查默认模式。看起来你说你的文件名为“spec / models / XXXX_test.rb”,rspec查找默认结束的“_spec.rb”。