RoR:测试:未定义的局部变量或方法“be_nil”但是ߪ我包括 RSpec、spec/spec_helper、spec/matchers 等
在我的环境/test.rb中:
config.gem "rspec"
config.gem "rspec-rails"
我的gemfile的相关部分:
group :test do
...
gem "rspec", "1.3.2"
gem "rspec-rails", "1.3.2"
在test_helper.rb中
需要'test_help' 需要“捆绑器/设置” Bundler.require(:test)
require 'factory_girl'
require 'shoulda'
require "shoulda-matchers"
require 'spec'
require 'spec/matchers'
我最近将所有 gem 移至 gemfile,而不是将 config.gem 中的所有内容都放在
env/test.rb 文件中,我必须使用两个 config.gem,否则我的测试将无法运行根本不。
我读过,包括spec_helper会有所帮助......但我的测试不在spec文件夹中......它们在测试文件夹中......当我包含spec/spec_helper.rb时,我的所有测试都会<代码>警告:已定义。
编辑:我找到了这个链接: https://github.com/rspec/rspec-rails/问题/93 它告诉我这样做
include RSpec::Matchers
,我得到了一个不同的错误:
/Users/lprestonsegoiii/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/optparse.rb:314:in `initialize': unhandled exception
编辑2: 我通过使用 IRB 发现,使用匹配器的最低限度是:
require "spec/spec_helper"
include RSpec::Matchers
但我仍然遇到重复定义问题。唔。
in my environments/test.rb:
config.gem "rspec"
config.gem "rspec-rails"
relevant part of my gemfile:
group :test do
...
gem "rspec", "1.3.2"
gem "rspec-rails", "1.3.2"
in test_helper.rb
require 'test_help'
require "bundler/setup"
Bundler.require(:test)
require 'factory_girl'
require 'shoulda'
require "shoulda-matchers"
require 'spec'
require 'spec/matchers'
I recently moved all my gems to a gemfile, instead of having everything in config.gem's
in my env/test.rb file, I have to use the two config.gem's or my tests don't run at all.
I've read that including spec_helper will help.... but my tests aren't in the spec folder... they are in the test folder... when I include spec/spec_helper.rb, all of my tests get WARNING: already defined
.
EDIT: I found this link: https://github.com/rspec/rspec-rails/issues/93
which told me to do
include RSpec::Matchers
and I got a differente error with this one:
/Users/lprestonsegoiii/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/optparse.rb:314:in `initialize': unhandled exception
EDIT2:
I've discovered through using IRB, that the minimum to use the matchers are:
require "spec/spec_helper"
include RSpec::Matchers
But I still have the duplicate definition issue. hmm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论