我正在尝试练习为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宝石。你知道为什么会出现这种情况吗?
/spec/lib/swap_elements_spec.rb
文件,并且它是“可加载的”? - Peter Alfvin