LoginSignup
1
1

More than 5 years have passed since last update.

RSpecで試験結果項目に時刻を表示

Posted at

試験失敗時などに外部のログを照らし合わせたいときは、項目毎に時刻が出力されるよう以下の設定を追加している。

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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1