Cambass Cambass - 7 months ago 37
Ruby Question

Rspec feature test - verifying content in table

I have a feature test that doesn't seem to be finding the content of the table that I expect. I should say that I'm new to feature tests so this is for sure something I am doing wrong. Basically I have a Groups table that takes in group name and response both of which should are displayed in the table but are not showing up when I run the test. Here is my error and code for clarity.

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


ERROR MESSAGE

This is the image

HERE IS THE PAGE

This is the image

As you can see it should display the response and group name on the page but it saying it doesn't show the words I expect? any help would be great!

VIEW

<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>

Answer

Since you login the user first and only after that create subscription group, it won't be visible on the page unless you do a refresh. Maybe try creating the subscription group before logging in in the user?

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
Comments