Skip to content

Instantly share code, notes, and snippets.

@tgaff
Last active August 29, 2015 14:21
Show Gist options
  • Save tgaff/e0ddd054f202f9a0ebb2 to your computer and use it in GitHub Desktop.
Save tgaff/e0ddd054f202f9a0ebb2 to your computer and use it in GitHub Desktop.
capybara tricks

Frequently one might want to make an assertion inside a within block, but it's not obvious how to do so.

This doesn't work (within doesn't have block attributes):

within(level_selector) do |this|
  click_button 'edit'
  expect(this).to have_content(header_text) # sadly this = nil
end

current_scope will work though and looks at only the content in the within

within(level_selector) do
  click_button 'edit'
  expect(current_scope).to have_content(header_text)
end
@showaltb
Copy link

Actually, expect(page) will work as well. This is handy when you call a step from within another step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment