RSpec:主页集成测试

问题描述 投票:0回答:1

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

product模型具有三个属性:

  1. sku_code
  2. 名称
  3. 价格

[warehouse模型具有四个属性:

  1. wh_code
  2. 名称
  3. 密码
  4. 最大容量

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

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

所以我应该如何从编写首页规范开始,然后继续下一步?

ruby-on-rails rspec tdd integration-testing
1个回答
0
投票

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

所以,如果您遇到任何困难,请尝试写一些东西,然后回到这里。

© www.soinside.com 2019 - 2024. All rights reserved.