【问题标题】:Test file write in rails application在 Rails 应用程序中写入测试文件
【发布时间】:2016-02-01 00:53:32
【问题描述】:

我正在为 iphone 应用程序开发 Rails API 应用程序。一些端点导致将数据写入文件并将其存储在目录中的功能。一切正常,但每次我为这些特定端点之一运行测试时,都会写入一个文件。测试完成后是否可以自动删除文件?

更多信息: 我将 RSpec 与 shoulda_matchers 和 FactoryGirl 一起使用,以防万一。

【问题讨论】:

    标签: ruby-on-rails unit-testing rspec


    【解决方案1】:

    您可以删除 after 块中的文件,例如

    context :foo do
      let(:filename) { '/foo/bar/baz/qux.txt' }
    
      it { ... }
    
      after do
        FileUtil.rm filename
      end
    end
    

    【讨论】:

    • 我收到此错误:NoMethodError: undefined method `after' for #<:core::examplegroup::nested_2::nested_3::nested_1:0x007fdd0b3421d8> 有什么想法可能出错吗?
    • @ShEsKo,试试after(:each)after(:all)after(:suite)
    • 还是没有运气:/ @Mori
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多