RSpec重试Gem - 无法实现重试尝试

时间:2018-02-20 14:42:49

标签: rspec

我正在努力将Rspec Retry gem应用到我的项目中。我已将重试代码添加到spec_helper.rb中,我正在测试此方法:

  it 'should randomly succeed', :retry => 3 do
    expect(rand(23)).to eq(1)
  end

但是,我无法让Retry实际重新运行该方法。我正在研究为什么它不会重试。这是控制台输出。

My console outputs the following:
C:\RSpecRetry>rspec spec/support/raise_error.rb
C:/RSpecRetry/spec/spec_helper.rb:100: warning: already initialized constant CONTINUE_SPEC
C:/RSpecRetry/spec/spec_helper.rb:95: warning: previous definition of CONTINUE_SPEC was here

1st Try error in ./spec/support/raise_error.rb:8:

expected: 1
     got: 17

(compared using ==)


RSpec::Retry: 2nd try ./spec/support/raise_error.rb:8
.

Finished in 1.07 seconds (files took 1.89 seconds to load)
1 example, 0 failures

1 个答案:

答案 0 :(得分:0)

从我看到你的规范实际上已经重试:

  • 首先尝试获得17而不是1 1st Try error in ./spec/support/raise_error.rb:8
  • 第二次尝试(幸运!)你已经RSpec::Retry: 2nd try ./spec/support/raise_error.rb:8 .< - 这个点是传递的规范

并且摘要证实了它:

1 example, 0 failures

如果您不想看到失败的尝试,请摆弄config(尤其是前两个)