Ruby on rails 带有Rspec 3的rails 4中的测试布局
我在布局中放了一个引导导航栏,想测试所有链接是否正确Ruby on rails 带有Rspec 3的rails 4中的测试布局,ruby-on-rails,ruby,twitter-bootstrap-3,specifications,Ruby On Rails,Ruby,Twitter Bootstrap 3,Specifications,我在布局中放了一个引导导航栏,想测试所有链接是否正确 require 'rails_helper' describe "layouts/application.html.erb" do it "should have the right links in navbar" do render expect(page).to have_link('Home', href: "/home/index") expect(page).to have_link('Gam
require 'rails_helper'
describe "layouts/application.html.erb" do
it "should have the right links in navbar" do
render
expect(page).to have_link('Home', href: "/home/index")
expect(page).to have_link('Games', href: "/games/index")
expect(page).to have_link('Programming', href: "/programming/index")
expect(page).to have_link('Bananenmannfrau', href: "/pages/about")
end
end
这只是返回错误:
layouts/application.html.erb should have the right links in navbar
Failure/Error: render
NameError:
undefined local variable or method `render' for #<RSpec::ExampleGroups::LayoutsApplicationHtmlErb:0x00000005a8f750>
# ./spec/layouts/application.html.erb_spec.rb:8:in `block (2 levels) in <top (required)>'
layouts/application.html.erb应该在导航栏中有正确的链接
失败/错误:渲染
名称错误:
未定义的局部变量或方法“render”#
#./spec/layouts/application.html.erb_spec.rb:8:in'block(2层)in'
这是测试它的正确方法吗?如果是,我遗漏了什么?您应该使用capybara gem来测试前端! 然后您将能够像这样使用它:
require 'rails_helper'
describe "layouts/application.html.erb" do
it "should have the right links in navbar" do
visit root_path
within(".nav-bar-selector") do
expect(page).to have_content('Home')
expect(page).to have_content('Games')
expect(page).to have_content('Programming')
expect(page).to have_content('Bananenmannfrau')
end
end
end
您应该使用水豚宝石测试前端! 然后您将能够像这样使用它:
require 'rails_helper'
describe "layouts/application.html.erb" do
it "should have the right links in navbar" do
visit root_path
within(".nav-bar-selector") do
expect(page).to have_content('Home')
expect(page).to have_content('Games')
expect(page).to have_content('Programming')
expect(page).to have_content('Bananenmannfrau')
end
end
end
您应该使用水豚宝石测试前端! 然后您将能够像这样使用它:
require 'rails_helper'
describe "layouts/application.html.erb" do
it "should have the right links in navbar" do
visit root_path
within(".nav-bar-selector") do
expect(page).to have_content('Home')
expect(page).to have_content('Games')
expect(page).to have_content('Programming')
expect(page).to have_content('Bananenmannfrau')
end
end
end
您应该使用水豚宝石测试前端! 然后您将能够像这样使用它:
require 'rails_helper'
describe "layouts/application.html.erb" do
it "should have the right links in navbar" do
visit root_path
within(".nav-bar-selector") do
expect(page).to have_content('Home')
expect(page).to have_content('Games')
expect(page).to have_content('Programming')
expect(page).to have_content('Bananenmannfrau')
end
end
end
好的,谢谢。但基本上这意味着我只在根页面上测试布局,对吗?我只是想可能会有另一个测试只是布局的情况下,任何一个单一的页面可能会打破它,但不太可能。好的,谢谢。但基本上这意味着我只在根页面上测试布局,对吗?我只是想可能会有另一个测试只是布局的情况下,任何一个单一的页面可能会打破它,但不太可能。好的,谢谢。但基本上这意味着我只在根页面上测试布局,对吗?我只是想可能会有另一个测试只是布局的情况下,任何一个单一的页面可能会打破它,但不太可能。好的,谢谢。但基本上这意味着我只在根页面上测试布局,对吗?我只是认为可能会有另一个测试,只是布局的情况下,任何一个单一的页面可能会打破它,但不太可能。