我正在学习关于 RSpec 测试的一章,但我一直遇到一个“加载错误”。
首先它告诉我创建一个新的分支,然后创建两个新的目录:Models 和 Spec。在这些目录中,我需要创建两个文件;models/entry.rb 和 spec/entry_spec.rb。在 spec/entry_spec.rb 文件中,我需要输入以下代码:
然后在我的
并获得以下结果:
如果有人能花时间帮助我解决问题,告诉我我可能做错了什么,我会非常感激。对于这个冗长的问题,我表示抱歉!
首先它告诉我创建一个新的分支,然后创建两个新的目录:Models 和 Spec。在这些目录中,我需要创建两个文件;models/entry.rb 和 spec/entry_spec.rb。在 spec/entry_spec.rb 文件中,我需要输入以下代码:
require_relative '../models/entry'
RSpec.describe Entry do
end
然后在我的
models/entry.rb
文件中,我应该放置这段代码:class Entry
end
我接下来需要运行这个终端命令:
$ rspec spec/entry_spec.rb
并获得以下结果:
No examples found.
Finished in 0.00015 seconds (files took 0.1186 seconds to load)
0 examples, 0 failures
但是我总是遇到这个加载错误,而且我不知道它是什么意思。
/Users/ethanfranson/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- spec_helper (LoadError)
from /Users/ethanfranson/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/configuration.rb:1295:in `block in requires='
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/configuration.rb:1295:in `each'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/configuration.rb:1295:in `requires='
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/configuration_options.rb:109:in `block in process_options_into'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/configuration_options.rb:108:in `each'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/configuration_options.rb:108:in `process_options_into'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/configuration_options.rb:21:in `configure'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/runner.rb:105:in `setup'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/runner.rb:92:in `run'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/runner.rb:78:in `run'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/lib/rspec/core/runner.rb:45:in `invoke'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.2/exe/rspec:4:in `<top (required)>'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `load'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `<main>'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/ethanfranson/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
如果有人能花时间帮助我解决问题,告诉我我可能做错了什么,我会非常感激。对于这个冗长的问题,我表示抱歉!
spec_helper
文件吗? - x6iae