Rspec功能测试 - 验证表格中的内容

时间:2016-04-25 15:38:41

标签: ruby-on-rails ruby rspec

我有一个功能测试似乎没有找到我期望的表的内容。我应该说我是新功能测试,所以这肯定是我做错了。基本上我有一个Groups表,它接受组名和响应,这两个表应该显示在表中但是在我运行测试时没有出现。为清楚起见,这是我的错误和代码。

TEST

require "rails_helper"

RSpec.feature "Edit 'Bounce Back' Message" do
  scenario "Staff can change the response message" do
    visit "/groups"

    user = FactoryGirl.create(:user)
    fill_in "Email", with: user.email
    fill_in "Password", with: user.password
    click_button "Sign in"

    group = Group.create!(name: "Group A")
    person = Person.create!(groups: [group], phone_number: "+161655555555")

    expect(page).to have_content("You are now subscribed for updates")
    expect(page).to have_content("Group A")
  end
end

错误消息

This is the image

这是页面

This is the image

正如您所看到的,它应该在页面上显示响应和组名称,但它说它没有显示我期望的单词?任何帮助都会很棒!

查看

<div class="container text-center">
<div class="row">
<div class="text-center">
  <h3>Edit The "Bounce Back" Subscription Response</h3>
<table class="table table-striped">
  <tbody>
    <% @group.each do |group| %>
      <tr>
        <td class='edit_response'><%= group.name.capitalize %></td>
        <td class='edit-response'><%= group.response %></td>
        <td><%= link_to 'Edit', edit_group_path(group) %></td>
      <tr>
    <% end %>
  </tbody>
</table>
</div>
</div>
</div>

1 个答案:

答案 0 :(得分:1)

由于您首先登录用户并且仅在该创建订阅组之后登录,因此除非您进行刷新,否则它将无法在页面上显示。也许在登录用户之前尝试创建订阅组?

scenario "Staff can change the response message" do
  visit "/groups"

  group = Group.create!(name: "Group A")
  person = Person.create!(groups: [group], phone_number: "+161655555555")

  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")
  expect(page).to have_content("Group A")
end