RSpec:主页的集成测试

我正在尝试学习使用RSpec来测试驱动代码。为此,我正在创建一个库存管理系统。

product模型具有三个属性:

  1. sku_code
  2. 名称
  3. 价格

warehouse模型具有四个属性:

  1. wh_code
  2. 名称
  3. 密码
  4. max_capacity

应用程序的根URL将显示products的当前列表及其在所有warehouses中的计数。

我已经读过,我应该先编写集成规范,而不是模型规范。

那么我应该如何开始为主页编写规格并继续进行下一步?

ACACmi 回答:RSpec:主页的集成测试

您正在寻找的可能是使用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,并获取大量视频和博客文章以开始使用。

所以,请尝试写点东西,如果遇到任何困难,请回到这里。

本文链接:https://www.f2er.com/3075610.html

大家都在问