【问题标题】:When will the examples.txt file will be created in Rspec?什么时候会在 Rspec 中创建 examples.txt 文件?
【发布时间】:2021-07-19 08:27:19
【问题描述】:

我想将examples.txt文件复制到另一个examples_1.txt文件中,以便在重新运行时我可以在examples.txt文件被覆盖时获得另一个副本。

问题: 我有这样的代码。我在 after(:suite) 部分复制了 example.txt 文件,但出现错误。

我收到此错误。当我检查时,这是由于examples.txt文件甚至不存在。关于何时创建 examples.txt 文件的任何想法,以便我可以在创建文件后复制它们。

  No such file or directory @ rb_sysopen - reports/examples.txt
# ./spec/spec_helper.rb:94:in `block in <top (required)>'
# ./spec/spec_helper.rb:89:in `<top (required)>'

【问题讨论】:

    标签: ruby rspec


    【解决方案1】:

    这就是它发生的地方: https://github.com/rspec/rspec-core/blob/e7c5d030966a7e8dad3e0a67c61920c4f2437c15/lib/rspec/core/runner.rb#L90

          # Configures and runs a spec suite.
          #
          # @param err [IO] error stream
          # @param out [IO] output stream
          def run(err, out)
            setup(err, out)
            return @configuration.reporter.exit_early(@configuration.failure_exit_code) if RSpec.world.wants_to_quit
    
            run_specs(@world.ordered_example_groups).tap do
              persist_example_statuses
            end
          end
    

    如果您在同一个文件 (https://github.com/rspec/rspec-core/blob/e7c5d030966a7e8dad3e0a67c61920c4f2437c15/lib/rspec/core/runner.rb#L113) 中探索 run_specs,您会看到在此方法返回之前挂钩已经完成,并且 examples.txt 被保留。没有人预料到你的情况,所以没有“after_persistence_file_saved”钩子供你使用。

    一些可能的选择是:

    • 猴子补丁def persist_example_status 方法并进行额外的复制(hacky,带有猴子补丁的所有问题),或者
    • 运行rspec ... &amp;&amp; cp reports/examples.txt reports.examples_1.txt(简单得多,不那么老套,做的假设也很少)。
    • 向 rspec-core 打开一个 PR,引入一个您需要的钩子(我认为它不太可能被接受,因为存在更简单的解决方案)

    各有优缺点,但这些似乎超出了这个问题的范围。

    【讨论】:

    • 现在我已经在 J​​enkins 文件中复制了examples.txt,然后使用--only-failures cp reports/examples.txt reports/examples_1.txt 运行Rspec
    猜你喜欢
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 2012-03-25
    相关资源
    最近更新 更多