블로그 기능이 포함 된 레일 앱이 있습니다.Capybara Rails TestCase를 단일 트랜잭션으로 실행하려면 어떻게해야합니까?
Ruby 테스트 (asserts/refutes) (즉, 사양이 아닌 Capybara :: Rails :: TestCase 사용)에서 블로그를 테스트 할 때 게시물 추가, 주석 추가, 게시물 편집 테스트를하고 싶습니다 각 테스트는 마지막 테스트를 바탕으로 이루어지며 첫 번째 테스트에서 생성 된 포스트는 두 번째 테스트에서 주석 처리됩니다.
단위 테스트 (글로벌 변수, setup/teardown 사용)에서이 작업을 수행 할 때 해결 방법을 보여주는 게시물을 보았지만 기능 테스트에서 직접 테스트하는 방법이 있는지 궁금해했습니다. 여기서 더 일반적입니다.
이상적으로는 이전 테스트에서 생성 된 데이터베이스 레코드뿐만 아니라 로그인 세션이 지속되도록하여 TestCase의 각 테스트에서 지속되도록합니다.
class BlogTest< Capybara::Rails::TestCase
test 'can sign in' do
user = User.create!(name: "user",
email: "[email protected]",
password: "passw0rd!", password_confirmation: "passw0rd!")
visit new_user_session_path
fill_in('Login', :with => user.email)
fill_in('Password', :with => user.password)
check('Remember me')
click_button('Sign in')
end
test 'can create post' do
visit new_post_path # how can I have user logged in?
fill_in "Title", with: "My first post title!"
fill_in "Body", with: "My first post body!"
click_button "Publish"
end
test 'can comment on post' do
visit post_path(Post.first) # should go to post created in last test
click_button "Add comment"
...
end
end
내가이 오이에서 가능하다 들었습니다 : 설치 및 해체는 게시물, 댓글에 대해 생성 된 중간 기록 등
내가 좋아하는 뭔가를 할을 때마다 로그인하는 데 사용하지만 수 , 다른 이유로 오이를 사용하지 않기로 선택 했으므로 Minitest와 Capybara와 함께 작업하길 원합니다.
아마도 이러한 메서드 중 일부는 test_helper.rb의 Capybara :: Rails :: TestCase에 추가 될 수 있습니까? user와 user_password 같은 것이 더 일반적으로 유용합니까? – Anand
블로그 게시물 [여기] (http://rcanand.github.io/How_To_Test_Rails_With_Minitest_And_Capybara/)으로 응답 연장 (계층화 된 테스트 사용 가능)을 게시했습니다. – Anand