Skip to content

Instantly share code, notes, and snippets.

@delba
Last active December 19, 2015 04:19
Show Gist options
  • Select an option

  • Save delba/5896301 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5896301 to your computer and use it in GitHub Desktop.
Capybara DSL
assert_selector 'article', count: Article.count
assert_selector 'article', exact: Article.count
assert find_button('Save article', disabled: true).disabled?
assert has_link?('New article', href: new_article_path)
# assert that a link with text 'New article' and href new_article_path exists
# not necessarily good to track bugs
assert_equal new_article_path, find('a', text: 'New article')[:href]
# assert selector and href value
assert_selector 'p.notice', text: 'Article created!'
# => asserts that a p.notice with text 'Article created!' is on the page
assert_equal 'Article created!', find('p.notice').text
# => assert that a p.notice exists *and* that its content is 'Article created!'
assert_equal 'Lorem Ipsum', title
# delegates `title` to `page`
assert_match %r(/articles/\d+), current_path
# no need to escape forward slashes with %r(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment