Reputation: 35
So I am testing public profiles and I am getting the following error
1) Visiting profiles not signed in shows profile
Failure/Error: expect( page ).to have_content(@post.title)
expected to find text "Post title" in "Bloccit About Sign In or Sign Up Posts
Comments"
# ./spec/features/profiles_spec.rb:22:in `block (3 levels) in <top (required)>'
Here is my profile_spec.rb
require 'rails_helper'
describe "Visiting profiles" do
include TestFactories
before do
@user = authenticated_user
@post = associated_post(user: @user)
@comment = Comment.new(user: @user, body: "A Comment")
allow(@comment).to receive(:send_favorite_emails)
@comment.save
end
describe "not signed in" do
it "shows profile" do
visit user_path(@user)
expect(current_path).to eq(user_path(@user))
expect( page ).to have_content(@user.name)
expect( page ).to have_content(@post.title)
expect( page ).to have_content(@comment.body)
end
end
end
I am not sure what else could be wrong.
It seems like the view is looking at the main page and not to the user profile.
This is the user_controller show
def show
@user = User.find(params[:id])
@posts = @user.posts
@comments = @user.comments
end
Upvotes: 1
Views: 84
Reputation: 6466
mckay74 -- The issue is a slight one.
In ERB, <% some ruby %>
executes Ruby. <%= some ruby %>
executes that ruby AND prints it to the page. You used the former, so while your Ruby is executing, it's not showing up in the final HTML. Add those =
s, (to the lines that should actually print) and your test should pass.
Upvotes: 1