尝试运行bundle exec rspec spec / models / user_spec.rb但未能执行(参见下面的错误).
user_spec.rb的内容:
require 'rails_helper' describe User do pending "add some examples to (or delete) #{__FILE__}" end
如果我删除最后3行,则完成0个示例和0个失败.但是,当最后3行存在时,会产生错误
/spec/models/user_spec.rb:4:in `<top (required)>': uninitialized constant User (NameError) from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load' from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `block in load_spec_files' from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `each' from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load_spec_files' from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:97:in `setup' from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:85:in `run' from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:70:in `run' from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:38:in `invoke' from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/exe/rspec:4:in `<top (required)>' from /usr/local/bin/rspec:23:in `load' from /usr/local/bin/rspec:23:in `<main>'
它似乎不知道用户是什么,并将其视为常量,而这实际上是一个模型.我已经在ruby沙箱中验证了我可以在数据库中创建新用户.有任何想法吗?
回答:
从.rspec中删除–warnings后(感谢kirti),目前的错误是关于水豚版本太低(需要2.2).安装最新版本(修改gemfile和bundle install)后,rspec似乎正在正确执行.感谢大家的意见.