Skip to content

Instantly share code, notes, and snippets.

@frankolson
Last active October 27, 2018 01:11
Show Gist options
  • Save frankolson/06f4bf2dbd511131de668c40420e1219 to your computer and use it in GitHub Desktop.
Save frankolson/06f4bf2dbd511131de668c40420e1219 to your computer and use it in GitHub Desktop.
Capybara/Trix Editor example tests
# test/system/article/post_test.rb
require 'application_system_test_case'
class Articles::PostTest < ApplicationSystemTestCase
setup do
sign_in_as users(:will)
visit articles_path
end
test 'post a new article' do
click_on 'Create a new article'
fill_in 'Title', with: 'Dope new article'
fill_in_trix_editor 'article_content', with: 'Work for us!!!'
click_on 'Create Article'
assert_selector 'h4.aticle-title', text: 'Dope new article'
end
end
# test/system/article/update_test.rb
require 'application_system_test_case'
class Articles::UpdateTest < ApplicationSystemTestCase
setup do
@article = articles(:trix_capybara)
sign_in_as users(:will)
visit article_path(@article)
end
test 'update an article' do
# check the fields were prefilled correctly
assert_equal find_field('article_title').value, @article.title
assert_equal find_trix_editor('article_content').value, @article.content
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment