File tree Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -85,16 +85,19 @@ def app
85
85
def initialize ( *args , &blk )
86
86
super ( *args , &blk )
87
87
@driver = nil
88
+
89
+ self . class . before do
90
+ # A user may have already set the driver, so only default if driver
91
+ # is not set
92
+ driven_by ( :selenium ) unless @driver
93
+ end
88
94
end
89
95
90
96
def driven_by ( *args , &blk )
91
97
@driver = ::ActionDispatch ::SystemTestCase . driven_by ( *args , &blk ) . tap ( &:use )
92
98
end
93
99
94
100
before do
95
- # A user may have already set the driver, so only default if driver
96
- # is not set
97
- driven_by ( :selenium ) unless @driver
98
101
@routes = ::Rails . application . routes
99
102
end
100
103
Original file line number Diff line number Diff line change @@ -18,6 +18,47 @@ module RSpec::Rails
18
18
end
19
19
end
20
20
end
21
+
22
+ describe '#driver' do
23
+ it 'uses :selenium driver by default' do
24
+ group = RSpec ::Core ::ExampleGroup . describe do
25
+ include SystemExampleGroup
26
+ end
27
+ example = group . new
28
+ group . hooks . run ( :before , :example , example )
29
+
30
+ expect ( Capybara . current_driver ) . to eq :selenium
31
+ end
32
+
33
+ it 'sets :rack_test driver using by before_action' do
34
+ group = RSpec ::Core ::ExampleGroup . describe do
35
+ include SystemExampleGroup
36
+
37
+ before do
38
+ driven_by ( :rack_test )
39
+ end
40
+ end
41
+ example = group . new
42
+ group . hooks . run ( :before , :example , example )
43
+
44
+ expect ( Capybara . current_driver ) . to eq :rack_test
45
+ end
46
+
47
+ it 'calls :driven_by method only once' do
48
+ group = RSpec ::Core ::ExampleGroup . describe do
49
+ include SystemExampleGroup
50
+
51
+ before do
52
+ driven_by ( :rack_test )
53
+ end
54
+ end
55
+ example = group . new
56
+ allow ( example ) . to receive ( :driven_by ) . and_call_original
57
+ group . hooks . run ( :before , :example , example )
58
+
59
+ expect ( example ) . to have_received ( :driven_by ) . once
60
+ end
61
+ end
21
62
end
22
63
end
23
64
end
You can’t perform that action at this time.
0 commit comments