-1
# /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_includebe_start_with作为此处描述的有效方法?这可能是显而易见的,在这种情况下,我道歉。我有 rspec 2.12.2。谢谢!

更新:我在 rspec-expectations 2.12 中意识到, start_with 和 include 是内置匹配器,所以我不需要(实际上我不能)be_再为它们加上前缀。这解决了上述 3 个故障中的 2 个。但我仍然失败should_not be_empty,根据文档应该仍然有效

4

1 回答 1

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')

或者

谢谢

于 2013-09-26T08:14:46.397 回答