Rajkaran Mishra
Rajkaran Mishra

Reputation: 4952

RSpec: Integration test for homepage

I am trying to learn to test drive the code using RSpec. For this I am creating an inventory management system.

Let the product model has three attributes:

  1. sku_code
  2. name
  3. price

And the warehouse model have four attributes:

  1. wh_code
  2. name
  3. pincode
  4. max_capacity

The application's root url will show the current list of products and their counts in all warehouses.

I have read that instead of model specs, I should write integration specs first.

So how should I start with writing specs for the homepage and proceed to the next steps?

Upvotes: 3

Views: 370

Answers (1)

Greg
Greg

Reputation: 6659

What you're looking for is probably a feature (integration) test made with capybara framework. In your case it could look like this

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

It's just a general pointer on how to start. You can search for capybara rails tests and get plenty of videos and blog posts to get you started.

So, please try to write something and come back here if you get stuck anywhere.

Upvotes: 4

Related Questions