@@ -2,7 +2,8 @@ module RSpec::Rails
2
2
RSpec . describe FixtureSupport do
3
3
context "with use_transactional_fixtures set to false" do
4
4
it "still supports fixture_path" do
5
- allow ( RSpec . configuration ) . to receive ( :use_transactional_fixtures ) { false }
5
+ allow ( RSpec . configuration ) . to \
6
+ receive ( :use_transactional_fixtures ) { false }
6
7
group = RSpec ::Core ::ExampleGroup . describe do
7
8
include FixtureSupport
8
9
end
@@ -21,5 +22,57 @@ module RSpec::Rails
21
22
22
23
expect { group . new . setup_fixtures } . to_not raise_error
23
24
end
25
+
26
+ context "without database available" do
27
+ let ( :example_group ) do
28
+ RSpec ::Core ::ExampleGroup . describe ( "FixtureSupport" ) do
29
+ include FixtureSupport
30
+ include RSpec ::Rails ::MinitestLifecycleAdapter
31
+ end
32
+ end
33
+ let ( :example ) do
34
+ example_group . example ( "foo" ) do
35
+ expect ( true ) . to be ( true )
36
+ end
37
+ end
38
+
39
+ RSpec . shared_examples_for "unrelated example raise" do
40
+ it "raise due to no connection established" do
41
+ expect ( example_group . run ) . to be ( false )
42
+ expect ( example . execution_result . exception ) . to \
43
+ be_a ( ActiveRecord ::ConnectionNotEstablished )
44
+ end
45
+ end
46
+
47
+ RSpec . shared_examples_for "unrelated example does not raise" do
48
+ it "does not raise" do
49
+ expect ( example_group . run ) . to be ( true )
50
+ expect ( example . execution_result . exception ) . not_to \
51
+ be_a ( ActiveRecord ::ConnectionNotEstablished )
52
+ end
53
+ end
54
+
55
+ before { clear_active_record_connection }
56
+
57
+ after { establish_active_record_connection }
58
+
59
+ context "with use_active_record set to false" do
60
+ before { RSpec . configuration . use_active_record = false }
61
+
62
+ after { RSpec . configuration . use_active_record = true }
63
+
64
+ include_examples "unrelated example does not raise"
65
+ end
66
+
67
+ context "with use_active_record set to true" do
68
+ before { RSpec . configuration . use_active_record = true }
69
+
70
+ if Rails . version . to_f >= 4.0
71
+ include_examples "unrelated example does not raise"
72
+ else
73
+ include_examples "unrelated example raise"
74
+ end
75
+ end
76
+ end
24
77
end
25
78
end
0 commit comments