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 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 diff --git a/spec/stimulus/turbo_spec.rb b/spec/stimulus/turbo_spec.rb index 5697a7291..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") } + 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" } @@ -39,20 +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") - sleep(1) + + 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 @@ -60,6 +55,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 @@ -67,12 +64,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 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