@@ -33,16 +33,16 @@ module ActiveRecord
3333 end
3434
3535 context "when unsupported adapter" do
36- before { allow ( ::ActiveRecord ::Base ) . to receive ( :connection ) . and_return ( double ( adapter_name : "kakadudu" ) ) }
37-
3836 it "raises an error" do
37+ with_stubbed_adapter ( "kakadudu" )
38+
3939 expect { RailsMigrationGenerator . new ( [ ] , data_type : nil ) } . to raise_error RailsMigrationGenerator ::Error ,
4040 'Unsupported adapter: "kakadudu"'
4141 end
4242 end
4343
4444 context "when postgresql adapter is used and data_type option is specified" do
45- before { allow ( :: ActiveRecord :: Base ) . to receive ( :connection ) . and_return ( double ( adapter_name : "postgresql" ) ) }
45+ before { with_stubbed_adapter ( "postgresql" ) }
4646
4747 subject do
4848 RailsMigrationGenerator . start ( [ "--data-type=#{ data_type } " ] , destination_root : @dir )
@@ -72,7 +72,7 @@ module ActiveRecord
7272 end
7373
7474 context "when mysql adapter is used and data_type option is specified" do
75- before { allow ( :: ActiveRecord :: Base ) . to receive ( :connection ) . and_return ( double ( adapter_name : "Mysql2" ) ) }
75+ before { with_stubbed_adapter ( "Mysql2" ) }
7676
7777 subject do
7878 RailsMigrationGenerator . start ( [ "--data-type=#{ data_type } " ] , destination_root : @dir )
@@ -106,7 +106,7 @@ module ActiveRecord
106106 end
107107
108108 context "when sqlite adapter is used and data_type option is specified" do
109- before { allow ( :: ActiveRecord :: Base ) . to receive ( :connection ) . and_return ( double ( adapter_name : "sqlite" ) ) }
109+ before { with_stubbed_adapter ( "sqlite" ) }
110110
111111 subject do
112112 RailsMigrationGenerator . start ( [ "--data-type=#{ data_type } " ] , destination_root : @dir )
@@ -153,6 +153,12 @@ module ActiveRecord
153153 end
154154 end
155155 end
156+
157+ private
158+
159+ def with_stubbed_adapter ( name )
160+ allow ( ::ActiveRecord ::Base ) . to receive ( :connection ) . and_return ( double ( adapter_name : name ) )
161+ end
156162 end
157163 end
158164end
0 commit comments