我有这个目录结构:
project_dir
spec
person
person_invalid_address_examples.yaml
person_spec.rb
rakefile.rb
person_spec.rb 中有这段代码:
describe "Create person tests"
...
context "Person with invalid address" do
invalid_address_examples = []
File.open("person_invalid_address_examples.yaml", "r") do |file|
invalid_address_examples = YAML::load(file)
end
invalid_address_examples.each do |example|
it "Does not allow to create person with #{example[:description]}" do
person.address = example[:value]
result = person.create
result.should_not be_success
end
end
end
...
end
现在,当我从 person 目录运行时,rspec person_spec.rb
一切都按预期工作。但是,如果我从 rakefile 运行 RSpec rake 任务,我会收到No such file or directory
错误...问题显然也反过来存在 - 如果我使用相对于 rakefile 位置的路径配置文件名,则 RSpec rake 任务工作正常,但我No such file or directory
从rspec runner .. 有没有办法用路径配置文件名,以便它同时适用于 RSpec rake 任务和 Rspec runner?