简体   繁体   English

rails - 如何在调试器中使用请求规范显示页面的HTML源代码?

[英]rails - how can I show a page's HTML source in the debugger with a request spec?

I've tried p page and p page.source and also: 我已经尝试过p pagep page.source以及:

(rdb:1) find ('page')
(rdb:1) find ('bosy')
(rdb:1) find ('body')
(rdb:1) find
(rdb:1) p page
(rdb:1) p html
(rdb:1) p source
(rdb:1) p page.source

but all I get is variations on: 但我得到的只是变化:

*** Unknown command: "page".  Try "help".

Code: 码:

describe "For a user who is not logged in." do

  context "Visiting the home page." do
    before(:each) { visit root_path }

    describe "The page." do
      subject { page }

      debugger
      1   

      it "Has a 'login' link." do
        should have_link('Sign In')
      end 

      it "does NOT have a 'logout' link." do
        should have_no_link('Logout')
      end 

    end 

  end

end

Where your current debugger line is won't get executed in the scope where page is defined. 当前debugger行的位置将不会在定义page的范围内执行。 Maybe before(:each) { visit root_path; debugger } 也许before(:each) { visit root_path; debugger } before(:each) { visit root_path; debugger } would work. before(:each) { visit root_path; debugger }会工作。 Completely untested. 完全未经测试。

Hm. 嗯。 I can't answer your question, but if you goal is to peek at the page, you could use 我无法回答你的问题,但如果你的目标是窥视页面,你可以使用

save_and_open_page save_and_open_page

which requires the launchy gem in test & development scope. 这需要在测试和开发范围内的launchy宝石。

(assuming you're using capybara?) (假设你正在使用水豚?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM