做一些简单的Capybara + Rspec测试:
it "Edit Voice and Display the Result" do
voice = FactoryGirl.create(:voice, title: "Another Random Fact", opinion: "A flock of crows is known as a murder.")
visit voices_path
expect(page).to have_content("Another Random Fact")
expect(page).to have_content("A flock of crows is known as a murder.")
click_link "Edit"
fill_in "Title", with: "One More Random Fact!"
fill_in "Opinion", with: "You cannot snore and dream at the same time."
click_button "Update Voice"
expect(page).to have_content("One More Random Fact!")
expect(page).to have_content("You cannot snore and dream at the same time.")
end
当我运行上述测试时,它会返回Failure/Error: click_link "Edit" Capybara::ElementNotFound:Unable to find link "Edit"
错误。
我在这里做错了什么?链接"编辑"在节目页面上清晰可见。
show.html.haml
%h2= @voice.title
%p= @voice.opinion
= link_to "Edit", edit_voice_path(@voice)
= link_to "Destroy", voice_path(@voice), method: :delete, data: {confirm: "Are you sure?"}
编辑:
发现错误,这是一个错字。我很抱歉。我的修复方法在之下答案 0 :(得分:0)
我认为您实际上还没有导航到语音页面。这就是你犯这个错误的原因。确保您首先访问正确的show
页面,其中包含Edit
按钮。
从您的评论和回答中可以清楚地看到,您遇到错误导致您没有转到我在评论和回答中提及的show
页面。
答案 1 :(得分:0)
道歉,事实证明我正在访问错误的页面。
代码显示visit voices_path
的位置应为visit voice_path(voice)
voices_path
链接到索引,但我想要显示页面,即voice_path(voice)