Today I Learned

hashrocket A Hashrocket project

Expecting A Selector and Its Content

In integration tests with Capybara, I find myself writing code like this a lot:

within 'h1' do
  expect(page).to have_content('Today I Learned')

Today I remembered that there is another way:

expect(page).to have_selector('h1', text: 'Today I Learned')

I prefer this because it captures the scope and the content in one line. RSpec integration tests in particular can get pretty long, and I think this is a good opportunity to keep them concise.

See More #testing TILs