File: session_spec.rb

package info (click to toggle)
ruby-capybara 3.36.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,380 kB
  • sloc: ruby: 23,399; javascript: 748; makefile: 11
file content (91 lines) | stat: -rw-r--r-- 2,439 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Capybara::Session do
  describe '#new' do
    it 'should raise an error if passed non-existent driver' do
      expect do
        described_class.new(:quox, TestApp).driver
      end.to raise_error(Capybara::DriverNotFoundError)
    end

    it 'verifies a passed app is a rack app' do
      expect do
        described_class.new(:unknown, random: 'hash')
      end.to raise_error TypeError, 'The second parameter to Session::new should be a rack app if passed.'
    end
  end

  context 'current_driver' do
    around do |example|
      orig_driver = Capybara.current_driver
      example.run
      Capybara.current_driver = orig_driver
    end

    it 'is global when threadsafe false' do
      Capybara.threadsafe = false
      Capybara.current_driver = :selenium
      thread = Thread.new do
        Capybara.current_driver = :random
      end
      thread.join
      expect(Capybara.current_driver).to eq :random
    end

    it 'is thread specific threadsafe true' do
      Capybara.threadsafe = true
      Capybara.current_driver = :selenium
      thread = Thread.new do
        Capybara.current_driver = :random
      end
      thread.join
      expect(Capybara.current_driver).to eq :selenium
    end
  end

  context 'session_name' do
    around do |example|
      orig_name = Capybara.session_name
      example.run
      Capybara.session_name = orig_name
    end

    it 'is global when threadsafe false' do
      Capybara.threadsafe = false
      Capybara.session_name = 'sess1'
      thread = Thread.new do
        Capybara.session_name = 'sess2'
      end
      thread.join
      expect(Capybara.session_name).to eq 'sess2'
    end

    it 'is thread specific when threadsafe true' do
      Capybara.threadsafe = true
      Capybara.session_name = 'sess1'
      thread = Thread.new do
        Capybara.session_name = 'sess2'
      end
      thread.join
      expect(Capybara.session_name).to eq 'sess1'
    end
  end

  context 'quit' do
    it 'will reset the driver' do
      session = described_class.new(:rack_test, TestApp)
      driver = session.driver
      session.quit
      expect(session.driver).not_to eql driver
    end

    it 'resets the document' do
      session = described_class.new(:rack_test, TestApp)
      document = session.document
      session.quit
      expect(session.document.base).not_to eql document.base
    end
  end
end