# /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)>'
ここでbe_include
説明されているように、rspec がorbe_start_with
を有効なメソッドとして認識しないのはなぜですか? 当たり前のことかもしれませんが、その場合はお詫び申し上げます。私はrspec 2.12.2を持っています。ありがとう!
更新: rspec-expectations 2.12 で、start_with と include は組み込みのマッチャーであることに気付きましたbe_
。これにより、上記の 3 つの障害のうち 2 つが解決されます。should_not be_empty
しかし、ドキュメントによると、まだ動作するはずの でまだ失敗します。