0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Railsアプリの単体テストでCapybaraを使ってるときにpageをいい感じに標準出力させる方法: CGI.pretty

Posted at

職場にいるあるAnonymous曰く、

  let(:page) do
    # do something
    render
    Capybara.string(rendered)
  end

のようなことをしてる場合に

it do
  puts CGI.pretty(page.native.to_html)
  expect(subject).to include("something")
end

のようにすると

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">                                                          |  ETA: ??:??:?? 

<html>
  <body>
<!-- 以下略 -->

のような出力を単体テスト実行時に出せる。

この手のテストではbinding.pryとかを挟むと挙動が変わってしまうことがあり(renderできなくなったり)、古き良きprintifデバッグするしか無いときに役に立つらしい。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?