4.5 implemented tests for creating a new beer

This commit is contained in:
Aaro Koivukangas
2023-11-08 16:55:54 +02:00
parent 7dfff96dcb
commit afc123126a
5 changed files with 56 additions and 0 deletions
+1
View File
@@ -71,6 +71,7 @@ group :test do
gem "webdrivers"
gem "rspec-rails"
gem "factory_bot_rails"
gem "launchy"
end
+3
View File
@@ -110,6 +110,8 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
launchy (2.5.2)
addressable (~> 2.8)
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
@@ -250,6 +252,7 @@ DEPENDENCIES
factory_bot_rails
importmap-rails
jbuilder
launchy
pg
pry-byebug
puma (~> 5.0)
+41
View File
@@ -0,0 +1,41 @@
require "rails_helper"
describe "Beers page" do
it "should display all beers in the database" do
visit beers_path
expect(page).to have_content "Beers"
expect(page).to have_content "Iso 3"
expect(page).to have_content "Karhu"
expect(page).to have_content "Tuplahumala"
expect(page).to have_content "Huvila Pale Ale"
expect(page).to have_content "X Porter"
expect(page).to have_content "Hefeweizen"
expect(page).to have_content "Helles"
end
it "should be able to add a new beer" do
visit new_beer_path
expect(page).to have_content "New beer"
expect(page).to_not have_content "New fancy test beer"
fill_in("beer_name", with: "New fancy test beer")
click_button "Create Beer"
expect(page).to have_content "Beer was successfully created"
expect(page).to have_content "New fancy test beer"
end
it "should not be able to add a new beer without a proper beer name" do
visit new_beer_path
expect(page).to have_content "New beer"
expect(page).to_not have_content "New fancy test beer"
fill_in("beer_name", with: "")
click_button "Create Beer"
expect(page).to_not have_content "Beer was successfully created"
expect(page).to_not have_content "New fancy test beer"
expect(page).to have_content "Name can't be blank"
end
end
+10
View File
@@ -0,0 +1,10 @@
require "rails_helper"
describe "Breweries page" do
it "should not have any before created" do
visit breweries_path
expect(page).to have_content "Breweries"
# Has all of the default Breweries
expect(Brewery.count).to eq 3
end
end
+1
View File
@@ -0,0 +1 @@
require 'capybara/rspec'