Skip to content

Commit

Permalink
created a test for the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
julienguyenn committed Feb 11, 2020
1 parent bad1b29 commit 7a4c678
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/features/home_page_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'rails_helper'

RSpec.feature "Visitor navigates to home page", type: :feature, js: true do

# SETUP
before :each do
@category = Category.create! name: 'Apparel'

10.times do |n|
@category.products.create!(
name: Faker::Hipster.sentence(3),
description: Faker::Hipster.paragraph(4),
image: open_asset('apparel1.jpg'),
quantity: 10,
price: 64.99
)
end
end

scenario "They see all products" do
# This is the act
visit root_path

# Takes a screenshot
save_and_open_screenshot

# This is to verify
expect(page).to have_css 'article.product', count: 10
end
end
4 changes: 4 additions & 0 deletions spec/support/images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Helper function to open product images
def open_asset(file_name)
File.open(Rails.root.join('db', 'seed_assets', file_name))
end

0 comments on commit 7a4c678

Please sign in to comment.