試験失敗時などに外部のログを照らし合わせたいときは、項目毎に時刻が出力されるよう以下の設定を追加している。
spec_helper.rb
RSpec.configure do |c|
c.format_docstrings { |s| "#{s} (#{Time.now.strftime('%T')})" }
end
サンプル
sample_spec.rb
require 'rspec/core'
RSpec.configure do |c|
c.format_docstrings { |s| "#{s} (#{Time.now.strftime('%T')})" }
end
describe "NaN" do
subject { Float::NAN }
it { is_expected.to eq subject } # fails
it { is_expected.to be subject } # passes
end
terminal
$ rspec -fd sample_spec.rb
NaN (04:31:20)
should eq NaN (04:31:20) (FAILED - 1)
should equal NaN (04:31:20)
Failures:
1) NaN should eq NaN
Failure/Error: it { is_expected.to eq subject } # fails
expected: NaN
got: NaN
(compared using ==)
# ./sample_spec.rb:9:in `block (2 levels) in <top (required)>'
Finished in 0.0164 seconds (files took 0.1518 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./sample_spec.rb:9 # NaN should eq NaN