There's an echo in my head

日々のメモ。

RSpecのbeforeブロックで現在テスト中のexampleのソースを取得する

describe "foo" do
  before do
    puts example.description
  end
  it "bar" do
    # some test
  end
end

specのファイルパスと行番号が表示される。

example at .spec/foo_spec.rb:5

Getting the full RSpec test name from within a before(:each) blockを見ると、ExampleGroupの名前も取得できるっぽい。

このブログに出てくるコードスニペッツは、引用あるいは断りがない限りMITライセンスです。