0
votes

This describe is the default that RSpec creates. I am having difficulty working with TDD. I find it complicated and am having trouble understanding the entire procedure.

For example, I need to test that by accessing the index method, it returns a list of users. What would be the way to test this functionality?

describe "GET 'index'" do
  it "returns http success" do
    get 'index'
    expect(response).to be_success
  end
end
1
Confused by the wording in your question. You are having difficulty working with TDD - you find it complicated - and you (don't) understand the entire procedure? I'd like to help edit your question to make it clearer so I or others could better answer it.verdammelt

1 Answers

0
votes

You can avoid controller tests, because all logic can be tested with acceptance tests (using rspec + Capybara). I recommend to buy a pdf book, which is a best for rspec learning. https://leanpub.com/everydayrailsrspec

And here I give you an example for your question:

feature 'Visitor' do

  background do
    2.times |n| { User.new(username: "User #{n}") } #create 2 users to test list
  end

  scenario 'tries to view list of users on users index page' do
    visit users_path #try to enter to users index page
    expect(current_path).to eq users_path #check current path
    expect(page).to have_content 'User 1' #check for User 1 from 'background'
    expect(page).to have_content 'User 2' #check for User 2 from 'background'
  end

end

Simply, we are entering index page by method 'visit', and expect to see some information.