저는 rspec 및 capybara를 처음 사용하고 테스트 시나리오를 천천히 확장하여 학습합니다.Rspec : 로그인 한 사용자와 다른 사용자가 작성한 설명
내가 로그인 한 후 작성한 주석 (예 : 친구)이 다른 테스트 사용자 (예 : Test1)가 작성한 것처럼 인쇄되는 이유를 이해할 수 없습니까?
(I 브라우저에서 확인하고 현재 사용자가 만든 같은 댓글이 표시됩니다)
require 'rails_helper'
describe 'navigate' do
let!(:user) { FactoryGirl.create(:user) }
let!(:friend) { FactoryGirl.create(:friend) }
let!(:article) {
Article.create(title:"To test notifications", summary: "Summary of article", description: "Description of article.", status: "published", user_id: user.id)
}
describe 'notification created if other use comments on article' , js: true do
before do
login_as(friend, :scope => :user)
visit article_path(article)
fill_in 'comment[content]', with: "Some comments"
click_on "Add Comment"
logout(:friend)
login_as(user, :scope => :user)
end
it "renders notification on dropdown list" do
expect(page).to have_css("#notificationList", text: friend.name + " posted a Comment on " + article.title)
expect(page).to have_css("#notification-counter", text: "1")
end
it "render notification on notifiction index page" do
visit notifications_path
expect(page).to have_css("#notifications-container", text: friend.name + " posted a Comment on " + article.title)
end
end
end
나도 방법을 아래에 시도했지만 내가 응용 프로그램에 로그인 할 수없는이기 때문에 테스트가 실패합니다.
2) login_as(friend, :scope => :friend)
사용자 공장 login_as(friend, :scope => :user)
교체 :
FactoryGirl.define do
sequence :email do |n|
"test#{n}@example.com"
end
factory :user do
sequence(:name) { |n| "Test#{n}" }
email { generate :email }
password "asdfasdf"
password_confirmation "asdfasdf"
end
factory :friend, class: "User" do
name 'Friend'
email { generate :email }
password "asdfasdf"
password_confirmation "asdfasdf"
end
end
안녕하세요로 쓰기 더 나을 것, 그쪽으로 조언을 주셔서 감사합니다! 나는 로그 아웃하기 전에 Friend의 의견이 성공적으로 제출되었는지 확인하기 위해 click_on "comments"뒤에 expect (page) .to have_content "Some comments"를 배치했습니다. 그러나, 나는 지금 logout (: friend)을 expect 문 다음에 배치 했음에도 불구하고 Friend를 로그 아웃 할 수 없다. 로그 아웃하고 수동으로 로그인하면 테스트가 통과됩니다. (예 : 로그 아웃 버튼을 클릭하고 로그인 양식을 입력하십시오) – doyz
문서 작성자에게 알림을 실시간으로 업데이트 할 수 있도록 조치 할 수있는 설정이 있지만이 문제와 관련이 있는지 의심 스럽습니까? – doyz
@diana'logout'이'devise' /'warden'에서 나온 것이면 매개 변수 (사용자가 아닌)로 범위를 가져옵니다. 그러므로 여러분의 경우'logout (: user)'여야합니다 - 아니라 : 친구 : 당신은 : 친구 범위가 없기 때문에 단지 '친구'사용자 인스턴스 –