From 5b70e5a872c1367f136a67fad868fd6ef5ba4f1d Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Thu, 9 Nov 2023 09:34:27 +0300 Subject: [PATCH] chore: wrap tests with context --- spec/browser_spec.rb | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/spec/browser_spec.rb b/spec/browser_spec.rb index 270b13a9..758623ef 100644 --- a/spec/browser_spec.rb +++ b/spec/browser_spec.rb @@ -265,33 +265,35 @@ end end - it "stops process if an error is raised during process start" do - process = Ferrum::Browser::Process.new(Ferrum::Browser::Options.new(process_timeout: 0)) - allow(Ferrum::Browser::Process).to receive(:new).and_return(process) - expect { Ferrum::Browser.new }.to raise_error(Ferrum::ProcessTimeoutError) - expect(process.pid).to be(nil) - end + context "with error on initialize" do + it "stops process if an error is raised during process start" do + process = Ferrum::Browser::Process.new(Ferrum::Browser::Options.new(process_timeout: 0)) + allow(Ferrum::Browser::Process).to receive(:new).and_return(process) + expect { Ferrum::Browser.new }.to raise_error(Ferrum::ProcessTimeoutError) + expect(process.pid).to be(nil) + end - it "stops process if an error is raised during client creation" do - process = Ferrum::Browser::Process.new(Ferrum::Browser::Options.new) - allow(Ferrum::Browser::Process).to receive(:new).and_return(process) + it "stops process if an error is raised during client creation" do + process = Ferrum::Browser::Process.new(Ferrum::Browser::Options.new) + allow(Ferrum::Browser::Process).to receive(:new).and_return(process) - error = StandardError.new - allow(Ferrum::Browser::Client).to receive(:new).and_raise(error) + error = StandardError.new + allow(Ferrum::Browser::Client).to receive(:new).and_raise(error) - expect { Ferrum::Browser.new }.to raise_error(error) - expect(process.pid).to be(nil) - end + expect { Ferrum::Browser.new }.to raise_error(error) + expect(process.pid).to be(nil) + end - it "stops process if an error is raised during contexts creation" do - process = Ferrum::Browser::Process.new(Ferrum::Browser::Options.new) - allow(Ferrum::Browser::Process).to receive(:new).and_return(process) + it "stops process if an error is raised during contexts creation" do + process = Ferrum::Browser::Process.new(Ferrum::Browser::Options.new) + allow(Ferrum::Browser::Process).to receive(:new).and_return(process) - error = StandardError.new - allow(Ferrum::Contexts).to receive(:new).and_raise(error) + error = StandardError.new + allow(Ferrum::Contexts).to receive(:new).and_raise(error) - expect { Ferrum::Browser.new }.to raise_error(error) - expect(process.pid).to be(nil) + expect { Ferrum::Browser.new }.to raise_error(error) + expect(process.pid).to be(nil) + end end end