【发布时间】:2016-04-26 14:38:25
【问题描述】:
我有一个试图验证编辑操作的功能测试。这是一个超级简单的测试,但我写的并不多,而且我犯了一些我无法弄清楚的错误。基本上,当访问页面时,它不会呈现要编辑的文本信息,并且“更新”按钮不存在。为了清楚起见,这是我的错误和代码。
测试
scenario "Staff can edit the response messages" do
group = Group.create!(name: "Group A", response: "You are now subscribed for updates")
visit "/groups/#{group.id}/edit"
user = FactoryGirl.create(:user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
expect(page).to have_content("You are now subscribed for updates")
end
查看
<div class="container text-center">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 well">
<%= form_for @group do |form| %>
<div class="form-group">
<%= form.label :body, "Edit The Response:", class: "message_label"%>
<%= form.text_field :response, class: "form-control", placeholder: "New things are happening!" %>
</div>
<%= form.submit "Update", class: "btn btn-primary" %>
<% end %>
</div>
</div>
</div>
更奇怪的是,当我运行“save_and_open_page”时,我期望的内容是存在的?但是,我的测试仍然失败,说没有显示预期的内容很奇怪!
【问题讨论】:
-
您好。在您看来,我看不到您再次测试的文本应该显示在哪里。带有失败消息的图像没有显示页面上实际存在的所有文本(在右侧被截断) 一般来说,我建议使用 save_and_open_page 或 save_and_open_screenshot (如果你的包中有 capybara-screenshot)更好地了解页面实际显示的内容。
-
是的,这更奇怪,因为如果我使用 save_and_open_page 它会在页面上显示我期望的内容,但如果我运行测试它不会显示?
-
在唱歌后插入
pause 3,仅用于测试目的 -
唱完后插入停顿 3?很抱歉,但我不确定这意味着什么?
-
@Cambass
sleep 3
标签: ruby-on-rails ruby rspec