@@ -13,5 +13,54 @@ module RSpec::Rails
1313 expect ( group ) . to respond_to ( :fixture_path= )
1414 end
1515 end
16+
17+ context "without database available" do
18+ before { clear_active_record_connection }
19+
20+ after { establish_active_record_connection }
21+
22+ context "with use_active_record set to true" do
23+ before { RSpec . configuration . use_active_record = true }
24+
25+ # Not all Rails versions raise the
26+ # +ActiveRecord::ConnectionNotEstablished+ exception at this point.
27+ # (Eg. Rails 3.x, 4.0, 5.0)
28+ it "raise due to no connection established" do
29+ example_group = RSpec ::Core ::ExampleGroup . describe ( "FixtureSupport" ) do
30+ include FixtureSupport
31+ include RSpec ::Rails ::MinitestLifecycleAdapter
32+ end
33+
34+ test = example_group . example ( "foo" ) do
35+ expect ( true ) . to be ( true )
36+ end
37+
38+ success = example_group . run
39+ expect ( test . execution_result . exception ) . to \
40+ be_a ( ActiveRecord ::ConnectionNotEstablished ) unless success
41+ end
42+ end
43+
44+ context "with use_active_record set to false" do
45+ before { RSpec . configuration . use_active_record = false }
46+
47+ after { RSpec . configuration . use_active_record = true }
48+
49+ it "does not raise" do
50+ example_group = RSpec ::Core ::ExampleGroup . describe ( "FixtureSupport" ) do
51+ include FixtureSupport
52+ include RSpec ::Rails ::MinitestLifecycleAdapter
53+ end
54+
55+ test = example_group . example ( "foo" ) do
56+ expect ( true ) . to be ( true )
57+ end
58+
59+ expect ( example_group . run ) . to be ( true )
60+ expect ( test . execution_result . exception ) . not_to \
61+ be_a ( ActiveRecord ::ConnectionNotEstablished )
62+ end
63+ end
64+ end
1665 end
1766end
0 commit comments