rspecの中でレンダリング後のHTMLを確認する方法
超絶ハマった。。
こんなテストがあるとして、、、
~snip~ subject { page } ~snip~ describe "with username and password" do before do fill_in I18n.t('sessions.new.form.email'), with: user.email fill_in I18n.t('sessions.new.form.password'), with: user.password click_button I18n.t('sessions.new.form.submit') end it { should have_selector('title', text: user.name) } end
テストがfailするんだけど、実際に動かしてみると期待通りの動きをする。
ということはテストの書き方が間違っているか、レンダリングされたHTMLが実際と違うかだ。
ということでチェックされているHTMLが知りたい!知りたい!どうやって出すの!というときのこと。
pageというオブジェクトがviewを表すオブジェクトなので、
~snip~ subject { page } ~snip~ describe "with username and password" do before do fill_in I18n.t('sessions.new.form.email'), with: user.email fill_in I18n.t('sessions.new.form.password'), with: user.password click_button I18n.t('sessions.new.form.submit') end it "hoge" do p page.html end it { should have_selector('title', text: user.name) } end
よくわかってないんだけど、it = page だと思うので、ブロック作らなくても p it.htmlとかできるかと思ったらそれはできなかった。
っていうか頭がもう回らない・・・