我是watir的新手,我尝试使用watir来测试我的rails应用。我有下一个代码:
require 'watir_helper'
require 'spec_helper'
RSpec.feature 'Questions hub', type: :request do
let!(:user) { create(:user, email: 'test1@example.com', name: 'John', last_name: 'Stivens') }
let!(:question) { create(:question, created_at: 'August 25, 2016', user: user) }
describe 'Comments feature' do
context 'When user signed in' do
def sign_in_user
goto new_user_session_path
text_field(name: 'user[email]').set('test1@example.com')
text_field(name: 'user[password]').set('12345678')
button(name: 'commit').click
end
def visit_question_page_and_post_answer
goto question_path(question)
textarea(id: 'answer_content').set('Lorem Ipsum')
button(name: 'commit').click
end
def add_comment_to_answer
link(text: 'comments (0)').click
link(text: 'Add Comment').when_present.click
textarea(name: 'comment[content]').set('MyComment')
button(name: 'commit').click
end
before do
sign_in_user
visit_question_page_and_post_answer
end
it "Check comments count when it's empty" do
text.include? 'comments (0)'
end
it "Add comment to question's answer" do
add_comment_to_answer
text.include? 'MyComment'
text.include? 'comments (1)'
end
it 'Comment has link to user profile' do
add_comment_to_answer
div(class: 'user-name-w').link(text: 'John Stivens').click # problem happens here
end
end
end
end
当我在代码中有下一行时:
div(class: 'user-name-w').link(text: 'John Stivens').click
此测试失败并显示错误:
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQsocket() can't get socket descriptor: BEGIN
但是如果要进行2次先前的测试,那么第三次测试(问题发生)将会通过。