【发布时间】:2013-12-28 01:00:52
【问题描述】:
我正在使用 RSpec 和 Capybara。我想用click_link 测试导航面板,并为具体页面提供共享示例。但我不能使用it_should_behave_like,因为我不想在点击链接后更改主题。有什么方法可以包含与expect(page).to 共享的示例?
编辑: 这是我的代码:
require 'spec_helper'
describe "SomeController" do
subject { page }
content_list = {
home: 'Some text on the home page',
about: 'Some text on the about page',
order: 'Some text on the order page'
}
shared_examples_for 'with layout' do
it { should have_content 'Some text on the layout' }
it { should have_title 'Title' }
end
describe 'Home page' do
before { visit root_path }
it_should_behave_like 'with layout'
it { should have_content content_list[:home] }
end
describe 'About page' do
before { visit about_path }
it_should_behave_like 'with layout'
it { should have_content content_list[:about] }
end
describe 'Order page' do
before { visit order_path }
it_should_behave_like 'with layout'
it { should have_content content_list[:order] }
end
it 'should have correct links on the layout' do
visit root_path
click_link 'Some link text'
expect(page).to have_content content_list[:about]
find('.logoLink').click
expect(page).to have_content content_list[:home]
click_link 'Another link text'
expect(page).to have_content content_list[:about]
click_link 'One more link text'
expect(page).to have_content content_list[:order]
end
end
在访问带有路线名称的页面和点击访问它们时,我正在检查相同的内容。我想重构它。
【问题讨论】: