2017-02-23 2 views
1

RSpec 테스트를 작성하고 텍스트 필드를 채울 때 다음 오류가 발생합니다.RSpec 테스트를 작성할 때 오류가 발생했습니다. Capybara :: ElementNotFound : 필드를 찾을 수 없습니다.

1) coordinators/new.html.erb populate page name text entry field filled checks for presence of filled in text field 
Failure/Error: fill_in "coordinator_name", with: 'JoeJoe' 

Capybara::ElementNotFound: 
    Unable to find field "coordinator_name" 
# ./spec/views/coordinators/new.html.erb_spec.rb:47:in `block (4 levels) in <top (required)>' 

여기에는 "coordinator_name"필드가있는 앞의 테스트를 포함한 내 코드의 일부입니다. 나는 왜 그것이 2 차 시험에서 발견되지 않는지 혼란 스럽다.

describe 'name text entry field' do 
    it 'checks for presence of empty text field for name' do 
    expect(rendered).to have_field('coordinator_name', text: nil) 
    end 
end 

describe 'name text entry field filled' do 
    it 'checks for presence of filled in text field' do 
    fill_in "coordinator_name", with: 'JoeJoe' 
    expect(rendered).to have_field('coordinator_name', text: 'JoeJoe') 
    end 
end 

해결책을 찾는 방법에 대한 제안이 있으십니까?

+0

테스트 코드에서는 have_field에 ': text' 옵션을 넘기는 것을 보여줍니다 - have_field는': text' 옵션을 취하지 않습니다. 필드의 값을 테스트하려는 경우': with' 옵션을 사용합니다 , 또한 '렌더링'이란 무엇입니까? - 신경 쓰지 마. 네가 뭘 잘못하고 있는지. –

+0

@KevinEtore 빈 파일 (html 없음)입니다. 하지만 "빈 텍스트 필드의 존재 여부 확인"테스트를 위해 save_and_open_page를 넣을 때도 마찬가지입니다 (빈 페이지). – JSmooth

답변

1

여기서 문제는보기 테스트를 작성한다는 것입니다.보기 테스트는 페이지의 내용을 확인할 수는 있지만 페이지와 상호 작용할 수 없습니다. 정상적인 설정에서는 capybara matchers가 뷰 스펙에 포함되지만 Capybara :: DSL은 https://github.com/teamcapybara/capybara/blob/master/lib/capybara/rspec.rb#L10이 아니기 때문에 fill_in은 뷰 스펙에서 사용할 수 없어야합니다. 모든 사양에 카피 바라 : DSL을 포함 시켜서 오버라이드했다고 가정합니다.

두 번째 사양으로 작동하려면 사양 사양을 작성해야합니다.

+0

spec/rails_helper.rb 파일에 Capybara :: DSL이 포함되었습니다. – JSmooth

+1

@Joseph Right - 모든 사양 유형을 - 정확하지 않은 - 포함하고 있습니다. 단지 'capybara/spec''을 요구하고 DSL은 기능 테스트에만 포함될 것입니다 - 실제로 페이지와 상호 작용할 수 있습니다. matchers는 뷰 스펙에 포함되어 필드의 존재 여부를 확인할 수는 있지만 변경할 수는 없습니다. –

관련 문제