Skip to content

Commit

Permalink
chore: wrap tests with context
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Nov 9, 2023
1 parent 1daebe1 commit 5b70e5a
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions spec/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5b70e5a

Please sign in to comment.