2

레일스 앱 테스트를 위해 RSpec/Capybara를 사용 중이므로보기의 한 요소가 한 번만 표시되는지 확인해야합니다.해당 텍스트가 한 번만 페이지에 표시되는지 확인해야합니다.

예를 들어 다음 코드에서 task.title이 페이지에 한 번만 표시되어야합니다. 표시된 것처럼 내가 존재하는지 여부를 확인할 수는 있지만 한 번만 나타나는지 확인하는 방법을 찾을 수 없습니다.

task = FactoryGirl.create(:task) 
login_as(task.user, :scope => :user) 
visit tasks_index_url 
expect(page).to have_content task.title 

답변

1

카피 바라의 page.has_content? (page.has_text?의 별칭) 텍스트가 나타나도록 배의 숫자입니다 소요됩니다.

: 그래서 당신은 단지 the rdoc에 표시되지 않지만 현재 버전 : 라인 (234)에서 시작 the source (에 설명되어 몇 가지 다른 옵션을 가지고

expect(page).to have_content(task.title, count: 1) 

has_text?/has_content?로 당신의 기대를 변경할 수 있습니다

# @option options [Integer] :count (nil) Number of times the text should occur 
# @option options [Integer] :minimum (nil) Minimum number of times the text should occur 
# @option options [Integer] :maximum (nil) Maximum number of times the text should occur 
# @option options [Range] :between (nil) Range of times that should contain number of times text occurs 
관련 문제