【发布时间】:2015-04-15 22:00:53
【问题描述】:
我正在编写有关 rspec 的教程,并且每当我尝试执行 rake 测试或通过终端手动运行 rspec 时,都会不断出错。这是我得到的:
mes-mbp:00_hello Me$ ls
hello.rb hello_spec.rb index.html
mes-mbp:00_hello Me$ rspec 00_hello/hello_spec.rb
/Users/Me/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- spec_helper (LoadError)
from /Users/Me/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1181:in `block in requires='
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1181:in `each'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1181:in `requires='
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration_options.rb:110:in `block in process_options_into'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration_options.rb:109:in `each'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration_options.rb:109:in `process_options_into'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/configuration_options.rb:22:in `configure'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:96:in `setup'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/Me/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'
from /Users/Me/.rvm/gems/ruby-2.2.0/bin/rspec:23:in `load'
from /Users/Me/.rvm/gems/ruby-2.2.0/bin/rspec:23:in `<main>'
from /Users/Me/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
from /Users/Me/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `<main>'
谁能告诉我我做错了什么?
编辑:有关我按要求执行的操作的更多信息: 我正在关注this 教程。在上面的代码中,我试图对 hello_spec.rb 文件中的 hello.rb 文件运行测试,该文件中包含“require hello”代码。
【问题讨论】:
-
你能发布更多关于你在做什么的信息吗?
-
touch spec_helper.rb -
我根本看不到
spec_helper文件。这甚至看起来不像是一个 Rails 应用程序。也许是辛纳特拉?您还需要在项目的根目录下运行rspec --init。这将创建像spec_helper这样的文件。 See Here 了解更多信息。 -
那些教程已经过时了——我会推荐类似codeschool.com/courses/testing-with-rspec的东西。您绝对不想开始使用 RSpec 2,然后必须学习新的 RSpec 3 语法。
标签: ruby-on-rails ruby rspec