|
21 | 21 |
|
22 | 22 | module Selenium
|
23 | 23 | module WebDriver
|
24 |
| - describe Service do |
25 |
| - describe '#new' do |
26 |
| - let(:service_path) { "/path/to/#{Chrome::Service::EXECUTABLE}" } |
| 24 | + module Chrome |
| 25 | + describe Service do |
| 26 | + describe '#new' do |
| 27 | + let(:service_path) { "/path/to/#{Service::EXECUTABLE}" } |
27 | 28 |
|
28 |
| - before do |
29 |
| - allow(Platform).to receive(:assert_executable).and_return(true) |
30 |
| - end |
| 29 | + before do |
| 30 | + allow(Platform).to receive(:assert_executable).and_return(true) |
| 31 | + end |
31 | 32 |
|
32 |
| - after { Chrome::Service.driver_path = nil } |
| 33 | + after { Service.driver_path = nil } |
33 | 34 |
|
34 |
| - it 'uses default path and port' do |
35 |
| - allow(Platform).to receive(:find_binary).and_return(service_path) |
| 35 | + it 'uses default path and port' do |
| 36 | + allow(Platform).to receive(:find_binary).and_return(service_path) |
36 | 37 |
|
37 |
| - service = Service.chrome |
| 38 | + service = Service.chrome |
38 | 39 |
|
39 |
| - expect(service.executable_path).to include Chrome::Service::EXECUTABLE |
40 |
| - expected_port = Chrome::Service::DEFAULT_PORT |
41 |
| - expect(service.port).to eq expected_port |
42 |
| - expect(service.host).to eq Platform.localhost |
43 |
| - end |
| 40 | + expect(service.executable_path).to include Service::EXECUTABLE |
| 41 | + expected_port = Service::DEFAULT_PORT |
| 42 | + expect(service.port).to eq expected_port |
| 43 | + expect(service.host).to eq Platform.localhost |
| 44 | + end |
44 | 45 |
|
45 |
| - it 'uses provided path and port' do |
46 |
| - path = 'foo' |
47 |
| - port = 5678 |
| 46 | + it 'uses provided path and port' do |
| 47 | + path = 'foo' |
| 48 | + port = 5678 |
48 | 49 |
|
49 |
| - service = Service.chrome(path: path, port: port) |
| 50 | + service = Service.chrome(path: path, port: port) |
50 | 51 |
|
51 |
| - expect(service.executable_path).to eq path |
52 |
| - expect(service.port).to eq port |
53 |
| - expect(service.host).to eq Platform.localhost |
54 |
| - end |
| 52 | + expect(service.executable_path).to eq path |
| 53 | + expect(service.port).to eq port |
| 54 | + expect(service.host).to eq Platform.localhost |
| 55 | + end |
55 | 56 |
|
56 |
| - it 'allows #driver_path= with String value' do |
57 |
| - path = '/path/to/driver' |
58 |
| - Chrome::Service.driver_path = path |
| 57 | + it 'allows #driver_path= with String value' do |
| 58 | + path = '/path/to/driver' |
| 59 | + Service.driver_path = path |
59 | 60 |
|
60 |
| - service = Service.chrome |
| 61 | + service = Service.chrome |
61 | 62 |
|
62 |
| - expect(service.executable_path).to eq path |
63 |
| - end |
| 63 | + expect(service.executable_path).to eq path |
| 64 | + end |
64 | 65 |
|
65 |
| - it 'allows #driver_path= with Proc value' do |
66 |
| - path = '/path/to/driver' |
67 |
| - proc = proc { path } |
68 |
| - Chrome::Service.driver_path = proc |
| 66 | + it 'allows #driver_path= with Proc value' do |
| 67 | + path = '/path/to/driver' |
| 68 | + proc = proc { path } |
| 69 | + Service.driver_path = proc |
69 | 70 |
|
70 |
| - service = Service.chrome |
| 71 | + service = Service.chrome |
71 | 72 |
|
72 |
| - expect(service.executable_path).to eq path |
73 |
| - end |
| 73 | + expect(service.executable_path).to eq path |
| 74 | + end |
74 | 75 |
|
75 |
| - it 'does not create args by default' do |
76 |
| - allow(Platform).to receive(:find_binary).and_return(service_path) |
| 76 | + it 'does not create args by default' do |
| 77 | + allow(Platform).to receive(:find_binary).and_return(service_path) |
77 | 78 |
|
78 |
| - service = Service.chrome |
| 79 | + service = Service.new |
79 | 80 |
|
80 |
| - expect(service.extra_args).to be_empty |
81 |
| - end |
| 81 | + expect(service.extra_args).to be_empty |
| 82 | + end |
82 | 83 |
|
83 |
| - it 'uses provided args' do |
84 |
| - allow(Platform).to receive(:find_binary).and_return(service_path) |
| 84 | + it 'uses provided args' do |
| 85 | + allow(Platform).to receive(:find_binary).and_return(service_path) |
85 | 86 |
|
86 |
| - service = Service.chrome(args: ['--foo', '--bar']) |
| 87 | + service = Service.chrome(args: ['--foo', '--bar']) |
87 | 88 |
|
88 |
| - expect(service.extra_args).to eq ['--foo', '--bar'] |
89 |
| - end |
| 89 | + expect(service.extra_args).to eq ['--foo', '--bar'] |
| 90 | + end |
90 | 91 |
|
91 |
| - it 'uses args when passed in as a Hash' do |
92 |
| - allow(Platform).to receive(:find_binary).and_return(service_path) |
| 92 | + it 'uses args when passed in as a Hash' do |
| 93 | + allow(Platform).to receive(:find_binary).and_return(service_path) |
93 | 94 |
|
94 |
| - expect { |
95 |
| - service = Service.chrome(args: {log_path: '/path/to/log', |
96 |
| - verbose: true}) |
| 95 | + expect { |
| 96 | + service = Service.new(args: {log_path: '/path/to/log', |
| 97 | + verbose: true}) |
97 | 98 |
|
98 |
| - expect(service.extra_args).to eq ['--log-path=/path/to/log', '--verbose'] |
99 |
| - }.to have_deprecated(:driver_opts) |
| 99 | + expect(service.extra_args).to eq ['--log-path=/path/to/log', '--verbose'] |
| 100 | + }.to have_deprecated(:driver_opts) |
| 101 | + end |
100 | 102 | end
|
101 |
| - end |
102 | 103 |
|
103 |
| - context 'when initializing driver' do |
104 |
| - let(:driver) { Chrome::Driver } |
105 |
| - let(:service) { instance_double(Service, launch: service_manager) } |
106 |
| - let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') } |
107 |
| - let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) } |
| 104 | + context 'when initializing driver' do |
| 105 | + let(:driver) { Chrome::Driver } |
| 106 | + let(:service) { instance_double(Service, launch: service_manager) } |
| 107 | + let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') } |
| 108 | + let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) } |
108 | 109 |
|
109 |
| - before do |
110 |
| - allow(Remote::Bridge).to receive(:new).and_return(bridge) |
111 |
| - allow(bridge).to receive(:browser).and_return(:chrome) |
112 |
| - end |
| 110 | + before do |
| 111 | + allow(Remote::Bridge).to receive(:new).and_return(bridge) |
| 112 | + allow(bridge).to receive(:browser).and_return(:chrome) |
| 113 | + end |
113 | 114 |
|
114 |
| - it 'is not created when :url is provided' do |
115 |
| - expect(Service).not_to receive(:new) |
| 115 | + it 'is not created when :url is provided' do |
| 116 | + expect(Service).not_to receive(:new) |
116 | 117 |
|
117 |
| - driver.new(url: 'http://example.com:4321') |
118 |
| - end |
| 118 | + driver.new(url: 'http://example.com:4321') |
| 119 | + end |
119 | 120 |
|
120 |
| - it 'is created when :url is not provided' do |
121 |
| - allow(Service).to receive(:new).and_return(service) |
| 121 | + it 'is created when :url is not provided' do |
| 122 | + allow(Service).to receive(:new).and_return(service) |
122 | 123 |
|
123 |
| - driver.new |
124 |
| - expect(Service).to have_received(:new).with(no_args) |
125 |
| - end |
| 124 | + driver.new |
| 125 | + expect(Service).to have_received(:new).with(no_args) |
| 126 | + end |
126 | 127 |
|
127 |
| - it 'accepts :service without creating a new instance' do |
128 |
| - allow(Service).to receive(:new) |
| 128 | + it 'accepts :service without creating a new instance' do |
| 129 | + allow(Service).to receive(:new) |
129 | 130 |
|
130 |
| - driver.new(service: service) |
131 |
| - expect(Service).not_to have_received(:new) |
| 131 | + driver.new(service: service) |
| 132 | + expect(Service).not_to have_received(:new) |
| 133 | + end |
132 | 134 | end
|
133 | 135 | end
|
134 |
| - end |
| 136 | + end # Chrome |
135 | 137 | end # WebDriver
|
136 | 138 | end # Selenium
|
0 commit comments