rspec <top(必需)>错误 - 没有其他好的信息 - 根本原因是什么?</top(必需)>

时间:2013-04-30 18:42:50

标签: ruby rspec ruby-on-rails-3.2 rspec-rails spork

这是我的设置:

rails 3.12.2,rspec 2.13.1,spork 0.9.2,mysql gem 0.3.11。我是RoR和rspec的新手。

我在后台运行spork,spork没有报告任何问题。

当我用:

运行模型测试时

rake spec:models --trace

我得到以下结果:

 Invoke spec:models (first_time)
 Invoke test:prepare (first_time)
 Invoke db:test:prepare (first_time)
 Invoke db:abort_if_pending_migrations (first_time)
 Invoke environment (first_time)
 Execute environment
 Invoke db:load_config (first_time)
 Execute db:load_config
 Execute db:abort_if_pending_migrations
 Execute db:test:prepare
 Invoke db:test:load (first_time)
 Invoke db:test:purge (first_time)
 Invoke environment
 Invoke db:load_config
 Execute db:test:purge
 Execute db:test:load
 Invoke db:test:load_schema (first_time)
 Invoke db:test:purge
 Execute db:test:load_schema
 Invoke db:schema:load (first_time)
 Invoke environment
 Invoke db:load_config
 Execute db:schema:load
 Execute test:prepare
 Execute spec:models
 ruby.exe -S rspec ./spec/models/user_spec.rb
 ..

  Finished in 0.51565 seconds
  2 examples, *0 failures*

  Randomized with seed 540

<-- Slave(1) run done!
**rake aborted!**
ruby.exe -S rspec ./spec/models/user_spec.rb     **failed**
/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:156:in `run_task'
/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:124:in `block (2 levels) in initialize'

....

/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `**<top (required)>**'
bin/rake:19:in `load'
bin/rake:19:in `<main>'
Tasks: TOP => spec:models

所以我的测试似乎通过了,但整体的rspec结果都失败了。如果我运行没有 spork它就可以了。所以我的(修改过的)问题是如何让它与spork一起工作?有什么我需要配置spork来解决我看到的问题?下面是rspec和spork文件。

这是“用户”的rspec:

require_relative '../spec_helper'
require_relative '../../app/models/user'

describe User do

before :each do
    @user = User.new login: 'TestUser', name: 'Test User 999'
end


it "login and name are required fields" do
  @user.name.should_not be_nil
  @user.login.should_not be_nil
end

it "can be instantiated" do
  User.new.should be_an_instance_of(User)
end
end

这是spec_helper.rb内容:

require 'spork'
Spork.prefork do

# 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|


  # 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.order = "random"
  end
 end

Spork.each_run do
 # This code will be run each time you run your specs.

end

那么使用spork运行时上面出现“需要顶部”错误的根本原因是什么?我是否提供了确定根本原因所需的一切?

我已经查看了其他问题(What does mean <top (required)> in rspec?)(What does "<top (required)>" mean in a Ruby stack trace?),但问题不同。

TIA,

斯科特

0 个答案:

没有答案