# /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
作为此处描述的有效方法?这可能是显而易见的,在这种情况下,我道歉。我有 rspec 2.12.2。谢谢!
更新:我在 rspec-expectations 2.12 中意识到, start_with 和 include 是内置匹配器,所以我不需要(实际上我不能)be_
再为它们加上前缀。这解决了上述 3 个故障中的 2 个。但我仍然失败should_not be_empty
,根据文档应该仍然有效。