Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Content appears in my browser, but not in my test

I can see the content fine in my browser, but it doesn't appear in the the test. I checked the page with save_and_open_page and the categories that I created isn't in the generated page. What am I missing here?

This is the error that I'm getting:

  1. Categories index page when the user is signed in should be able to see a list of categories Failure/Error: page.should have_content category1.name expected there to be content "category-1" in "Gastos\n\n\n\n\n\n\n\n\nGastos\n\n\nHome\n\n\nAbout\n\n\nContact\n\n\n\nLogged in as\nfoo2@example.com\n\nEdit profile\nSign Out\n\n\n\n\n\n\n\nBrowse Categories\nName\n\n\n\n"

    ./spec/requests/categories_spec.rb:19:in `block (4 levels) in <top (required)>'

class CategoriesController < ApplicationController
def index
@categories = Category.all
end
end
require 'spec_helper'
include Warden::Test::Helpers
describe "Categories" do
let(:user) { FactoryGirl.create(:user) }
describe 'index page' do
context 'when the user is signed in' do
let(:category1) { FactoryGirl.create(:category, user: user) }
let(:category2) { FactoryGirl.create(:category, user: user) }
before(:each) do
login_as user
visit categories_path
end
it 'should be able to see a list of categories' do
page.should have_content 'Browse Categories'
page.should have_content category1.name
page.should have_content category2.name
end
end
end
end
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "foo#{n}@example.com" }
password 'secret'
time_zone 'Hong Kong'
end
factory :category do
user
sequence(:name) { |n| "category-#{n}" }
end
end
%h1 Browse Categories
%table
%tr
%th Name
%th
%th
- @categories.each do |category|
%tr
%td= link_to category.name, category
%td= link_to 'Edit', edit_category_path(category)
%td= link_to 'Destroy', category_path(category), method: :delete, confirm: 'Are you sure?'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.