我在导轨中进行了一次失败的rspec测试,它说:
Failure/Error: click_on "New Part"
Capybara::ElementNotFound:
Unable to find link or button "New Part"
这是我的spec文件:
require "spec_helper"
describe "Adding and Registering a part" do
it "shows a part not in a class" do
company1 = Company.create(company_attributes)
product1 = Product.create(product_1_attributes)
product1.company = company1
product1.save
part1 = Part.new(part1_attributes)
visit parts_path
click_on "New Part"
fill_in('part_part_number', :with => part1.part_number)
fill_in('part_name', :with => part1.name)
fill_in('part_description', :with => part1.description)
fill_in('part_manufacturer', :with => part1.manufacturer)
click_on "Create Part"
visit parts_path
expect(page).to have_text(part1.part_number)
expect(page).to have_text(part1.name)
expect(page).to have_text(part1.description)
expect(page).to have_text(part1.manufacturer)
end
it "shows a part in a class after Register" do
company1 = Company.create(company_attributes)
product1 = Product.create(product_1_attributes)
product1.company = company1
product1.save
part1 = Part.new(part1_attributes)
visit parts_path
click_on "New Part"
fill_in('part_part_number', :with => part1.part_number)
fill_in('part_name', :with => part1.name)
fill_in('part_description', :with => part1.description)
fill_in('part_manufacturer', :with => part1.manufacturer)
click_on "Create Part"
visit products_path
click_on "Show"
click_on "Register Parts"
click_on "Register"
expect(page).to have_text("Parts Registered")
expect(page).to have_text(part1.name)
end
end
这是capybara无法找到的链接:
<%= link_to 'New Part', new_part_path %>
&#34; New Part&#34;的拼写是完全相同的(我将链接复制并粘贴到rspec测试的链接只是为了安全),我有一个类似的rspec测试,在另一个页面上工作。