# /spec/presenters/pdf_download_spec.rb
describe "instance methods" do
let(:survey) { Survey.create :title => "test survey" }
let(:pdf_download) { PdfDownload.new survey }
before do
# only write to tmp folders
PdfDownload.any_instance.stub(:location_prefix) { '../tmp' }
end
it "should stub location prefix properly" do
pdf_download.system_path.should_not be_empty
pdf_download.system_path.should be_include File.join(Rails.root, 'tmp')
pdf_download.system_path.should be_start_with File.join(Rails.root, 'tmp')
end
end
# app/models/pdf_download.rb
def system_path
File.expand_path File.join Rails.root, "public", location_path
end
失败讯息:
1) PdfDownload instance methods should stub location prefix properly
Failure/Error: expect(pdf_download.system_path).to be_empty
NameError:
undefined local variable or method `be_empty' for #<#<Class:0x007f8af0924870>:0x007f8af1b82a08>
# ./spec/presenters/pdf_download_spec.rb:36:in `block (3 levels) in <top (required)>'
为什么rspec不会将be_include
或be_start_with
识别为here所述的有效方法?这可能是显而易见的事情,在这种情况下我道歉。我有rspec 2.12.2。谢谢!
更新:我在rspec-expectations 2.12中意识到,start_with和include是内置的匹配器,因此我不需要(实际上我不能)将它们作为be_
加上前缀。这解决了上述3次失败中的2次。但根据文档should still work,should_not be_empty
仍然会导致失败。
答案 0 :(得分:0)
be_include
不是匹配器或查找器。我想,您想检查一下,如果您的文件路径是否正确,请执行以下操作:
pdf_download.system_path.should eql(File.join(Rails.root, 'tmp'))
你可以使用像这样的包含,但我认为它不会起作用。你应该这样做: -
pdf_download.system_path.should include File.join(Rails.root, 'tmp')
或
由于