0

我有一个 rspec 测试失败,但在开发中,当我自己执行操作时,页面会正确呈现。

这是片段:

describe "sign up process" do

let (:admin1) { FactoryGirl.create(:admin) }

describe "with valid information"

  before do 
    visit new_admin_registration_path
    fill_in "Email", with: admin1.email
    fill_in "Password", with: admin1.password
    fill_in "Password confirmation", with: admin1.password_confirmation
    click_button "Sign up"
  end

  it { should have_selector('div.alert') }
end

它根本没有找到那个选择器,但我在使用开发环境查看源代码时确认它存在。

我想做的是检查正在呈现的页面以查看我缺少的内容。有没有办法做到这一点?

4

2 回答 2

5

Capybara 有一个方法save_and_open_page可以打开一个带有当前页面状态的新浏览器窗口(它需要launchygem)。

例如:

  before do 
    ...
    click_button "Sign up"
    save_and_open_page
  end
于 2012-07-24T21:27:29.970 回答
4

这就像在你的规范中使用调试器或其他不同的东西一样简单。

我个人更喜欢 pry,因为每次我用 ruby​​ 1.9 尝试安装调试器时都会有点麻烦......

with pry you would just add a require "pry" in your spec_helper.rb and then write a binding.pry the line before the problem occurs. you then have an irb session attached to your test.

于 2012-07-24T21:28:59.060 回答