【问题标题】:How to properly test interpolated string from yaml file如何正确测试来自 yaml 文件的插值字符串
【发布时间】:2023-03-31 16:50:01
【问题描述】:

我有 rspec/capybara 测试正在测试字符串的期望值,但测试正在替换变量。

yaml 中的刺痛:

title: Sold %{product}

测试中的期望:

expect(page).to have_text(t("sell_successes.show.title"))

结果:

expected to find text "Sold %{product}" in blah blah

什么时候应该寻找:

expected to find text "Sold shoes" in blah blah

【问题讨论】:

    标签: ruby-on-rails rspec yaml capybara


    【解决方案1】:

    yaml 包含一个字符串模板,因此您需要为其提供值以放入模板中

    expect(page).to have_text(t("sell_successes.show.title") % { product: 'shoes' })
    

    【讨论】:

      猜你喜欢
      • 2019-06-15
      • 2020-10-16
      • 2017-01-27
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 2021-06-15
      相关资源
      最近更新 更多