我正在尝试学习使用RSpec来测试驱动代码。为此,我正在创建一个库存管理系统。
让product
模型具有三个属性:
[warehouse
模型具有四个属性:
应用程序的根URL将显示products
的当前列表及其在所有warehouses
中的计数。
我已经读过,而不是模型规格,我应该首先编写集成规格。
所以我应该如何从编写首页规范开始,然后继续下一步?
您正在寻找的可能是使用capybara框架进行的功能(集成)测试。您的情况可能看起来像这样
RSpec.describe 'Homepage', type: :feature do
before do
create(:product, name: 'Pants')
# set how many there is in the warehouse (the model is not clear to me, so I'm not guessing this one)
end
scenario 'index page' do
visit home_page_path
expect(page).to have_content('Paths, 5 items') # Obviously, this depends on how you plan to present that into
end
end
这只是关于如何开始的一般指针。您可以搜索capybara rails tests,并获取大量视频和博客文章以入门。
所以,如果您遇到任何困难,请尝试写一些东西,然后回到这里。