我正在尝试为 CodeEval 上的挑战练习编写测试。每个挑战我都在创建一个文件夹,在项目文件夹中我创建“lib”和“spec”文件夹。从我运行的命令行:
rspec --init
它告诉我创建了“spec/spec_helper.rb”和“.rspec”。我将源文件放在“lib”文件夹中,将规范文件放在“spec/lib”文件夹中,并相应地命名它们。这是规范的示例:
require 'spec_helper'
require 'file_name'
describe '#swap_elements' do
it 'should swap 1 pair of numbers' do
swap_elements('1 2 3 4 5 6 7 8 9',0,8).should == '9 2 3 4 5 6 7 8 1'
end
end
我从项目的根目录运行:
rspec /spec/lib/file_name_spec.rb
结果如下:
/Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load': cannot load such file -- /spec/lib/swap_elements_spec.rb (LoadError)
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/username/.rvm/gems/ruby-2.0.0-p195/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
这是最近的一个问题,我还没有安装任何更新的 rspec gem。知道为什么会这样吗?