From d67b86d6d410c4da96f02af1ab90f3956551afb9 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: 2023年12月31日 20:06:36 +0330 Subject: [PATCH 01/16] Increase wait time for capybara --- spec/rails_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a55540114..d2a07654b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -104,7 +104,7 @@ options: { args: %w[headless disable-gpu no-sandbox disable-dev-shm-usage] } end - # Capybara.default_max_wait_time = 15 + Capybara.default_max_wait_time = 5 puts "=" * 80 puts "Capybara using driver: #{Capybara.javascript_driver}" puts "=" * 80 From c9d22e3b635c02c5872231cc884c70ceec75965b Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: 2023年12月31日 20:14:26 +0330 Subject: [PATCH 02/16] run bin/rspec --- lib/tasks/ci.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 29a4dc040..51d0d553b 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -10,7 +10,7 @@ if Rails.env.development? || Rails.env.test? task rspec_tests: :environment do puts Rainbow("Running RSpec tests").green - sh "rspec" + sh "./bin/rspec" end task build_rescript: :environment do From 3455e55b0241c7d4b738da99f014c88ae17b947c Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: 2023年12月31日 20:20:25 +0330 Subject: [PATCH 03/16] Increase wait time for capybara --- spec/rails_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index d2a07654b..f4439f949 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -104,7 +104,8 @@ options: { args: %w[headless disable-gpu no-sandbox disable-dev-shm-usage] } end - Capybara.default_max_wait_time = 5 + Capybara.default_max_wait_time = 15 + puts "=" * 80 puts "Capybara using driver: #{Capybara.javascript_driver}" puts "=" * 80 From 71a779dff741037c57de7b0e426ab477b6405dd3 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: 2023年12月31日 20:58:10 +0330 Subject: [PATCH 04/16] Improve rescript tests In this commit, a deply is put between UI interaction and database check. This, fixed false positive test pass for not updating database on empty form submission. --- spec/rescript/rescript_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/rescript/rescript_spec.rb b/spec/rescript/rescript_spec.rb index aedc5aa99..f0d9e17e0 100644 --- a/spec/rescript/rescript_spec.rb +++ b/spec/rescript/rescript_spec.rb @@ -50,6 +50,9 @@ fill_in author_field, with: comment.author fill_in text_field, with: comment.text click_button("Post") + + page.driver.browser.manage.timeouts.implicit_wait = 1 + expect(Comment.all.count).to equal(new_comment_count) end @@ -57,6 +60,8 @@ initial_comment_count = Comment.all.count fill_in text_field, with: comment.text click_button("Post") + + expect(page).to have_text(/Can't save the comment!/) expect(Comment.all.count).to equal(initial_comment_count) end @@ -64,12 +69,16 @@ initial_comment_count = Comment.all.count fill_in author_field, with: comment.author click_button("Post") + + expect(page).to have_text(/Can't save the comment!/) expect(Comment.all.count).to equal(initial_comment_count) end it "comment count remains the same when both form fields are empty" do initial_comment_count = Comment.all.count click_button("Post") + + expect(page).to have_text(/Can't save the comment!/) expect(Comment.all.count).to equal(initial_comment_count) end end From 79ed86d36d10e83c9f956064ae086ac004f2537e Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Mon, 1 Jan 2024 19:44:38 +0330 Subject: [PATCH 05/16] Chack page load rather forcing sleep --- spec/stimulus/turbo_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/stimulus/turbo_spec.rb b/spec/stimulus/turbo_spec.rb index 5697a7291..c7593a75b 100644 --- a/spec/stimulus/turbo_spec.rb +++ b/spec/stimulus/turbo_spec.rb @@ -52,7 +52,10 @@ fill_in author_field, with: comment.author fill_in text_field, with: comment.text click_button("Post") - sleep(1) + + # This will ensure we wait enough for the changes to be applied + expect(page).to have_text("") + expect(Comment.all.count).to equal(new_comment_count) end From fc3f6b8d212c3238810743c62f2d3297b5bccd53 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Mon, 1 Jan 2024 20:00:07 +0330 Subject: [PATCH 06/16] Fix false positive test pass in turbu spec --- spec/stimulus/turbo_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/stimulus/turbo_spec.rb b/spec/stimulus/turbo_spec.rb index c7593a75b..e4958893b 100644 --- a/spec/stimulus/turbo_spec.rb +++ b/spec/stimulus/turbo_spec.rb @@ -63,6 +63,8 @@ initial_comment_count = Comment.all.count fill_in text_field, with: comment.text click_button("Post") + + expect(page).to have_text("Author: can't be blank") expect(Comment.all.count).to equal(initial_comment_count) end @@ -70,12 +72,16 @@ initial_comment_count = Comment.all.count fill_in author_field, with: comment.author click_button("Post") + + expect(page).to have_text("Text: can't be blank") expect(Comment.all.count).to equal(initial_comment_count) end it "comment count remains the same when both form fields are empty" do initial_comment_count = Comment.all.count click_button("Post") + + expect(page).to have_text("Author: can't be blank") expect(Comment.all.count).to equal(initial_comment_count) end end From a5ddd573ec9fdbaa71f7f49ed2d49715b53c543e Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Mon, 1 Jan 2024 20:48:10 +0330 Subject: [PATCH 07/16] Change type to feature --- spec/system/add_new_comment_spec.rb | 6 +++--- spec/system/react_router_demo_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/add_new_comment_spec.rb b/spec/system/add_new_comment_spec.rb index c2926f0f6..e94906d94 100644 --- a/spec/system/add_new_comment_spec.rb +++ b/spec/system/add_new_comment_spec.rb @@ -4,7 +4,7 @@ require "system/shared/contexts" describe "Add new comment" do - context "when React Router", page: :main, js: true, type: :system do + context "when React Router", page: :main, js: true, type: :feature do describe "with Horizontal Form" do before do visit root_path @@ -61,7 +61,7 @@ end end - context "when React/Redux", page: :react_demo, js: true, type: :system do + context "when React/Redux", page: :react_demo, js: true, type: :feature do describe "with Horizontal Form" do before do visit root_path @@ -118,7 +118,7 @@ end end - context "when simple page", page: :simple, js: true, type: :system do + context "when simple page", page: :simple, js: true, type: :feature do describe "with Horizontal Form" do before do visit root_path diff --git a/spec/system/react_router_demo_spec.rb b/spec/system/react_router_demo_spec.rb index d1255e4f9..e6e00f159 100644 --- a/spec/system/react_router_demo_spec.rb +++ b/spec/system/react_router_demo_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" require "system/shared/contexts" -describe "React Router Routes", js: true, type: :system do +describe "React Router Routes", js: true, type: :feature do context "when Root URL", page: :main do it "shows comments section" do visit root_path From 599b2bc2b440cbd368071da954c0851be520387a Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Mon, 1 Jan 2024 20:49:17 +0330 Subject: [PATCH 08/16] Comment back capybara default max wait time config --- spec/rails_helper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index f4439f949..a55540114 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -104,8 +104,7 @@ options: { args: %w[headless disable-gpu no-sandbox disable-dev-shm-usage] } end - Capybara.default_max_wait_time = 15 - + # Capybara.default_max_wait_time = 15 puts "=" * 80 puts "Capybara using driver: #{Capybara.javascript_driver}" puts "=" * 80 From a6190ebd3c5133017708543dc3ef8da0e0a7ed7c Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Mon, 1 Jan 2024 20:59:07 +0330 Subject: [PATCH 09/16] Revert "run bin/rspec" This reverts commit c9d22e3b635c02c5872231cc884c70ceec75965b. --- lib/tasks/ci.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 51d0d553b..29a4dc040 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -10,7 +10,7 @@ if Rails.env.development? || Rails.env.test? task rspec_tests: :environment do puts Rainbow("Running RSpec tests").green - sh "./bin/rspec" + sh "rspec" end task build_rescript: :environment do From 244a390fc39c49b3b3845433effd4eb6e9f4f6e9 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Tue, 2 Jan 2024 20:34:49 +0330 Subject: [PATCH 10/16] Revert "Change type to feature" This reverts commit a5ddd573ec9fdbaa71f7f49ed2d49715b53c543e. --- spec/system/add_new_comment_spec.rb | 6 +++--- spec/system/react_router_demo_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/add_new_comment_spec.rb b/spec/system/add_new_comment_spec.rb index e94906d94..c2926f0f6 100644 --- a/spec/system/add_new_comment_spec.rb +++ b/spec/system/add_new_comment_spec.rb @@ -4,7 +4,7 @@ require "system/shared/contexts" describe "Add new comment" do - context "when React Router", page: :main, js: true, type: :feature do + context "when React Router", page: :main, js: true, type: :system do describe "with Horizontal Form" do before do visit root_path @@ -61,7 +61,7 @@ end end - context "when React/Redux", page: :react_demo, js: true, type: :feature do + context "when React/Redux", page: :react_demo, js: true, type: :system do describe "with Horizontal Form" do before do visit root_path @@ -118,7 +118,7 @@ end end - context "when simple page", page: :simple, js: true, type: :feature do + context "when simple page", page: :simple, js: true, type: :system do describe "with Horizontal Form" do before do visit root_path diff --git a/spec/system/react_router_demo_spec.rb b/spec/system/react_router_demo_spec.rb index e6e00f159..d1255e4f9 100644 --- a/spec/system/react_router_demo_spec.rb +++ b/spec/system/react_router_demo_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" require "system/shared/contexts" -describe "React Router Routes", js: true, type: :feature do +describe "React Router Routes", js: true, type: :system do context "when Root URL", page: :main do it "shows comments section" do visit root_path From 9314c7006106e3b27dc9098aacd8ad902afa1bd2 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Tue, 2 Jan 2024 20:56:07 +0330 Subject: [PATCH 11/16] Remove unneeded Capybara config --- spec/rails_helper.rb | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a55540114..33fb63fcc 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -66,45 +66,9 @@ # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! - # Capybara config - # - # selenium_firefox webdriver only works for Travis-CI builds. - default_driver = :selenium_chrome_headless - - supported_drivers = %i[selenium_chrome_headless selenium_chrome selenium_firefox selenium] - driver = ENV["DRIVER"].try(:to_sym) || default_driver - Capybara.default_driver = driver - - raise "Unsupported driver: #{driver} (supported = #{supported_drivers})" unless supported_drivers.include?(driver) - - case driver - when :selenium_chrome - DriverRegistration.register_selenium_chrome - - when :selenium_chrome_headless - DriverRegistration.register_selenium_chrome_headless - - when :selenium_firefox, :selenium - DriverRegistration.register_selenium_firefox - driver = :selenium_firefox - end - - Capybara.javascript_driver = driver - Capybara.default_driver = driver - - Capybara.register_server(Capybara.javascript_driver) do |app, port| - require "rack/handler/puma" - Rack::Handler::Puma.run(app, Port: port) - end - Capybara.server = :puma - - config.before(:each, type: :system, js: true) do - driven_by driver - driven_by :selenium, using: :chrome, - options: { args: %w[headless disable-gpu no-sandbox disable-dev-shm-usage] } - end + Capybara.default_driver = :selenium_chrome_headless + Capybara.javascript_driver = :selenium_chrome_headless - # Capybara.default_max_wait_time = 15 puts "=" * 80 puts "Capybara using driver: #{Capybara.javascript_driver}" puts "=" * 80 From a56a1649f02983b8241bae74d3729bf270c895da Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Tue, 2 Jan 2024 21:24:54 +0330 Subject: [PATCH 12/16] Remove unneeded js and type metadata in system specs --- spec/system/add_new_comment_spec.rb | 6 +++--- spec/system/react_router_demo_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/add_new_comment_spec.rb b/spec/system/add_new_comment_spec.rb index c2926f0f6..c62fd055f 100644 --- a/spec/system/add_new_comment_spec.rb +++ b/spec/system/add_new_comment_spec.rb @@ -4,7 +4,7 @@ require "system/shared/contexts" describe "Add new comment" do - context "when React Router", page: :main, js: true, type: :system do + context "when React Router", page: :main do describe "with Horizontal Form" do before do visit root_path @@ -61,7 +61,7 @@ end end - context "when React/Redux", page: :react_demo, js: true, type: :system do + context "when React/Redux", page: :react_demo do describe "with Horizontal Form" do before do visit root_path @@ -118,7 +118,7 @@ end end - context "when simple page", page: :simple, js: true, type: :system do + context "when simple page", page: :simple do describe "with Horizontal Form" do before do visit root_path diff --git a/spec/system/react_router_demo_spec.rb b/spec/system/react_router_demo_spec.rb index d1255e4f9..1d74d3d13 100644 --- a/spec/system/react_router_demo_spec.rb +++ b/spec/system/react_router_demo_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" require "system/shared/contexts" -describe "React Router Routes", js: true, type: :system do +describe "React Router Routes" do context "when Root URL", page: :main do it "shows comments section" do visit root_path From b0eaa5faa7a9b34eeb7d00707e7d967a71b4a5f5 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Fri, 5 Jan 2024 02:27:18 +0330 Subject: [PATCH 13/16] Improve test by checking comment on the page --- spec/stimulus/turbo_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/stimulus/turbo_spec.rb b/spec/stimulus/turbo_spec.rb index e4958893b..18ce7dab3 100644 --- a/spec/stimulus/turbo_spec.rb +++ b/spec/stimulus/turbo_spec.rb @@ -53,8 +53,8 @@ fill_in text_field, with: comment.text click_button("Post") - # This will ensure we wait enough for the changes to be applied - expect(page).to have_text("") + expect(page).to have_content(comment.author) + expect(page).to have_content(comment.text) expect(Comment.all.count).to equal(new_comment_count) end From facb4b05b5256f6884cfc2d08769b01dd6b3a260 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Fri, 5 Jan 2024 02:36:06 +0330 Subject: [PATCH 14/16] Combine the two similar tests --- spec/stimulus/turbo_spec.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/spec/stimulus/turbo_spec.rb b/spec/stimulus/turbo_spec.rb index 18ce7dab3..0b802ebd4 100644 --- a/spec/stimulus/turbo_spec.rb +++ b/spec/stimulus/turbo_spec.rb @@ -39,23 +39,15 @@ visit "/stimulus" end - it "adds a new comment to the page" do - fill_in author_field, with: comment.author - fill_in text_field, with: comment.text - click_button("Post") - expect(page).to have_selector "h2", text: comment.author - end - - it "comment count increases with successful form submission" do + it "adds a new comment to the page and database" do initital_comment_count = Comment.all.count new_comment_count = initital_comment_count + 1 fill_in author_field, with: comment.author fill_in text_field, with: comment.text click_button("Post") - expect(page).to have_content(comment.author) - expect(page).to have_content(comment.text) - + expect(page).to have_css("h2", text: comment.author) + expect(page).to have_css("p", text: comment.text) expect(Comment.all.count).to equal(new_comment_count) end From 9b123678991b4d6098d6ed10f2a2a59f38ef4ccf Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Thu, 4 Jan 2024 14:36:34 -1000 Subject: [PATCH 15/16] updated to unique comments --- spec/stimulus/turbo_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/stimulus/turbo_spec.rb b/spec/stimulus/turbo_spec.rb index 0b802ebd4..931cc1fc3 100644 --- a/spec/stimulus/turbo_spec.rb +++ b/spec/stimulus/turbo_spec.rb @@ -29,7 +29,7 @@ end describe "form submission functions" do - let(:comment) { Comment.new(author: "Author", text: "This is a comment") } + let(:comment) { Comment.new(author: "Author", text: "This is a comment #{Time.now}") } let(:author_field) { "comment_author" } let(:author_error) { "Author: can't be blank" } let(:text_field) { "comment_text" } From 338f9f477a229e8c466946ed58b3d188a6ad9625 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Thu, 4 Jan 2024 14:48:20 -1000 Subject: [PATCH 16/16] lint --- spec/stimulus/turbo_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/stimulus/turbo_spec.rb b/spec/stimulus/turbo_spec.rb index 931cc1fc3..d25059985 100644 --- a/spec/stimulus/turbo_spec.rb +++ b/spec/stimulus/turbo_spec.rb @@ -29,7 +29,7 @@ end describe "form submission functions" do - let(:comment) { Comment.new(author: "Author", text: "This is a comment #{Time.now}") } + let(:comment) { Comment.new(author: "Author", text: "This is a comment #{Time.zone.now}") } let(:author_field) { "comment_author" } let(:author_error) { "Author: can't be blank" } let(:text_field) { "comment_text" }

AltStyle によって変換されたページ (->オリジナル) /