[英]RSpec explicitly tagged cases failing from NameError
I'm currently using rspec-core-3.1.7
with a rails application I've inherited. 我目前正在将
rspec-core-3.1.7
与我继承的Rails应用程序一起使用。 It seems like the previous owners made a lot of progress with their testing suite, but I can't seem to get it working properly. 以前的所有者似乎在他们的测试套件方面取得了很大的进步,但是我似乎无法使其正常运行。 My
spec_helper.rb
and rails_helper.rb
are fresh from a rails generate rspec:install
, with some minor tweaks. 我的
spec_helper.rb
和rails_helper.rb
是从新rails generate rspec:install
的rails generate rspec:install
中进行的一些细微调整。
The way the tests are set-up looks as follows: 测试的设置方式如下所示:
require "rails_helper"
RSpec.describe FooController, :type => :routing do
...
and here was the relevant error message: 这是相关的错误消息:
athan@spacerobot:~/website$ rake spec:routing
/home/athan/.rbenv/versions/2.1.2/bin/ruby -I/home/athan/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib:/home/athan/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-support-3.1.2/lib /home/athan/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/exe/rspec --pattern ./spec/routing/\*\*/\*_spec.rb
/home/athan/website/spec/routing/foo_routing_spec.rb:3:in `<top (required)>': uninitialized constant FooController (NameError)
from /home/athan/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `load'
from /home/athan/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.7/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
...
But for some reason, I can't get rspec
to find FooController
before it throws the NameError. 但是由于某些原因,在抛出NameError之前,我无法获得
rspec
来查找FooController
。 Is it a common convention to... pretend these classes exist, when describing RSpec tests? 在描述RSpec测试时,假装这些类存在是一种普遍的惯例吗? Where would they come from...?
他们从哪里来? How should I properly define test descriptions?
我应该如何正确定义测试说明?
I am not too familiar with how rails uses rspec, but I do use rspec quite a bit for my test suites. 我对Rails如何使用rspec不太熟悉,但是我在测试套件中确实使用了rspec。 I am suspecting that you need to add a require for the FooController into either the spec_helper.rb or rails_helper.rb.
我怀疑您需要在spec_helper.rb或rails_helper.rb中添加对FooController的需求。 In my case, I require all of my test framework components in the spec_helper.rb so that they are available for all the tests to use.
就我而言,我需要spec_helper.rb中的所有测试框架组件,以便可供所有测试使用。 Hope that helps.
希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.