sequel 4.22.0 → 4.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +22 -0
  3. data/README.rdoc +6 -0
  4. data/Rakefile +59 -81
  5. data/doc/migration.rdoc +2 -0
  6. data/doc/release_notes/4.23.0.txt +65 -0
  7. data/doc/sharding.rdoc +16 -14
  8. data/doc/testing.rdoc +61 -77
  9. data/lib/sequel/adapters/jdbc.rb +1 -0
  10. data/lib/sequel/adapters/mock.rb +0 -1
  11. data/lib/sequel/adapters/postgres.rb +1 -0
  12. data/lib/sequel/adapters/postgresql.rb +1 -0
  13. data/lib/sequel/adapters/shared/postgres.rb +3 -3
  14. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
  15. data/lib/sequel/connection_pool/threaded.rb +9 -1
  16. data/lib/sequel/database/connecting.rb +1 -1
  17. data/lib/sequel/database/transactions.rb +2 -1
  18. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  19. data/lib/sequel/extensions/constraint_validations.rb +12 -12
  20. data/lib/sequel/extensions/date_arithmetic.rb +0 -4
  21. data/lib/sequel/extensions/pagination.rb +14 -2
  22. data/lib/sequel/extensions/pg_enum.rb +2 -2
  23. data/lib/sequel/extensions/pg_hstore.rb +1 -1
  24. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  25. data/lib/sequel/plugins/csv_serializer.rb +2 -0
  26. data/lib/sequel/plugins/delay_add_association.rb +50 -0
  27. data/lib/sequel/plugins/list.rb +2 -2
  28. data/lib/sequel/plugins/nested_attributes.rb +8 -28
  29. data/lib/sequel/plugins/update_refresh.rb +50 -0
  30. data/lib/sequel/plugins/validate_associated.rb +55 -0
  31. data/lib/sequel/version.rb +1 -1
  32. data/spec/adapters/db2_spec.rb +29 -29
  33. data/spec/adapters/firebird_spec.rb +97 -103
  34. data/spec/adapters/informix_spec.rb +25 -25
  35. data/spec/adapters/mssql_spec.rb +156 -172
  36. data/spec/adapters/mysql_spec.rb +334 -359
  37. data/spec/adapters/oracle_spec.rb +67 -69
  38. data/spec/adapters/postgres_spec.rb +1298 -1249
  39. data/spec/adapters/spec_helper.rb +2 -35
  40. data/spec/adapters/sqlanywhere_spec.rb +39 -39
  41. data/spec/adapters/sqlite_spec.rb +203 -200
  42. data/spec/bin_spec.rb +57 -59
  43. data/spec/core/connection_pool_spec.rb +402 -401
  44. data/spec/core/database_spec.rb +953 -944
  45. data/spec/core/dataset_spec.rb +2178 -2168
  46. data/spec/core/deprecated_spec.rb +19 -19
  47. data/spec/core/expression_filters_spec.rb +415 -415
  48. data/spec/core/mock_adapter_spec.rb +212 -212
  49. data/spec/core/object_graph_spec.rb +73 -73
  50. data/spec/core/placeholder_literalizer_spec.rb +71 -71
  51. data/spec/core/schema_generator_spec.rb +44 -44
  52. data/spec/core/schema_spec.rb +470 -472
  53. data/spec/core/spec_helper.rb +5 -20
  54. data/spec/core/version_spec.rb +2 -2
  55. data/spec/core_extensions_spec.rb +320 -320
  56. data/spec/extensions/accessed_columns_spec.rb +12 -12
  57. data/spec/extensions/active_model_spec.rb +3 -3
  58. data/spec/extensions/after_initialize_spec.rb +2 -2
  59. data/spec/extensions/arbitrary_servers_spec.rb +23 -23
  60. data/spec/extensions/association_dependencies_spec.rb +34 -34
  61. data/spec/extensions/association_pks_spec.rb +98 -98
  62. data/spec/extensions/association_proxies_spec.rb +33 -33
  63. data/spec/extensions/auto_validations_spec.rb +46 -46
  64. data/spec/extensions/blacklist_security_spec.rb +19 -18
  65. data/spec/extensions/blank_spec.rb +36 -36
  66. data/spec/extensions/boolean_readers_spec.rb +36 -36
  67. data/spec/extensions/caching_spec.rb +82 -82
  68. data/spec/extensions/class_table_inheritance_spec.rb +72 -72
  69. data/spec/extensions/column_conflicts_spec.rb +19 -14
  70. data/spec/extensions/column_select_spec.rb +19 -19
  71. data/spec/extensions/columns_introspection_spec.rb +43 -43
  72. data/spec/extensions/composition_spec.rb +64 -64
  73. data/spec/extensions/connection_validator_spec.rb +92 -90
  74. data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
  75. data/spec/extensions/constraint_validations_spec.rb +80 -80
  76. data/spec/extensions/core_refinements_spec.rb +220 -220
  77. data/spec/extensions/csv_serializer_spec.rb +44 -44
  78. data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
  79. data/spec/extensions/dataset_associations_spec.rb +65 -65
  80. data/spec/extensions/dataset_source_alias_spec.rb +16 -16
  81. data/spec/extensions/date_arithmetic_spec.rb +51 -58
  82. data/spec/extensions/defaults_setter_spec.rb +19 -19
  83. data/spec/extensions/delay_add_association_spec.rb +52 -0
  84. data/spec/extensions/dirty_spec.rb +51 -51
  85. data/spec/extensions/eager_each_spec.rb +8 -8
  86. data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
  87. data/spec/extensions/error_splitter_spec.rb +2 -2
  88. data/spec/extensions/error_sql_spec.rb +4 -4
  89. data/spec/extensions/eval_inspect_spec.rb +3 -3
  90. data/spec/extensions/filter_having_spec.rb +8 -8
  91. data/spec/extensions/force_encoding_spec.rb +30 -30
  92. data/spec/extensions/from_block_spec.rb +7 -7
  93. data/spec/extensions/graph_each_spec.rb +19 -19
  94. data/spec/extensions/hash_aliases_spec.rb +5 -5
  95. data/spec/extensions/hook_class_methods_spec.rb +100 -100
  96. data/spec/extensions/inflector_spec.rb +54 -54
  97. data/spec/extensions/input_transformer_spec.rb +10 -10
  98. data/spec/extensions/insert_returning_select_spec.rb +8 -8
  99. data/spec/extensions/instance_filters_spec.rb +26 -26
  100. data/spec/extensions/instance_hooks_spec.rb +85 -85
  101. data/spec/extensions/json_serializer_spec.rb +68 -68
  102. data/spec/extensions/lazy_attributes_spec.rb +49 -49
  103. data/spec/extensions/list_spec.rb +77 -75
  104. data/spec/extensions/looser_typecasting_spec.rb +16 -16
  105. data/spec/extensions/many_through_many_spec.rb +627 -627
  106. data/spec/extensions/meta_def_spec.rb +7 -7
  107. data/spec/extensions/migration_spec.rb +217 -217
  108. data/spec/extensions/modification_detection_spec.rb +20 -20
  109. data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
  110. data/spec/extensions/named_timezones_spec.rb +18 -18
  111. data/spec/extensions/nested_attributes_spec.rb +107 -107
  112. data/spec/extensions/null_dataset_spec.rb +24 -24
  113. data/spec/extensions/optimistic_locking_spec.rb +21 -21
  114. data/spec/extensions/pagination_spec.rb +52 -52
  115. data/spec/extensions/pg_array_associations_spec.rb +273 -273
  116. data/spec/extensions/pg_array_ops_spec.rb +52 -52
  117. data/spec/extensions/pg_array_spec.rb +152 -152
  118. data/spec/extensions/pg_enum_spec.rb +13 -13
  119. data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
  120. data/spec/extensions/pg_hstore_spec.rb +84 -84
  121. data/spec/extensions/pg_inet_spec.rb +15 -15
  122. data/spec/extensions/pg_interval_spec.rb +29 -29
  123. data/spec/extensions/pg_json_ops_spec.rb +86 -84
  124. data/spec/extensions/pg_json_spec.rb +104 -104
  125. data/spec/extensions/pg_loose_count_spec.rb +6 -6
  126. data/spec/extensions/pg_range_ops_spec.rb +24 -24
  127. data/spec/extensions/pg_range_spec.rb +143 -143
  128. data/spec/extensions/pg_row_ops_spec.rb +14 -14
  129. data/spec/extensions/pg_row_plugin_spec.rb +12 -12
  130. data/spec/extensions/pg_row_spec.rb +118 -118
  131. data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
  132. data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
  133. data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
  134. data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
  135. data/spec/extensions/prepared_statements_spec.rb +28 -28
  136. data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
  137. data/spec/extensions/pretty_table_spec.rb +16 -16
  138. data/spec/extensions/query_literals_spec.rb +37 -37
  139. data/spec/extensions/query_spec.rb +32 -32
  140. data/spec/extensions/rcte_tree_spec.rb +141 -141
  141. data/spec/extensions/round_timestamps_spec.rb +21 -21
  142. data/spec/extensions/schema_caching_spec.rb +8 -8
  143. data/spec/extensions/schema_dumper_spec.rb +78 -78
  144. data/spec/extensions/schema_spec.rb +31 -27
  145. data/spec/extensions/scissors_spec.rb +3 -3
  146. data/spec/extensions/select_remove_spec.rb +14 -14
  147. data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
  148. data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
  149. data/spec/extensions/serialization_spec.rb +79 -78
  150. data/spec/extensions/server_block_spec.rb +17 -17
  151. data/spec/extensions/set_overrides_spec.rb +30 -30
  152. data/spec/extensions/sharding_spec.rb +65 -65
  153. data/spec/extensions/shared_caching_spec.rb +29 -29
  154. data/spec/extensions/single_table_inheritance_spec.rb +79 -79
  155. data/spec/extensions/skip_create_refresh_spec.rb +3 -3
  156. data/spec/extensions/spec_helper.rb +4 -29
  157. data/spec/extensions/split_array_nil_spec.rb +9 -9
  158. data/spec/extensions/split_values_spec.rb +7 -7
  159. data/spec/extensions/sql_expr_spec.rb +32 -32
  160. data/spec/extensions/static_cache_spec.rb +123 -123
  161. data/spec/extensions/string_date_time_spec.rb +34 -34
  162. data/spec/extensions/string_stripper_spec.rb +15 -15
  163. data/spec/extensions/subclasses_spec.rb +31 -31
  164. data/spec/extensions/table_select_spec.rb +15 -15
  165. data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
  166. data/spec/extensions/thread_local_timezones_spec.rb +13 -13
  167. data/spec/extensions/timestamps_spec.rb +40 -40
  168. data/spec/extensions/to_dot_spec.rb +34 -34
  169. data/spec/extensions/touch_spec.rb +52 -52
  170. data/spec/extensions/tree_spec.rb +72 -72
  171. data/spec/extensions/typecast_on_load_spec.rb +25 -25
  172. data/spec/extensions/unlimited_update_spec.rb +2 -2
  173. data/spec/extensions/update_or_create_spec.rb +36 -36
  174. data/spec/extensions/update_primary_key_spec.rb +35 -35
  175. data/spec/extensions/update_refresh_spec.rb +41 -0
  176. data/spec/extensions/validate_associated_spec.rb +52 -0
  177. data/spec/extensions/validation_class_methods_spec.rb +314 -317
  178. data/spec/extensions/validation_helpers_spec.rb +195 -195
  179. data/spec/extensions/xml_serializer_spec.rb +48 -48
  180. data/spec/guards_helper.rb +55 -0
  181. data/spec/integration/associations_test.rb +1089 -1088
  182. data/spec/integration/database_test.rb +29 -29
  183. data/spec/integration/dataset_test.rb +661 -661
  184. data/spec/integration/eager_loader_test.rb +147 -147
  185. data/spec/integration/migrator_test.rb +122 -122
  186. data/spec/integration/model_test.rb +70 -70
  187. data/spec/integration/plugin_test.rb +682 -640
  188. data/spec/integration/prepared_statement_test.rb +172 -172
  189. data/spec/integration/schema_test.rb +245 -245
  190. data/spec/integration/spec_helper.rb +1 -64
  191. data/spec/integration/timezone_test.rb +17 -17
  192. data/spec/integration/transaction_test.rb +87 -87
  193. data/spec/integration/type_test.rb +33 -33
  194. data/spec/model/association_reflection_spec.rb +130 -121
  195. data/spec/model/associations_spec.rb +1112 -1113
  196. data/spec/model/base_spec.rb +197 -196
  197. data/spec/model/class_dataset_methods_spec.rb +118 -118
  198. data/spec/model/dataset_methods_spec.rb +49 -49
  199. data/spec/model/eager_loading_spec.rb +705 -702
  200. data/spec/model/hooks_spec.rb +169 -168
  201. data/spec/model/inflector_spec.rb +5 -5
  202. data/spec/model/model_spec.rb +287 -297
  203. data/spec/model/plugins_spec.rb +47 -47
  204. data/spec/model/record_spec.rb +534 -535
  205. data/spec/model/spec_helper.rb +3 -21
  206. data/spec/model/validations_spec.rb +72 -70
  207. data/spec/spec_config.rb +8 -0
  208. metadata +41 -9
  209. data/lib/sequel/adapters/fdbsql.rb +0 -286
  210. data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
  211. data/lib/sequel/adapters/openbase.rb +0 -54
  212. data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
  213. data/spec/adapters/fdbsql_spec.rb +0 -429
  214. data/spec/rspec_helper.rb +0 -22
@@ -26,7 +26,7 @@ DB2 = Sequel.connect("#{CONN_PREFIX}#{BIN_SPEC_DB2}")
26
26
  File.delete(BIN_SPEC_DB) if File.file?(BIN_SPEC_DB)
27
27
  File.delete(BIN_SPEC_DB2) if File.file?(BIN_SPEC_DB2)
28
28
 
29
- require File.join(File.dirname(File.expand_path(__FILE__)), "rspec_helper.rb")
29
+ require 'minitest/autorun'
30
30
 
31
31
  describe "bin/sequel" do
32
32
  def bin(opts={})
@@ -41,22 +41,20 @@ describe "bin/sequel" do
41
41
  File.delete(BIN_SPEC_DB) if File.file?(BIN_SPEC_DB)
42
42
  File.delete(BIN_SPEC_DB2) if File.file?(BIN_SPEC_DB2)
43
43
  File.delete(TMP_FILE) if File.file?(TMP_FILE)
44
- end
45
- after(:all) do
46
44
  File.delete(OUTPUT) if File.file?(OUTPUT)
47
45
  end
48
46
 
49
47
  it "-h should print the help" do
50
48
  help = bin(:args=>"-h", :no_conn=>true)
51
- help.should =~ /\ASequel: The Database Toolkit for Ruby/
52
- help.should =~ /^Usage: sequel /
49
+ help.must_match(/\ASequel: The Database Toolkit for Ruby/)
50
+ help.must_match(/^Usage: sequel /)
53
51
  end
54
52
 
55
53
  it "-c should run code" do
56
- bin(:args=>'-c "print DB.tables.inspect"').should == '[]'
54
+ bin(:args=>'-c "print DB.tables.inspect"').must_equal '[]'
57
55
  DB.create_table(:a){Integer :a}
58
- bin(:args=>'-c "print DB.tables.inspect"').should == '[:a]'
59
- bin(:args=>'-v -c "print DB.tables.inspect"').should == "sequel #{Sequel.version}\n[:a]"
56
+ bin(:args=>'-c "print DB.tables.inspect"').must_equal '[:a]'
57
+ bin(:args=>'-v -c "print DB.tables.inspect"').strip.must_equal "sequel #{Sequel.version}\n[:a]"
60
58
  end
61
59
 
62
60
  it "-C should copy databases" do
@@ -70,7 +68,7 @@ describe "bin/sequel" do
70
68
  end
71
69
  DB[:a].insert(1, 'foo')
72
70
  DB[:b].insert(1)
73
- bin(:args=>'-C', :post=>"#{CONN_PREFIX}#{BIN_SPEC_DB2}").should =~ Regexp.new(<<END)
71
+ bin(:args=>'-C', :post=>"#{CONN_PREFIX}#{BIN_SPEC_DB2}").must_match Regexp.new(<<END)
74
72
  Databases connections successful
75
73
  Migrations dumped successfully
76
74
  Tables created
@@ -86,15 +84,15 @@ Begin adding foreign key constraints
86
84
  Finished adding foreign key constraints
87
85
  Database copy finished in \\d\\.\\d+ seconds
88
86
  END
89
- DB2.tables.sort_by{|t| t.to_s}.should == [:a, :b]
90
- DB[:a].all.should == [{:a=>1, :name=>'foo'}]
91
- DB[:b].all.should == [{:a=>1}]
92
- DB2.schema(:a).map{|col, sch| [col, *sch.values_at(:allow_null, :default, :primary_key, :db_type, :type, :ruby_default)]}.should == [[:a, false, nil, true, "integer", :integer, nil], [:name, true, nil, false, "varchar(255)", :string, nil]]
93
- DB2.schema(:b).map{|col, sch| [col, *sch.values_at(:allow_null, :default, :primary_key, :db_type, :type, :ruby_default)]}.should == [[:a, true, nil, false, "integer", :integer, nil]]
94
- DB2.indexes(:a).should == {}
95
- DB2.indexes(:b).should == {:b_a_index=>{:unique=>false, :columns=>[:a]}}
96
- DB2.foreign_key_list(:a).should == []
97
- DB2.foreign_key_list(:b).should == [{:columns=>[:a], :table=>:a, :key=>nil, :on_update=>:no_action, :on_delete=>:no_action}]
87
+ DB2.tables.sort_by{|t| t.to_s}.must_equal [:a, :b]
88
+ DB[:a].all.must_equal [{:a=>1, :name=>'foo'}]
89
+ DB[:b].all.must_equal [{:a=>1}]
90
+ DB2.schema(:a).map{|col, sch| [col, *sch.values_at(:allow_null, :default, :primary_key, :db_type, :type, :ruby_default)]}.must_equal [[:a, false, nil, true, "integer", :integer, nil], [:name, true, nil, false, "varchar(255)", :string, nil]]
91
+ DB2.schema(:b).map{|col, sch| [col, *sch.values_at(:allow_null, :default, :primary_key, :db_type, :type, :ruby_default)]}.must_equal [[:a, true, nil, false, "integer", :integer, nil]]
92
+ DB2.indexes(:a).must_equal({})
93
+ DB2.indexes(:b).must_equal(:b_a_index=>{:unique=>false, :columns=>[:a]})
94
+ DB2.foreign_key_list(:a).must_equal []
95
+ DB2.foreign_key_list(:b).must_equal [{:columns=>[:a], :table=>:a, :key=>nil, :on_update=>:no_action, :on_delete=>:no_action}]
98
96
  end
99
97
 
100
98
  it "-d and -D should dump generic and specific migrations" do
@@ -106,7 +104,7 @@ END
106
104
  foreign_key :a, :a
107
105
  index :a
108
106
  end
109
- bin(:args=>'-d').should == <<END
107
+ bin(:args=>'-d').must_equal <<END
110
108
  Sequel.migration do
111
109
  change do
112
110
  create_table(:a) do
@@ -122,7 +120,7 @@ Sequel.migration do
122
120
  end
123
121
  end
124
122
  END
125
- bin(:args=>'-D').should == <<END
123
+ bin(:args=>'-D').must_equal <<END
126
124
  Sequel.migration do
127
125
  change do
128
126
  create_table(:a) do
@@ -141,79 +139,79 @@ END
141
139
  end
142
140
 
143
141
  it "-E should echo SQL statements to stdout" do
144
- bin(:args=>'-E -c DB.tables').should =~ %r{SELECT \* FROM `sqlite_master` WHERE \(type = 'table' AND NOT name = 'sqlite_sequence'\)\n}
142
+ bin(:args=>'-E -c DB.tables').must_match %r{SELECT \* FROM `sqlite_master` WHERE \(type = 'table' AND NOT name = 'sqlite_sequence'\)\n}
145
143
  end
146
144
 
147
145
  it "-I should include directory in load path" do
148
- bin(:args=>'-Ifoo -c "p 1 if $:.include?(\'foo\')"').should == "1\n"
146
+ bin(:args=>'-Ifoo -c "p 1 if $:.include?(\'foo\')"').must_equal "1\n"
149
147
  end
150
148
 
151
149
  it "-l should log SQL statements to file" do
152
- bin(:args=>"-l #{TMP_FILE} -c DB.tables").should == ''
153
- File.read(TMP_FILE).should =~ %r{SELECT \* FROM `sqlite_master` WHERE \(type = 'table' AND NOT name = 'sqlite_sequence'\)\n}
150
+ bin(:args=>"-l #{TMP_FILE} -c DB.tables").must_equal ''
151
+ File.read(TMP_FILE).must_match %r{SELECT \* FROM `sqlite_master` WHERE \(type = 'table' AND NOT name = 'sqlite_sequence'\)\n}
154
152
  end
155
153
 
156
154
  it "-L should load all *.rb files in given directory" do
157
- bin(:args=>'-L ./lib/sequel/connection_pool -c "p [Sequel::SingleConnectionPool, Sequel::ThreadedConnectionPool, Sequel::ShardedSingleConnectionPool, Sequel::ShardedThreadedConnectionPool].length"').should == "4\n"
155
+ bin(:args=>'-L ./lib/sequel/connection_pool -c "p [Sequel::SingleConnectionPool, Sequel::ThreadedConnectionPool, Sequel::ShardedSingleConnectionPool, Sequel::ShardedThreadedConnectionPool].length"').must_equal "4\n"
158
156
  end
159
157
 
160
158
  it "-m should migrate database up" do
161
- bin(:args=>"-m spec/files/integer_migrations").should == ''
162
- DB.tables.sort_by{|t| t.to_s}.should == [:schema_info, :sm1111, :sm2222, :sm3333]
159
+ bin(:args=>"-m spec/files/integer_migrations").must_equal ''
160
+ DB.tables.sort_by{|t| t.to_s}.must_equal [:schema_info, :sm1111, :sm2222, :sm3333]
163
161
  end
164
162
 
165
163
  it "-M should specify version to migrate to" do
166
- bin(:args=>"-m spec/files/integer_migrations -M 2").should == ''
167
- DB.tables.sort_by{|t| t.to_s}.should == [:schema_info, :sm1111, :sm2222]
164
+ bin(:args=>"-m spec/files/integer_migrations -M 2").must_equal ''
165
+ DB.tables.sort_by{|t| t.to_s}.must_equal [:schema_info, :sm1111, :sm2222]
168
166
  end
169
167
 
170
168
  it "-N should not test for a valid connection" do
171
- bin(:no_conn=>true, :args=>"-c '' -N #{CONN_PREFIX}spec/nonexistent/foo").should == ''
172
- bin(:no_conn=>true, :args=>"-c '' #{CONN_PREFIX}spec/nonexistent/foo", :stderr=>true).should =~ /\AError: Sequel::DatabaseConnectionError: /
169
+ bin(:no_conn=>true, :args=>"-c '' -N #{CONN_PREFIX}spec/nonexistent/foo").must_equal ''
170
+ bin(:no_conn=>true, :args=>"-c '' #{CONN_PREFIX}spec/nonexistent/foo", :stderr=>true).must_match(/\AError: Sequel::DatabaseConnectionError: /)
173
171
  end
174
172
 
175
173
  it "-r should require a given library" do
176
- bin(:args=>'-rsequel/extensions/sql_expr -c "print DB.literal(1.sql_expr)"').should == "1"
174
+ bin(:args=>'-rsequel/extensions/sql_expr -c "print DB.literal(1.sql_expr)"').must_equal "1"
177
175
  end
178
176
 
179
177
  it "-S should dump the schema cache" do
180
- bin(:args=>"-S #{TMP_FILE}").should == ''
181
- Marshal.load(File.read(TMP_FILE)).should == {}
178
+ bin(:args=>"-S #{TMP_FILE}").must_equal ''
179
+ Marshal.load(File.read(TMP_FILE)).must_equal({})
182
180
  DB.create_table(:a){Integer :a}
183
- bin(:args=>"-S #{TMP_FILE}").should == ''
184
- Marshal.load(File.read(TMP_FILE)).should == {"`a`"=>[[:a, {:type=>:integer, :db_type=>"integer", :ruby_default=>nil, :allow_null=>true, :default=>nil, :primary_key=>false}]]}
181
+ bin(:args=>"-S #{TMP_FILE}").must_equal ''
182
+ Marshal.load(File.read(TMP_FILE)).must_equal("`a`"=>[[:a, {:type=>:integer, :db_type=>"integer", :ruby_default=>nil, :allow_null=>true, :default=>nil, :primary_key=>false}]])
185
183
  end
186
184
 
187
185
  it "-t should output full backtraces on error" do
188
- bin(:args=>'-c "lambda{lambda{lambda{raise \'foo\'}.call}.call}.call"', :stderr=>true).count("\n").should < 3
189
- bin(:args=>'-t -c "lambda{lambda{lambda{raise \'foo\'}.call}.call}.call"', :stderr=>true).count("\n").should > 3
186
+ bin(:args=>'-c "lambda{lambda{lambda{raise \'foo\'}.call}.call}.call"', :stderr=>true).count("\n").must_be :<, 3
187
+ bin(:args=>'-t -c "lambda{lambda{lambda{raise \'foo\'}.call}.call}.call"', :stderr=>true).count("\n").must_be :>, 3
190
188
  end
191
189
 
192
190
  it "-v should output the Sequel version and exit if database is not given" do
193
- bin(:args=>"-v", :no_conn=>true).should == "sequel #{Sequel.version}\n"
191
+ bin(:args=>"-v", :no_conn=>true).strip.must_equal "sequel #{Sequel.version}"
194
192
  end
195
193
 
196
194
  it "should error if using -M without -m" do
197
- bin(:args=>'-M 2', :stderr=>true).should == "Error: Must specify -m if using -M\n"
195
+ bin(:args=>'-M 2', :stderr=>true).must_equal "Error: Must specify -m if using -M\n"
198
196
  end
199
197
 
200
198
  it "should error if using mutually exclusive options together" do
201
- bin(:args=>'-c foo -d', :stderr=>true).should == "Error: Cannot specify -c and -d together\n"
202
- bin(:args=>'-D -d', :stderr=>true).should == "Error: Cannot specify -D and -d together\n"
203
- bin(:args=>'-m foo -d', :stderr=>true).should == "Error: Cannot specify -m and -d together\n"
204
- bin(:args=>'-S foo -d', :stderr=>true).should == "Error: Cannot specify -S and -d together\n"
205
- bin(:args=>'-S foo -C', :stderr=>true).should == "Error: Cannot specify -S and -C together\n"
199
+ bin(:args=>'-c foo -d', :stderr=>true).must_equal "Error: Cannot specify -c and -d together\n"
200
+ bin(:args=>'-D -d', :stderr=>true).must_equal "Error: Cannot specify -D and -d together\n"
201
+ bin(:args=>'-m foo -d', :stderr=>true).must_equal "Error: Cannot specify -m and -d together\n"
202
+ bin(:args=>'-S foo -d', :stderr=>true).must_equal "Error: Cannot specify -S and -d together\n"
203
+ bin(:args=>'-S foo -C', :stderr=>true).must_equal "Error: Cannot specify -S and -C together\n"
206
204
  end
207
205
 
208
206
  it "should use a mock database if no database is given" do
209
- bin(:args=>'-c "print DB.adapter_scheme"', :no_conn=>true).should == "mock"
207
+ bin(:args=>'-c "print DB.adapter_scheme"', :no_conn=>true).must_equal "mock"
210
208
  end
211
209
 
212
210
  it "should work with a yaml config file" do
213
211
  File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump(CONN_HASH))}
214
- bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[]"
212
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).must_equal "[]"
215
213
  DB.create_table(:a){Integer :a}
216
- bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[:a]"
214
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).must_equal "[:a]"
217
215
  end
218
216
 
219
217
  it "should work with a yaml config file with string keys" do
@@ -221,36 +219,36 @@ END
221
219
  CONN_HASH.each{|k,v| h[k.to_s] = v}
222
220
  File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump(h))}
223
221
  DB.create_table(:a){Integer :a}
224
- bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[:a]"
222
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).must_equal "[:a]"
225
223
  end
226
224
 
227
225
  it "should work with a yaml config file with environments" do
228
226
  File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump(:development=>CONN_HASH))}
229
- bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[]"
227
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).must_equal "[]"
230
228
  DB.create_table(:a){Integer :a}
231
- bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).should == "[:a]"
229
+ bin(:args=>"-c \"print DB.tables.inspect\" #{TMP_FILE}", :no_conn=>true).must_equal "[:a]"
232
230
  end
233
231
 
234
232
  it "-e should set environment for yaml config file" do
235
233
  File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump(:foo=>CONN_HASH))}
236
- bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).should == "[]"
234
+ bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).must_equal "[]"
237
235
  DB.create_table(:a){Integer :a}
238
- bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).should == "[:a]"
236
+ bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).must_equal "[:a]"
239
237
  File.open(TMP_FILE, 'wb'){|f| f.write(YAML.dump('foo'=>CONN_HASH))}
240
- bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).should == "[:a]"
238
+ bin(:args=>"-c \"print DB.tables.inspect\" -e foo #{TMP_FILE}", :no_conn=>true).must_equal "[:a]"
241
239
  end
242
240
 
243
241
  it "should run code in given filenames" do
244
242
  File.open(TMP_FILE, 'wb'){|f| f.write('print DB.tables.inspect')}
245
- bin(:post=>TMP_FILE).should == '[]'
243
+ bin(:post=>TMP_FILE).must_equal '[]'
246
244
  DB.create_table(:a){Integer :a}
247
- bin(:post=>TMP_FILE).should == '[:a]'
248
- bin(:post=>TMP_FILE, :args=>'-v').should == "sequel #{Sequel.version}\n[:a]"
245
+ bin(:post=>TMP_FILE).must_equal '[:a]'
246
+ bin(:post=>TMP_FILE, :args=>'-v').strip.must_equal "sequel #{Sequel.version}\n[:a]"
249
247
  end
250
248
 
251
249
  it "should run code provided on stdin" do
252
- bin(:pre=>'echo print DB.tables.inspect | ').should == '[]'
250
+ bin(:pre=>'echo print DB.tables.inspect | ').must_equal '[]'
253
251
  DB.create_table(:a){Integer :a}
254
- bin(:pre=>'echo print DB.tables.inspect | ').should == '[:a]'
252
+ bin(:pre=>'echo print DB.tables.inspect | ').must_equal '[:a]'
255
253
  end
256
254
  end
@@ -15,32 +15,32 @@ describe "An empty ConnectionPool" do
15
15
  @cpool = Sequel::ConnectionPool.get_pool(mock_db.call, CONNECTION_POOL_DEFAULTS)
16
16
  end
17
17
 
18
- specify "should have no available connections" do
19
- @cpool.available_connections.should == []
18
+ it "should have no available connections" do
19
+ @cpool.available_connections.must_equal []
20
20
  end
21
21
 
22
- specify "should have no allocated connections" do
23
- @cpool.allocated.should == {}
22
+ it "should have no allocated connections" do
23
+ @cpool.allocated.must_equal({})
24
24
  end
25
25
 
26
- specify "should have a created_count of zero" do
27
- @cpool.created_count.should == 0
26
+ it "should have a created_count of zero" do
27
+ @cpool.created_count.must_equal 0
28
28
  end
29
29
  end
30
30
 
31
31
  describe "ConnectionPool options" do
32
- specify "should support string option values" do
32
+ it "should support string option values" do
33
33
  cpool = Sequel::ConnectionPool.get_pool(mock_db.call, {:max_connections=>'5', :pool_timeout=>'3', :pool_sleep_time=>'0.01'})
34
- cpool.max_size.should == 5
35
- cpool.instance_variable_get(:@timeout).should == 3
36
- cpool.instance_variable_get(:@sleep_time).should == 0.01 unless cpool.class::USE_WAITER
34
+ cpool.max_size.must_equal 5
35
+ cpool.instance_variable_get(:@timeout).must_equal 3
36
+ cpool.instance_variable_get(:@sleep_time).must_equal 0.01 unless cpool.class::USE_WAITER
37
37
  end
38
38
 
39
- specify "should raise an error unless size is positive" do
40
- lambda{Sequel::ConnectionPool.get_pool(mock_db.call{1}, :max_connections=>0)}.should raise_error(Sequel::Error)
41
- lambda{Sequel::ConnectionPool.get_pool(mock_db.call{1}, :max_connections=>-10)}.should raise_error(Sequel::Error)
42
- lambda{Sequel::ConnectionPool.get_pool(mock_db.call{1}, :max_connections=>'-10')}.should raise_error(Sequel::Error)
43
- lambda{Sequel::ConnectionPool.get_pool(mock_db.call{1}, :max_connections=>'0')}.should raise_error(Sequel::Error)
39
+ it "should raise an error unless size is positive" do
40
+ lambda{Sequel::ConnectionPool.get_pool(mock_db.call{1}, :max_connections=>0)}.must_raise(Sequel::Error)
41
+ lambda{Sequel::ConnectionPool.get_pool(mock_db.call{1}, :max_connections=>-10)}.must_raise(Sequel::Error)
42
+ lambda{Sequel::ConnectionPool.get_pool(mock_db.call{1}, :max_connections=>'-10')}.must_raise(Sequel::Error)
43
+ lambda{Sequel::ConnectionPool.get_pool(mock_db.call{1}, :max_connections=>'0')}.must_raise(Sequel::Error)
44
44
  end
45
45
  end
46
46
 
@@ -51,86 +51,86 @@ describe "A connection pool handling connections" do
51
51
  @cpool = Sequel::ConnectionPool.get_pool(mock_db.call(proc{|c| msp.call}){:got_connection}, CONNECTION_POOL_DEFAULTS.merge(:max_connections=>@max_size))
52
52
  end
53
53
 
54
- specify "#hold should increment #created_count" do
54
+ it "#hold should increment #created_count" do
55
55
  @cpool.hold do
56
- @cpool.created_count.should == 1
57
- @cpool.hold {@cpool.hold {@cpool.created_count.should == 1}}
58
- Thread.new{@cpool.hold {@cpool.created_count.should == 2}}.join
56
+ @cpool.created_count.must_equal 1
57
+ @cpool.hold {@cpool.hold {@cpool.created_count.must_equal 1}}
58
+ Thread.new{@cpool.hold {_(@cpool.created_count).must_equal 2}}.join
59
59
  end
60
60
  end
61
61
 
62
- specify "#hold should add the connection to the #allocated array" do
62
+ it "#hold should add the connection to the #allocated array" do
63
63
  @cpool.hold do
64
- @cpool.allocated.size.should == 1
64
+ @cpool.allocated.size.must_equal 1
65
65
 
66
- @cpool.allocated.should == {Thread.current=>:got_connection}
66
+ @cpool.allocated.must_equal(Thread.current=>:got_connection)
67
67
  end
68
68
  end
69
69
 
70
- specify "#hold should yield a new connection" do
71
- @cpool.hold {|conn| conn.should == :got_connection}
70
+ it "#hold should yield a new connection" do
71
+ @cpool.hold {|conn| conn.must_equal :got_connection}
72
72
  end
73
73
 
74
- specify "a connection should be de-allocated after it has been used in #hold" do
74
+ it "a connection should be de-allocated after it has been used in #hold" do
75
75
  @cpool.hold {}
76
- @cpool.allocated.size.should == 0
76
+ @cpool.allocated.size.must_equal 0
77
77
  end
78
78
 
79
- specify "#hold should return the value of its block" do
80
- @cpool.hold {:block_return}.should == :block_return
79
+ it "#hold should return the value of its block" do
80
+ @cpool.hold {:block_return}.must_equal :block_return
81
81
  end
82
82
 
83
83
  if RUBY_VERSION < '1.9.0' and !defined?(RUBY_ENGINE)
84
- specify "#hold should remove dead threads from the pool if it reaches its max_size" do
84
+ it "#hold should remove dead threads from the pool if it reaches its max_size" do
85
85
  Thread.new{@cpool.hold{Thread.current.exit!}}.join
86
- @cpool.allocated.keys.map{|t| t.alive?}.should == [false]
86
+ @cpool.allocated.keys.map{|t| t.alive?}.must_equal [false]
87
87
 
88
88
  Thread.new{@cpool.hold{Thread.current.exit!}}.join
89
- @cpool.allocated.keys.map{|t| t.alive?}.should == [false, false]
89
+ @cpool.allocated.keys.map{|t| t.alive?}.must_equal [false, false]
90
90
 
91
91
  Thread.new{@cpool.hold{}}.join
92
- @cpool.allocated.should == {}
92
+ @cpool.allocated.must_equal({})
93
93
  end
94
94
  end
95
95
 
96
- specify "#make_new should not make more than max_size connections" do
96
+ it "#make_new should not make more than max_size connections" do
97
97
  q = Queue.new
98
98
  50.times{Thread.new{@cpool.hold{q.pop}}}
99
99
  50.times{q.push nil}
100
- @cpool.created_count.should <= @max_size
100
+ @cpool.created_count.must_be :<=, @max_size
101
101
  end
102
102
 
103
- specify "database's disconnect connection method should be called when a disconnect is detected" do
104
- @max_size.should == 2
105
- proc{@cpool.hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::DatabaseDisconnectError)
106
- @max_size.should == 3
103
+ it "database's disconnect connection method should be called when a disconnect is detected" do
104
+ @max_size.must_equal 2
105
+ proc{@cpool.hold{raise Sequel::DatabaseDisconnectError}}.must_raise(Sequel::DatabaseDisconnectError)
106
+ @max_size.must_equal 3
107
107
  end
108
108
 
109
- specify "#hold should remove the connection if a DatabaseDisconnectError is raised" do
110
- @cpool.created_count.should == 0
109
+ it "#hold should remove the connection if a DatabaseDisconnectError is raised" do
110
+ @cpool.created_count.must_equal 0
111
111
  q, q1 = Queue.new, Queue.new
112
112
  @cpool.hold{Thread.new{@cpool.hold{q1.pop; q.push nil}; q1.pop; q.push nil}; q1.push nil; q.pop; q1.push nil; q.pop}
113
- @cpool.created_count.should == 2
114
- proc{@cpool.hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::DatabaseDisconnectError)
115
- @cpool.created_count.should == 1
116
- proc{@cpool.hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::DatabaseDisconnectError)
117
- @cpool.created_count.should == 0
118
- proc{@cpool.hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::DatabaseDisconnectError)
119
- @cpool.created_count.should == 0
113
+ @cpool.created_count.must_equal 2
114
+ proc{@cpool.hold{raise Sequel::DatabaseDisconnectError}}.must_raise(Sequel::DatabaseDisconnectError)
115
+ @cpool.created_count.must_equal 1
116
+ proc{@cpool.hold{raise Sequel::DatabaseDisconnectError}}.must_raise(Sequel::DatabaseDisconnectError)
117
+ @cpool.created_count.must_equal 0
118
+ proc{@cpool.hold{raise Sequel::DatabaseDisconnectError}}.must_raise(Sequel::DatabaseDisconnectError)
119
+ @cpool.created_count.must_equal 0
120
120
  end
121
121
  end
122
122
 
123
123
  describe "A connection pool handling connection errors" do
124
- specify "#hold should raise a Sequel::DatabaseConnectionError if an exception is raised by the connection_proc" do
124
+ it "#hold should raise a Sequel::DatabaseConnectionError if an exception is raised by the connection_proc" do
125
125
  cpool = Sequel::ConnectionPool.get_pool(CONNECTION_POOL_DEFAULTS){raise Interrupt}
126
- proc{cpool.hold{:block_return}}.should raise_error(Sequel::DatabaseConnectionError)
127
- cpool.created_count.should == 0
126
+ proc{cpool.hold{:block_return}}.must_raise(Sequel::DatabaseConnectionError)
127
+ cpool.created_count.must_equal 0
128
128
  end
129
129
 
130
- specify "#hold should raise a Sequel::DatabaseConnectionError if nil is returned by the connection_proc" do
130
+ it "#hold should raise a Sequel::DatabaseConnectionError if nil is returned by the connection_proc" do
131
131
  cpool = Sequel::ConnectionPool.get_pool(CONNECTION_POOL_DEFAULTS){nil}
132
- proc{cpool.hold{:block_return}}.should raise_error(Sequel::DatabaseConnectionError)
133
- cpool.created_count.should == 0
132
+ proc{cpool.hold{:block_return}}.must_raise(Sequel::DatabaseConnectionError)
133
+ cpool.created_count.must_equal 0
134
134
  end
135
135
  end
136
136
 
@@ -144,24 +144,24 @@ describe "ConnectionPool#hold" do
144
144
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call{c.new}, CONNECTION_POOL_DEFAULTS)
145
145
  end
146
146
 
147
- specify "shoulda use the database's connect method to get new connections" do
147
+ it "shoulda use the database's connect method to get new connections" do
148
148
  res = nil
149
149
  @pool.hold {|c| res = c}
150
- res.should be_a_kind_of(@c)
151
- res.value.should == 1
150
+ res.must_be_kind_of(@c)
151
+ res.value.must_equal 1
152
152
  @pool.hold {|c| res = c}
153
- res.should be_a_kind_of(@c)
154
- res.value.should == 1 # the connection maker is invoked only once
153
+ res.must_be_kind_of(@c)
154
+ res.value.must_equal 1 # the connection maker is invoked only once
155
155
  end
156
156
 
157
- specify "should be re-entrant by the same thread" do
157
+ it "should be re-entrant by the same thread" do
158
158
  cc = nil
159
159
  @pool.hold {|c| @pool.hold {|c1| @pool.hold {|c2| cc = c2}}}
160
- cc.should be_a_kind_of(@c)
160
+ cc.must_be_kind_of(@c)
161
161
  end
162
162
 
163
- specify "should catch exceptions and reraise them" do
164
- proc {@pool.hold {|c| c.foobar}}.should raise_error(NoMethodError)
163
+ it "should catch exceptions and reraise them" do
164
+ proc {@pool.hold {|c| c.foobar}}.must_raise(NoMethodError)
165
165
  end
166
166
  end
167
167
 
@@ -172,51 +172,51 @@ describe "A connection pool with a max size of 1" do
172
172
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call{icp.call; 'herro'}, CONNECTION_POOL_DEFAULTS.merge(:max_connections=>1))
173
173
  end
174
174
 
175
- specify "should let only one thread access the connection at any time" do
175
+ it "should let only one thread access the connection at any time" do
176
176
  cc,c1, c2 = nil
177
177
  q, q1 = Queue.new, Queue.new
178
178
 
179
179
  t1 = Thread.new {@pool.hold {|c| cc = c; c1 = c.dup; q1.push nil; q.pop}}
180
180
  q1.pop
181
- cc.should == 'herro'
182
- c1.should == 'herro'
181
+ cc.must_equal 'herro'
182
+ c1.must_equal 'herro'
183
183
 
184
184
  t2 = Thread.new {@pool.hold {|c| c2 = c.dup; q1.push nil; q.pop;}}
185
185
 
186
186
  # connection held by t1
187
- t1.should be_alive
188
- t2.should be_alive
187
+ t1.must_be :alive?
188
+ t2.must_be :alive?
189
189
 
190
- cc.should == 'herro'
191
- c1.should == 'herro'
192
- c2.should be_nil
190
+ cc.must_equal 'herro'
191
+ c1.must_equal 'herro'
192
+ c2.must_equal nil
193
193
 
194
- @pool.available_connections.should be_empty
195
- @pool.allocated.should == {t1=>cc}
194
+ @pool.available_connections.must_be :empty?
195
+ @pool.allocated.must_equal(t1=>cc)
196
196
 
197
197
  cc.gsub!('rr', 'll')
198
198
  q.push nil
199
199
  q1.pop
200
200
 
201
201
  t1.join
202
- t2.should be_alive
202
+ t2.must_be :alive?
203
203
 
204
- c2.should == 'hello'
204
+ c2.must_equal 'hello'
205
205
 
206
- @pool.available_connections.should be_empty
207
- @pool.allocated.should == {t2=>cc}
206
+ @pool.available_connections.must_be :empty?
207
+ @pool.allocated.must_equal(t2=>cc)
208
208
 
209
209
  #connection released
210
210
  q.push nil
211
211
  t2.join
212
212
 
213
- @invoked_count.should == 1
214
- @pool.size.should == 1
215
- @pool.available_connections.should == [cc]
216
- @pool.allocated.should be_empty
213
+ @invoked_count.must_equal 1
214
+ @pool.size.must_equal 1
215
+ @pool.available_connections.must_equal [cc]
216
+ @pool.allocated.must_be :empty?
217
217
  end
218
218
 
219
- specify "should let the same thread reenter #hold" do
219
+ it "should let the same thread reenter #hold" do
220
220
  c1, c2, c3 = nil
221
221
  @pool.hold do |c|
222
222
  c1 = c
@@ -227,19 +227,19 @@ describe "A connection pool with a max size of 1" do
227
227
  end
228
228
  end
229
229
  end
230
- c1.should == 'herro'
231
- c2.should == 'herro'
232
- c3.should == 'herro'
230
+ c1.must_equal 'herro'
231
+ c2.must_equal 'herro'
232
+ c3.must_equal 'herro'
233
233
 
234
- @invoked_count.should == 1
235
- @pool.size.should == 1
236
- @pool.available_connections.size.should == 1
237
- @pool.allocated.should be_empty
234
+ @invoked_count.must_equal 1
235
+ @pool.size.must_equal 1
236
+ @pool.available_connections.size.must_equal 1
237
+ @pool.allocated.must_be :empty?
238
238
  end
239
239
  end
240
240
 
241
- shared_examples_for "A threaded connection pool" do
242
- specify "should not have all_connections yield connections allocated to other threads" do
241
+ ThreadedConnectionPoolSpecs = shared_description do
242
+ it "should not have all_connections yield connections allocated to other threads" do
243
243
  pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:max_connections=>2, :pool_timeout=>0))
244
244
  q, q1 = Queue.new, Queue.new
245
245
  t = Thread.new do
@@ -250,13 +250,13 @@ shared_examples_for "A threaded connection pool" do
250
250
  end
251
251
  pool.hold do |c1|
252
252
  q1.pop
253
- pool.all_connections{|c| c.should == c1}
253
+ pool.all_connections{|c| c.must_equal c1}
254
254
  q.push nil
255
255
  end
256
256
  t.join
257
257
  end
258
258
 
259
- specify "should wait until a connection is available if all are checked out" do
259
+ it "should wait until a connection is available if all are checked out" do
260
260
  pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:max_connections=>1, :pool_timeout=>0.1, :pool_sleep_time=>0))
261
261
  q, q1 = Queue.new, Queue.new
262
262
  t = Thread.new do
@@ -267,12 +267,12 @@ shared_examples_for "A threaded connection pool" do
267
267
  end
268
268
  end
269
269
  q1.pop
270
- proc{pool.hold{}}.should raise_error(Sequel::PoolTimeout)
270
+ proc{pool.hold{}}.must_raise(Sequel::PoolTimeout)
271
271
  q.push nil
272
272
  t.join
273
273
  end
274
274
 
275
- specify "should not have all_connections yield all available connections" do
275
+ it "should not have all_connections yield all available connections" do
276
276
  pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:max_connections=>2, :pool_timeout=>0))
277
277
  q, q1 = Queue.new, Queue.new
278
278
  b = []
@@ -291,128 +291,128 @@ shared_examples_for "A threaded connection pool" do
291
291
  t.join
292
292
  a = []
293
293
  pool.all_connections{|c| a << c}
294
- a.sort.should == b.sort
294
+ a.sort.must_equal b.sort
295
295
  end
296
296
 
297
- specify "should raise a PoolTimeout error if a connection couldn't be acquired before timeout" do
297
+ it "should raise a PoolTimeout error if a connection couldn't be acquired before timeout" do
298
298
  q, q1 = Queue.new, Queue.new
299
299
  pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:max_connections=>1, :pool_timeout=>0))
300
300
  t = Thread.new{pool.hold{|c| q1.push nil; q.pop}}
301
301
  q1.pop
302
- proc{pool.hold{|c|}}.should raise_error(Sequel::PoolTimeout)
302
+ proc{pool.hold{|c|}}.must_raise(Sequel::PoolTimeout)
303
303
  q.push nil
304
304
  t.join
305
305
  end
306
306
 
307
307
  it "should not add a disconnected connection back to the pool if the disconnection_proc raises an error" do
308
308
  pool = Sequel::ConnectionPool.get_pool(mock_db.call(proc{|c| raise Sequel::Error}, &@icpp), @cp_opts.merge(:max_connections=>1, :pool_timeout=>0))
309
- proc{pool.hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::Error)
310
- pool.available_connections.length.should == 0
309
+ proc{pool.hold{raise Sequel::DatabaseDisconnectError}}.must_raise(Sequel::Error)
310
+ pool.available_connections.length.must_equal 0
311
311
  end
312
312
 
313
- specify "should let five threads simultaneously access separate connections" do
313
+ it "should let five threads simultaneously access separate connections" do
314
314
  cc = {}
315
315
  threads = []
316
316
  q, q1, q2 = Queue.new, Queue.new, Queue.new
317
317
 
318
318
  5.times{|i| threads << Thread.new{@pool.hold{|c| q.pop; cc[i] = c; q1.push nil; q2.pop}}; q.push nil; q1.pop}
319
- threads.each {|t| t.should be_alive}
320
- cc.size.should == 5
321
- @invoked_count.should == 5
322
- @pool.size.should == 5
323
- @pool.available_connections.should be_empty
319
+ threads.each {|t| t.must_be :alive?}
320
+ cc.size.must_equal 5
321
+ @invoked_count.must_equal 5
322
+ @pool.size.must_equal 5
323
+ @pool.available_connections.must_be :empty?
324
324
 
325
325
  h = {}
326
326
  i = 0
327
327
  threads.each{|t| h[t] = (i+=1)}
328
- @pool.allocated.should == h
329
- @pool.available_connections.should == []
328
+ @pool.allocated.must_equal h
329
+ @pool.available_connections.must_equal []
330
330
  5.times{q2.push nil}
331
331
  threads.each{|t| t.join}
332
332
 
333
- @pool.available_connections.size.should == 5
334
- @pool.allocated.should be_empty
333
+ @pool.available_connections.size.must_equal 5
334
+ @pool.allocated.must_be :empty?
335
335
  end
336
336
 
337
- specify "should block threads until a connection becomes available" do
337
+ it "should block threads until a connection becomes available" do
338
338
  cc = {}
339
339
  threads = []
340
340
  q, q1 = Queue.new, Queue.new
341
341
 
342
342
  5.times{|i| threads << Thread.new{@pool.hold{|c| cc[i] = c; q1.push nil; q.pop}}}
343
343
  5.times{q1.pop}
344
- threads.each {|t| t.should be_alive}
345
- @pool.available_connections.should be_empty
344
+ threads.each {|t| t.must_be :alive?}
345
+ @pool.available_connections.must_be :empty?
346
346
 
347
347
  3.times {|i| threads << Thread.new {@pool.hold {|c| cc[i + 5] = c; q1.push nil}}}
348
348
 
349
- threads[5].should be_alive
350
- threads[6].should be_alive
351
- threads[7].should be_alive
352
- cc.size.should == 5
353
- cc[5].should be_nil
354
- cc[6].should be_nil
355
- cc[7].should be_nil
349
+ threads[5].must_be :alive?
350
+ threads[6].must_be :alive?
351
+ threads[7].must_be :alive?
352
+ cc.size.must_equal 5
353
+ cc[5].must_equal nil
354
+ cc[6].must_equal nil
355
+ cc[7].must_equal nil
356
356
 
357
357
  5.times{q.push nil}
358
358
  5.times{|i| threads[i].join}
359
359
  3.times{q1.pop}
360
360
  3.times{|i| threads[i+5].join}
361
361
 
362
- threads.each {|t| t.should_not be_alive}
362
+ threads.each {|t| t.wont_be :alive?}
363
363
 
364
- @pool.size.should == 5
365
- @invoked_count.should == 5
366
- @pool.available_connections.size.should == 5
367
- @pool.allocated.should be_empty
364
+ @pool.size.must_equal 5
365
+ @invoked_count.must_equal 5
366
+ @pool.available_connections.size.must_equal 5
367
+ @pool.allocated.must_be :empty?
368
368
  end
369
369
 
370
- specify "should store connections in a stack if :connection_handling=>:stack" do
370
+ it "should store connections in a stack if :connection_handling=>:stack" do
371
371
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:connection_handling=>:stack))
372
372
  c2 = nil
373
373
  c = @pool.hold{|cc| Thread.new{@pool.hold{|cc2| c2 = cc2}}.join; cc}
374
- @pool.size.should == 2
375
- @pool.hold{|cc| cc.should == c}
376
- @pool.hold{|cc| cc.should == c}
374
+ @pool.size.must_equal 2
375
+ @pool.hold{|cc| cc.must_equal c}
376
+ @pool.hold{|cc| cc.must_equal c}
377
377
  @pool.hold do |cc|
378
- cc.should == c
379
- Thread.new{@pool.hold{|cc2| cc2.should == c2}}
378
+ cc.must_equal c
379
+ Thread.new{@pool.hold{|cc2| cc2.must_equal c2}}
380
380
  end
381
381
  end
382
382
 
383
- specify "should store connections in a queue if :connection_handling=>:queue" do
383
+ it "should store connections in a queue if :connection_handling=>:queue" do
384
384
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:connection_handling=>:queue))
385
385
  c2 = nil
386
386
  c = @pool.hold{|cc| Thread.new{@pool.hold{|cc2| c2 = cc2}}.join; cc}
387
- @pool.size.should == 2
388
- @pool.hold{|cc| cc.should == c2}
389
- @pool.hold{|cc| cc.should == c}
387
+ @pool.size.must_equal 2
388
+ @pool.hold{|cc| cc.must_equal c2}
389
+ @pool.hold{|cc| cc.must_equal c}
390
390
  @pool.hold do |cc|
391
- cc.should == c2
392
- Thread.new{@pool.hold{|cc2| cc2.should == c}}
391
+ cc.must_equal c2
392
+ Thread.new{@pool.hold{|cc2| cc2.must_equal c}}
393
393
  end
394
394
  end
395
395
 
396
- specify "should not store connections if :connection_handling=>:disconnect" do
396
+ it "should not store connections if :connection_handling=>:disconnect" do
397
397
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts.merge(:connection_handling=>:disconnect))
398
398
  d = []
399
399
  meta_def(@pool.db, :disconnect_connection){|c| d << c}
400
400
  @pool.hold do |cc|
401
- cc.should == 1
402
- Thread.new{@pool.hold{|cc2| cc2.should == 2}}.join
403
- d.should == [2]
404
- @pool.hold{|cc3| cc3.should == 1}
401
+ cc.must_equal 1
402
+ Thread.new{@pool.hold{|cc2| _(cc2).must_equal 2}}.join
403
+ d.must_equal [2]
404
+ @pool.hold{|cc3| cc3.must_equal 1}
405
405
  end
406
- @pool.size.should == 0
407
- d.should == [2, 1]
406
+ @pool.size.must_equal 0
407
+ d.must_equal [2, 1]
408
408
 
409
- @pool.hold{|cc| cc.should == 3}
410
- @pool.size.should == 0
411
- d.should == [2, 1, 3]
409
+ @pool.hold{|cc| cc.must_equal 3}
410
+ @pool.size.must_equal 0
411
+ d.must_equal [2, 1, 3]
412
412
 
413
- @pool.hold{|cc| cc.should == 4}
414
- @pool.size.should == 0
415
- d.should == [2, 1, 3, 4]
413
+ @pool.hold{|cc| cc.must_equal 4}
414
+ @pool.size.must_equal 0
415
+ d.must_equal [2, 1, 3, 4]
416
416
  end
417
417
  end
418
418
 
@@ -424,7 +424,7 @@ describe "Threaded Unsharded Connection Pool" do
424
424
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts)
425
425
  end
426
426
 
427
- it_should_behave_like "A threaded connection pool"
427
+ include ThreadedConnectionPoolSpecs
428
428
  end
429
429
 
430
430
  describe "Threaded Sharded Connection Pool" do
@@ -435,7 +435,7 @@ describe "Threaded Sharded Connection Pool" do
435
435
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call(&@icpp), @cp_opts)
436
436
  end
437
437
 
438
- it_should_behave_like "A threaded connection pool"
438
+ include ThreadedConnectionPoolSpecs
439
439
  end
440
440
 
441
441
  describe "ConnectionPool#disconnect" do
@@ -451,34 +451,34 @@ describe "ConnectionPool#disconnect" do
451
451
  threads.each {|t| t.join}
452
452
  end
453
453
 
454
- specify "should invoke the given block for each available connection" do
455
- @pool.size.should == 5
456
- @pool.available_connections.size.should == 5
457
- @pool.available_connections.each {|c| c[:id].should_not be_nil}
454
+ it "should invoke the given block for each available connection" do
455
+ @pool.size.must_equal 5
456
+ @pool.available_connections.size.must_equal 5
457
+ @pool.available_connections.each {|c| c[:id].wont_equal nil}
458
458
  conns = []
459
459
  meta_def(@pool.db, :disconnect_connection){|c| conns << c}
460
460
  @pool.disconnect
461
- conns.size.should == 5
461
+ conns.size.must_equal 5
462
462
  end
463
463
 
464
- specify "should remove all available connections" do
465
- @pool.size.should == 5
464
+ it "should remove all available connections" do
465
+ @pool.size.must_equal 5
466
466
  @pool.disconnect
467
- @pool.size.should == 0
467
+ @pool.size.must_equal 0
468
468
  end
469
469
 
470
- specify "should disconnect connections in use as soon as they are no longer in use" do
471
- @pool.size.should == 5
470
+ it "should disconnect connections in use as soon as they are no longer in use" do
471
+ @pool.size.must_equal 5
472
472
  @pool.hold do |conn|
473
- @pool.available_connections.size.should == 4
474
- @pool.available_connections.each {|c| c.should_not be(conn)}
473
+ @pool.available_connections.size.must_equal 4
474
+ @pool.available_connections.each {|c| c.wont_be_same_as(conn)}
475
475
  conns = []
476
476
  meta_def(@pool.db, :disconnect_connection){|c| conns << c}
477
477
  @pool.disconnect
478
- conns.size.should == 4
479
- @pool.size.should == 1
478
+ conns.size.must_equal 4
479
+ @pool.size.must_equal 1
480
480
  end
481
- @pool.size.should == 0
481
+ @pool.size.must_equal 0
482
482
  end
483
483
  end
484
484
 
@@ -488,187 +488,187 @@ describe "A connection pool with multiple servers" do
488
488
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call{|server| "#{server}#{ic[server] += 1}"}, CONNECTION_POOL_DEFAULTS.merge(:servers=>{:read_only=>{}}))
489
489
  end
490
490
 
491
- specify "should support preconnect method that immediately creates the maximum number of connections" do
491
+ it "should support preconnect method that immediately creates the maximum number of connections" do
492
492
  @pool.send(:preconnect)
493
493
  i = 0
494
494
  @pool.all_connections{|c1| i+=1}
495
- i.should == @pool.max_size * 2
495
+ i.must_equal @pool.max_size * 2
496
496
  end
497
497
 
498
- specify "#all_connections should return connections for all servers" do
498
+ it "#all_connections should return connections for all servers" do
499
499
  @pool.hold{}
500
- @pool.all_connections{|c1| c1.should == "default1"}
500
+ @pool.all_connections{|c1| c1.must_equal "default1"}
501
501
  a = []
502
502
  @pool.hold(:read_only) do |c|
503
503
  @pool.all_connections{|c1| a << c1}
504
504
  end
505
- a.sort_by{|c| c.to_s}.should == ["default1", "read_only1"]
505
+ a.sort_by{|c| c.to_s}.must_equal ["default1", "read_only1"]
506
506
  end
507
507
 
508
- specify "#servers should return symbols for all servers" do
509
- @pool.servers.sort_by{|s| s.to_s}.should == [:default, :read_only]
508
+ it "#servers should return symbols for all servers" do
509
+ @pool.servers.sort_by{|s| s.to_s}.must_equal [:default, :read_only]
510
510
  end
511
511
 
512
- specify "should use the :default server by default" do
513
- @pool.size.should == 0
512
+ it "should use the :default server by default" do
513
+ @pool.size.must_equal 0
514
514
  @pool.hold do |c|
515
- c.should == "default1"
516
- @pool.allocated.should == {Thread.current=>"default1"}
515
+ c.must_equal "default1"
516
+ @pool.allocated.must_equal(Thread.current=>"default1")
517
517
  end
518
- @pool.available_connections.should == ["default1"]
519
- @pool.size.should == 1
520
- @invoked_counts.should == {:default=>1}
518
+ @pool.available_connections.must_equal ["default1"]
519
+ @pool.size.must_equal 1
520
+ @invoked_counts.must_equal(:default=>1)
521
521
  end
522
522
 
523
- specify "should use the :default server an invalid server is used" do
523
+ it "should use the :default server an invalid server is used" do
524
524
  @pool.hold do |c1|
525
- c1.should == "default1"
525
+ c1.must_equal "default1"
526
526
  @pool.hold(:blah) do |c2|
527
- c2.should == c1
527
+ c2.must_equal c1
528
528
  @pool.hold(:blah2) do |c3|
529
- c2.should == c3
529
+ c2.must_equal c3
530
530
  end
531
531
  end
532
532
  end
533
533
  end
534
534
 
535
- specify "should support a :servers_hash option used for converting the server argument" do
535
+ it "should support a :servers_hash option used for converting the server argument" do
536
536
  ic = @invoked_counts
537
537
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call{|server| "#{server}#{ic[server] += 1}"}, CONNECTION_POOL_DEFAULTS.merge(:servers_hash=>Hash.new(:read_only), :servers=>{:read_only=>{}}))
538
538
  @pool.hold(:blah) do |c1|
539
- c1.should == "read_only1"
539
+ c1.must_equal "read_only1"
540
540
  @pool.hold(:blah) do |c2|
541
- c2.should == c1
541
+ c2.must_equal c1
542
542
  @pool.hold(:blah2) do |c3|
543
- c2.should == c3
543
+ c2.must_equal c3
544
544
  end
545
545
  end
546
546
  end
547
547
 
548
548
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call{|server| "#{server}#{ic[server] += 1}"}, CONNECTION_POOL_DEFAULTS.merge(:servers_hash=>Hash.new{|h,k| raise Sequel::Error}, :servers=>{:read_only=>{}}))
549
- proc{@pool.hold(:blah){|c1|}}.should raise_error(Sequel::Error)
549
+ proc{@pool.hold(:blah){|c1|}}.must_raise(Sequel::Error)
550
550
  end
551
551
 
552
- specify "should use the requested server if server is given" do
553
- @pool.size(:read_only).should == 0
552
+ it "should use the requested server if server is given" do
553
+ @pool.size(:read_only).must_equal 0
554
554
  @pool.hold(:read_only) do |c|
555
- c.should == "read_only1"
556
- @pool.allocated(:read_only).should == {Thread.current=>"read_only1"}
555
+ c.must_equal "read_only1"
556
+ @pool.allocated(:read_only).must_equal(Thread.current=>"read_only1")
557
557
  end
558
- @pool.available_connections(:read_only).should == ["read_only1"]
559
- @pool.size(:read_only).should == 1
560
- @invoked_counts.should == {:read_only=>1}
558
+ @pool.available_connections(:read_only).must_equal ["read_only1"]
559
+ @pool.size(:read_only).must_equal 1
560
+ @invoked_counts.must_equal(:read_only=>1)
561
561
  end
562
562
 
563
- specify "#hold should only yield connections for the server requested" do
563
+ it "#hold should only yield connections for the server requested" do
564
564
  @pool.hold(:read_only) do |c|
565
- c.should == "read_only1"
566
- @pool.allocated(:read_only).should == {Thread.current=>"read_only1"}
565
+ c.must_equal "read_only1"
566
+ @pool.allocated(:read_only).must_equal(Thread.current=>"read_only1")
567
567
  @pool.hold do |d|
568
- d.should == "default1"
568
+ d.must_equal "default1"
569
569
  @pool.hold do |e|
570
- e.should == d
571
- @pool.hold(:read_only){|b| b.should == c}
570
+ e.must_equal d
571
+ @pool.hold(:read_only){|b| b.must_equal c}
572
572
  end
573
- @pool.allocated.should == {Thread.current=>"default1"}
573
+ @pool.allocated.must_equal(Thread.current=>"default1")
574
574
  end
575
575
  end
576
- @invoked_counts.should == {:read_only=>1, :default=>1}
576
+ @invoked_counts.must_equal(:read_only=>1, :default=>1)
577
577
  end
578
578
 
579
- specify "#disconnect should disconnect from all servers" do
579
+ it "#disconnect should disconnect from all servers" do
580
580
  @pool.hold(:read_only){}
581
581
  @pool.hold{}
582
582
  conns = []
583
- @pool.size.should == 1
584
- @pool.size(:read_only).should == 1
583
+ @pool.size.must_equal 1
584
+ @pool.size(:read_only).must_equal 1
585
585
  meta_def(@pool.db, :disconnect_connection){|c| conns << c}
586
586
  @pool.disconnect
587
- conns.sort.should == %w'default1 read_only1'
588
- @pool.size.should == 0
589
- @pool.size(:read_only).should == 0
590
- @pool.hold(:read_only){|c| c.should == 'read_only2'}
591
- @pool.hold{|c| c.should == 'default2'}
587
+ conns.sort.must_equal %w'default1 read_only1'
588
+ @pool.size.must_equal 0
589
+ @pool.size(:read_only).must_equal 0
590
+ @pool.hold(:read_only){|c| c.must_equal 'read_only2'}
591
+ @pool.hold{|c| c.must_equal 'default2'}
592
592
  end
593
593
 
594
- specify "#add_servers should add new servers to the pool" do
594
+ it "#add_servers should add new servers to the pool" do
595
595
  pool = Sequel::ConnectionPool.get_pool(mock_db.call{|s| s}, :servers=>{:server1=>{}})
596
596
 
597
597
  pool.hold{}
598
598
  pool.hold(:server2){}
599
599
  pool.hold(:server3){}
600
600
  pool.hold(:server1) do
601
- pool.allocated.length.should == 0
602
- pool.allocated(:server1).length.should == 1
603
- pool.allocated(:server2).should == nil
604
- pool.allocated(:server3).should == nil
605
- pool.available_connections.length.should == 1
606
- pool.available_connections(:server1).length.should == 0
607
- pool.available_connections(:server2).should == nil
608
- pool.available_connections(:server3).should == nil
601
+ pool.allocated.length.must_equal 0
602
+ pool.allocated(:server1).length.must_equal 1
603
+ pool.allocated(:server2).must_equal nil
604
+ pool.allocated(:server3).must_equal nil
605
+ pool.available_connections.length.must_equal 1
606
+ pool.available_connections(:server1).length.must_equal 0
607
+ pool.available_connections(:server2).must_equal nil
608
+ pool.available_connections(:server3).must_equal nil
609
609
 
610
610
  pool.add_servers([:server2, :server3])
611
611
  pool.hold(:server2){}
612
612
  pool.hold(:server3) do
613
- pool.allocated.length.should == 0
614
- pool.allocated(:server1).length.should == 1
615
- pool.allocated(:server2).length.should == 0
616
- pool.allocated(:server3).length.should == 1
617
- pool.available_connections.length.should == 1
618
- pool.available_connections(:server1).length.should == 0
619
- pool.available_connections(:server2).length.should == 1
620
- pool.available_connections(:server3).length.should == 0
613
+ pool.allocated.length.must_equal 0
614
+ pool.allocated(:server1).length.must_equal 1
615
+ pool.allocated(:server2).length.must_equal 0
616
+ pool.allocated(:server3).length.must_equal 1
617
+ pool.available_connections.length.must_equal 1
618
+ pool.available_connections(:server1).length.must_equal 0
619
+ pool.available_connections(:server2).length.must_equal 1
620
+ pool.available_connections(:server3).length.must_equal 0
621
621
  end
622
622
  end
623
623
  end
624
624
 
625
- specify "#add_servers should ignore existing keys" do
625
+ it "#add_servers should ignore existing keys" do
626
626
  pool = Sequel::ConnectionPool.get_pool(mock_db.call{|s| s}, :servers=>{:server1=>{}})
627
627
 
628
- pool.allocated.length.should == 0
629
- pool.allocated(:server1).length.should == 0
630
- pool.available_connections.length.should == 0
631
- pool.available_connections(:server1).length.should == 0
628
+ pool.allocated.length.must_equal 0
629
+ pool.allocated(:server1).length.must_equal 0
630
+ pool.available_connections.length.must_equal 0
631
+ pool.available_connections(:server1).length.must_equal 0
632
632
  pool.hold do |c1|
633
- c1.should == :default
634
- pool.allocated.length.should == 1
635
- pool.allocated(:server1).length.should == 0
636
- pool.available_connections.length.should == 0
637
- pool.available_connections(:server1).length.should == 0
633
+ c1.must_equal :default
634
+ pool.allocated.length.must_equal 1
635
+ pool.allocated(:server1).length.must_equal 0
636
+ pool.available_connections.length.must_equal 0
637
+ pool.available_connections(:server1).length.must_equal 0
638
638
  pool.hold(:server1) do |c2|
639
- c2.should == :server1
640
- pool.allocated.length.should == 1
641
- pool.allocated(:server1).length.should == 1
642
- pool.available_connections.length.should == 0
643
- pool.available_connections(:server1).length.should == 0
639
+ c2.must_equal :server1
640
+ pool.allocated.length.must_equal 1
641
+ pool.allocated(:server1).length.must_equal 1
642
+ pool.available_connections.length.must_equal 0
643
+ pool.available_connections(:server1).length.must_equal 0
644
644
  pool.add_servers([:default, :server1])
645
- pool.allocated.length.should == 1
646
- pool.allocated(:server1).length.should == 1
647
- pool.available_connections.length.should == 0
648
- pool.available_connections(:server1).length.should == 0
645
+ pool.allocated.length.must_equal 1
646
+ pool.allocated(:server1).length.must_equal 1
647
+ pool.available_connections.length.must_equal 0
648
+ pool.available_connections(:server1).length.must_equal 0
649
649
  end
650
- pool.allocated.length.should == 1
651
- pool.allocated(:server1).length.should == 0
652
- pool.available_connections.length.should == 0
653
- pool.available_connections(:server1).length.should == 1
650
+ pool.allocated.length.must_equal 1
651
+ pool.allocated(:server1).length.must_equal 0
652
+ pool.available_connections.length.must_equal 0
653
+ pool.available_connections(:server1).length.must_equal 1
654
654
  pool.add_servers([:default, :server1])
655
- pool.allocated.length.should == 1
656
- pool.allocated(:server1).length.should == 0
657
- pool.available_connections.length.should == 0
658
- pool.available_connections(:server1).length.should == 1
655
+ pool.allocated.length.must_equal 1
656
+ pool.allocated(:server1).length.must_equal 0
657
+ pool.available_connections.length.must_equal 0
658
+ pool.available_connections(:server1).length.must_equal 1
659
659
  end
660
- pool.allocated.length.should == 0
661
- pool.allocated(:server1).length.should == 0
662
- pool.available_connections.length.should == 1
663
- pool.available_connections(:server1).length.should == 1
660
+ pool.allocated.length.must_equal 0
661
+ pool.allocated(:server1).length.must_equal 0
662
+ pool.available_connections.length.must_equal 1
663
+ pool.available_connections(:server1).length.must_equal 1
664
664
  pool.add_servers([:default, :server1])
665
- pool.allocated.length.should == 0
666
- pool.allocated(:server1).length.should == 0
667
- pool.available_connections.length.should == 1
668
- pool.available_connections(:server1).length.should == 1
665
+ pool.allocated.length.must_equal 0
666
+ pool.allocated(:server1).length.must_equal 0
667
+ pool.available_connections.length.must_equal 1
668
+ pool.available_connections(:server1).length.must_equal 1
669
669
  end
670
670
 
671
- specify "#remove_servers should disconnect available connections immediately" do
671
+ it "#remove_servers should disconnect available connections immediately" do
672
672
  pool = Sequel::ConnectionPool.get_pool(mock_db.call{|s| s}, :max_connections=>5, :servers=>{:server1=>{}})
673
673
  threads = []
674
674
  q, q1 = Queue.new, Queue.new
@@ -677,57 +677,57 @@ describe "A connection pool with multiple servers" do
677
677
  5.times{q.push nil}
678
678
  threads.each {|t| t.join}
679
679
 
680
- pool.size(:server1).should == 5
680
+ pool.size(:server1).must_equal 5
681
681
  pool.remove_servers([:server1])
682
- pool.size(:server1).should == 0
682
+ pool.size(:server1).must_equal 0
683
683
  end
684
684
 
685
- specify "#remove_servers should disconnect connections in use as soon as they are returned to the pool" do
685
+ it "#remove_servers should disconnect connections in use as soon as they are returned to the pool" do
686
686
  dc = []
687
687
  pool = Sequel::ConnectionPool.get_pool(mock_db.call(proc{|c| dc << c}){|c| c}, :servers=>{:server1=>{}})
688
688
  c1 = nil
689
689
  pool.hold(:server1) do |c|
690
- pool.size(:server1).should == 1
691
- dc.should == []
690
+ pool.size(:server1).must_equal 1
691
+ dc.must_equal []
692
692
  pool.remove_servers([:server1])
693
- pool.size(:server1).should == 0
694
- dc.should == []
693
+ pool.size(:server1).must_equal 0
694
+ dc.must_equal []
695
695
  c1 = c
696
696
  end
697
- pool.size(:server1).should == 0
698
- dc.should == [c1]
697
+ pool.size(:server1).must_equal 0
698
+ dc.must_equal [c1]
699
699
  end
700
700
 
701
- specify "#remove_servers should remove server related data structures immediately" do
701
+ it "#remove_servers should remove server related data structures immediately" do
702
702
  pool = Sequel::ConnectionPool.get_pool(mock_db.call{|s| s}, :servers=>{:server1=>{}})
703
- pool.available_connections(:server1).should == []
704
- pool.allocated(:server1).should == {}
703
+ pool.available_connections(:server1).must_equal []
704
+ pool.allocated(:server1).must_equal({})
705
705
  pool.remove_servers([:server1])
706
- pool.available_connections(:server1).should == nil
707
- pool.allocated(:server1).should == nil
706
+ pool.available_connections(:server1).must_equal nil
707
+ pool.allocated(:server1).must_equal nil
708
708
  end
709
709
 
710
- specify "#remove_servers should not allow the removal of the default server" do
710
+ it "#remove_servers should not allow the removal of the default server" do
711
711
  pool = Sequel::ConnectionPool.get_pool(mock_db.call{|s| s}, :servers=>{:server1=>{}})
712
- proc{pool.remove_servers([:server1])}.should_not raise_error
713
- proc{pool.remove_servers([:default])}.should raise_error(Sequel::Error)
712
+ pool.remove_servers([:server1])
713
+ proc{pool.remove_servers([:default])}.must_raise(Sequel::Error)
714
714
  end
715
715
 
716
- specify "#remove_servers should ignore servers that have already been removed" do
716
+ it "#remove_servers should ignore servers that have already been removed" do
717
717
  dc = []
718
718
  pool = Sequel::ConnectionPool.get_pool(mock_db.call(proc{|c| dc << c}){|c| c}, :servers=>{:server1=>{}})
719
719
  c1 = nil
720
720
  pool.hold(:server1) do |c|
721
- pool.size(:server1).should == 1
722
- dc.should == []
721
+ pool.size(:server1).must_equal 1
722
+ dc.must_equal []
723
723
  pool.remove_servers([:server1])
724
724
  pool.remove_servers([:server1])
725
- pool.size(:server1).should == 0
726
- dc.should == []
725
+ pool.size(:server1).must_equal 0
726
+ dc.must_equal []
727
727
  c1 = c
728
728
  end
729
- pool.size(:server1).should == 0
730
- dc.should == [c1]
729
+ pool.size(:server1).must_equal 0
730
+ dc.must_equal [c1]
731
731
  end
732
732
  end
733
733
 
@@ -738,20 +738,20 @@ describe "SingleConnectionPool" do
738
738
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call{1234}, ST_CONNECTION_POOL_DEFAULTS)
739
739
  end
740
740
 
741
- specify "should provide a #hold method" do
741
+ it "should provide a #hold method" do
742
742
  conn = nil
743
743
  @pool.hold{|c| conn = c}
744
- conn.should == 1234
744
+ conn.must_equal 1234
745
745
  end
746
746
 
747
- specify "should provide a #disconnect method" do
747
+ it "should provide a #disconnect method" do
748
748
  conn = nil
749
749
  x = nil
750
750
  pool = Sequel::ConnectionPool.get_pool(mock_db.call(proc{|c| conn = c}){1234}, ST_CONNECTION_POOL_DEFAULTS)
751
751
  pool.hold{|c| x = c}
752
- x.should == 1234
752
+ x.must_equal 1234
753
753
  pool.disconnect
754
- conn.should == 1234
754
+ conn.must_equal 1234
755
755
  end
756
756
  end
757
757
 
@@ -762,242 +762,242 @@ describe "A single threaded pool with multiple servers" do
762
762
  @pool = Sequel::ConnectionPool.get_pool(mock_db.call(proc{|c| msp.call}){|c| c}, ST_CONNECTION_POOL_DEFAULTS.merge(:servers=>{:read_only=>{}}))
763
763
  end
764
764
 
765
- specify "should support preconnect method that immediately creates the maximum number of connections" do
765
+ it "should support preconnect method that immediately creates the maximum number of connections" do
766
766
  @pool.send(:preconnect)
767
767
  i = 0
768
768
  @pool.all_connections{|c1| i+=1}
769
- i.should == 2
769
+ i.must_equal 2
770
770
  end
771
771
 
772
- specify "#all_connections should return connections for all servers" do
772
+ it "#all_connections should return connections for all servers" do
773
773
  @pool.hold{}
774
- @pool.all_connections{|c1| c1.should == :default}
774
+ @pool.all_connections{|c1| c1.must_equal :default}
775
775
  a = []
776
776
  @pool.hold(:read_only) do
777
777
  @pool.all_connections{|c1| a << c1}
778
778
  end
779
- a.sort_by{|c| c.to_s}.should == [:default, :read_only]
779
+ a.sort_by{|c| c.to_s}.must_equal [:default, :read_only]
780
780
  end
781
781
 
782
- specify "#servers should return symbols for all servers" do
783
- @pool.servers.sort_by{|s| s.to_s}.should == [:default, :read_only]
782
+ it "#servers should return symbols for all servers" do
783
+ @pool.servers.sort_by{|s| s.to_s}.must_equal [:default, :read_only]
784
784
  end
785
785
 
786
- specify "#add_servers should add new servers to the pool" do
787
- @pool.hold(:blah){|c| c.should == :default}
786
+ it "#add_servers should add new servers to the pool" do
787
+ @pool.hold(:blah){|c| c.must_equal :default}
788
788
  @pool.add_servers([:blah])
789
- @pool.hold(:blah){|c| c.should == :blah}
789
+ @pool.hold(:blah){|c| c.must_equal :blah}
790
790
  end
791
791
 
792
- specify "#add_servers should ignore keys already existing" do
793
- @pool.hold{|c| c.should == :default}
794
- @pool.hold(:read_only){|c| c.should == :read_only}
792
+ it "#add_servers should ignore keys already existing" do
793
+ @pool.hold{|c| c.must_equal :default}
794
+ @pool.hold(:read_only){|c| c.must_equal :read_only}
795
795
  @pool.add_servers([:default, :read_only])
796
- @pool.conn.should == :default
797
- @pool.conn(:read_only).should == :read_only
796
+ @pool.conn.must_equal :default
797
+ @pool.conn(:read_only).must_equal :read_only
798
798
  end
799
799
 
800
- specify "#remove_servers should remove servers from the pool" do
801
- @pool.hold(:read_only){|c| c.should == :read_only}
800
+ it "#remove_servers should remove servers from the pool" do
801
+ @pool.hold(:read_only){|c| c.must_equal :read_only}
802
802
  @pool.remove_servers([:read_only])
803
- @pool.hold(:read_only){|c| c.should == :default}
803
+ @pool.hold(:read_only){|c| c.must_equal :default}
804
804
  end
805
805
 
806
- specify "#remove_servers should not allow the removal of the default server" do
807
- proc{@pool.remove_servers([:default])}.should raise_error(Sequel::Error)
806
+ it "#remove_servers should not allow the removal of the default server" do
807
+ proc{@pool.remove_servers([:default])}.must_raise(Sequel::Error)
808
808
  end
809
809
 
810
- specify "#remove_servers should disconnect connection immediately" do
811
- @pool.hold(:read_only){|c| c.should == :read_only}
812
- @pool.conn(:read_only).should == :read_only
810
+ it "#remove_servers should disconnect connection immediately" do
811
+ @pool.hold(:read_only){|c| c.must_equal :read_only}
812
+ @pool.conn(:read_only).must_equal :read_only
813
813
  @pool.remove_servers([:read_only])
814
- @pool.conn(:read_only).should == nil
814
+ @pool.conn(:read_only).must_equal nil
815
815
  @pool.hold{}
816
- @pool.conn(:read_only).should == :default
816
+ @pool.conn(:read_only).must_equal :default
817
817
  end
818
818
 
819
- specify "#remove_servers should ignore keys that do not exist" do
820
- proc{@pool.remove_servers([:blah])}.should_not raise_error
819
+ it "#remove_servers should ignore keys that do not exist" do
820
+ @pool.remove_servers([:blah])
821
821
  end
822
822
 
823
- specify "should use the :default server by default" do
824
- @pool.hold{|c| c.should == :default}
825
- @pool.conn.should == :default
823
+ it "should use the :default server by default" do
824
+ @pool.hold{|c| c.must_equal :default}
825
+ @pool.conn.must_equal :default
826
826
  end
827
827
 
828
- specify "should use the :default server an invalid server is used" do
828
+ it "should use the :default server an invalid server is used" do
829
829
  @pool.hold do |c1|
830
- c1.should == :default
830
+ c1.must_equal :default
831
831
  @pool.hold(:blah) do |c2|
832
- c2.should == c1
832
+ c2.must_equal c1
833
833
  @pool.hold(:blah2) do |c3|
834
- c2.should == c3
834
+ c2.must_equal c3
835
835
  end
836
836
  end
837
837
  end
838
838
  end
839
839
 
840
- specify "should use the requested server if server is given" do
841
- @pool.hold(:read_only){|c| c.should == :read_only}
842
- @pool.conn(:read_only).should == :read_only
840
+ it "should use the requested server if server is given" do
841
+ @pool.hold(:read_only){|c| c.must_equal :read_only}
842
+ @pool.conn(:read_only).must_equal :read_only
843
843
  end
844
844
 
845
- specify "#hold should only yield connections for the server requested" do
845
+ it "#hold should only yield connections for the server requested" do
846
846
  @pool.hold(:read_only) do |c|
847
- c.should == :read_only
847
+ c.must_equal :read_only
848
848
  @pool.hold do |d|
849
- d.should == :default
849
+ d.must_equal :default
850
850
  @pool.hold do |e|
851
- e.should == d
852
- @pool.hold(:read_only){|b| b.should == c}
851
+ e.must_equal d
852
+ @pool.hold(:read_only){|b| b.must_equal c}
853
853
  end
854
854
  end
855
855
  end
856
- @pool.conn.should == :default
857
- @pool.conn(:read_only).should == :read_only
856
+ @pool.conn.must_equal :default
857
+ @pool.conn(:read_only).must_equal :read_only
858
858
  end
859
859
 
860
- specify "#disconnect should disconnect from all servers" do
860
+ it "#disconnect should disconnect from all servers" do
861
861
  @pool.hold(:read_only){}
862
862
  @pool.hold{}
863
- @pool.conn.should == :default
864
- @pool.conn(:read_only).should == :read_only
863
+ @pool.conn.must_equal :default
864
+ @pool.conn(:read_only).must_equal :read_only
865
865
  @pool.disconnect
866
- @max_size.should == 4
867
- @pool.conn.should == nil
868
- @pool.conn(:read_only).should == nil
866
+ @max_size.must_equal 4
867
+ @pool.conn.must_equal nil
868
+ @pool.conn(:read_only).must_equal nil
869
869
  end
870
870
 
871
- specify ":disconnection_proc option should set the disconnection proc to use" do
872
- @max_size.should == 2
873
- proc{@pool.hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::DatabaseDisconnectError)
874
- @max_size.should == 3
871
+ it ":disconnection_proc option should set the disconnection proc to use" do
872
+ @max_size.must_equal 2
873
+ proc{@pool.hold{raise Sequel::DatabaseDisconnectError}}.must_raise(Sequel::DatabaseDisconnectError)
874
+ @max_size.must_equal 3
875
875
  end
876
876
 
877
- specify "#hold should remove the connection if a DatabaseDisconnectError is raised" do
878
- @pool.instance_variable_get(:@conns).length.should == 0
877
+ it "#hold should remove the connection if a DatabaseDisconnectError is raised" do
878
+ @pool.instance_variable_get(:@conns).length.must_equal 0
879
879
  @pool.hold{}
880
- @pool.instance_variable_get(:@conns).length.should == 1
881
- proc{@pool.hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::DatabaseDisconnectError)
882
- @pool.instance_variable_get(:@conns).length.should == 0
880
+ @pool.instance_variable_get(:@conns).length.must_equal 1
881
+ proc{@pool.hold{raise Sequel::DatabaseDisconnectError}}.must_raise(Sequel::DatabaseDisconnectError)
882
+ @pool.instance_variable_get(:@conns).length.must_equal 0
883
883
  end
884
884
  end
885
885
 
886
- shared_examples_for "All connection pools classes" do
887
- specify "should have pool_type return a symbol" do
888
- @class.new(mock_db.call{123}, {}).pool_type.should be_a_kind_of(Symbol)
886
+ AllConnectionPoolClassesSpecs = shared_description do
887
+ it "should have pool_type return a symbol" do
888
+ @class.new(mock_db.call{123}, {}).pool_type.must_be_kind_of(Symbol)
889
889
  end
890
890
 
891
- specify "should have all_connections yield current and available connections" do
891
+ it "should have all_connections yield current and available connections" do
892
892
  p = @class.new(mock_db.call{123}, {})
893
- p.hold{|c| p.all_connections{|c1| c.should == c1}}
893
+ p.hold{|c| p.all_connections{|c1| c.must_equal c1}}
894
894
  end
895
895
 
896
- specify "should have a size method that gives the current size of the pool" do
896
+ it "should have a size method that gives the current size of the pool" do
897
897
  p = @class.new(mock_db.call{123}, {})
898
- p.size.should == 0
898
+ p.size.must_equal 0
899
899
  p.hold{}
900
- p.size.should == 1
900
+ p.size.must_equal 1
901
901
  end
902
902
 
903
- specify "should have a max_size method that gives the maximum size of the pool" do
904
- @class.new(mock_db.call{123}, {}).max_size.should >= 1
903
+ it "should have a max_size method that gives the maximum size of the pool" do
904
+ @class.new(mock_db.call{123}, {}).max_size.must_be :>=, 1
905
905
  end
906
906
 
907
- specify "should support preconnect method that immediately creates the maximum number of connections" do
907
+ it "should support preconnect method that immediately creates the maximum number of connections" do
908
908
  p = @class.new(mock_db.call{123}, {})
909
909
  p.send(:preconnect)
910
910
  i = 0
911
911
  p.all_connections{|c1| i+=1}
912
- i.should == p.max_size
912
+ i.must_equal p.max_size
913
913
  end
914
914
 
915
- specify "should be able to modify after_connect proc after the pool is created" do
915
+ it "should be able to modify after_connect proc after the pool is created" do
916
916
  a = []
917
917
  p = @class.new(mock_db.call{123}, {})
918
918
  p.after_connect = pr = proc{|c| a << c}
919
- p.after_connect.should == pr
920
- a.should == []
919
+ p.after_connect.must_equal pr
920
+ a.must_equal []
921
921
  p.hold{}
922
- a.should == [123]
922
+ a.must_equal [123]
923
923
  end
924
924
 
925
- specify "should not raise an error when disconnecting twice" do
925
+ it "should not raise an error when disconnecting twice" do
926
926
  c = @class.new(mock_db.call{123}, {})
927
- proc{c.disconnect}.should_not raise_error
928
- proc{c.disconnect}.should_not raise_error
927
+ c.disconnect
928
+ c.disconnect
929
929
  end
930
930
 
931
- specify "should yield a connection created by the initialize block to hold" do
931
+ it "should yield a connection created by the initialize block to hold" do
932
932
  x = nil
933
933
  @class.new(mock_db.call{123}, {}).hold{|c| x = c}
934
- x.should == 123
934
+ x.must_equal 123
935
935
  end
936
936
 
937
- specify "should have the initialize block accept a shard/server argument" do
937
+ it "should have the initialize block accept a shard/server argument" do
938
938
  x = nil
939
939
  @class.new(mock_db.call{|c| [c, c]}, {}).hold{|c| x = c}
940
- x.should == [:default, :default]
940
+ x.must_equal [:default, :default]
941
941
  end
942
942
 
943
- specify "should have respect an :after_connect proc that is called with each newly created connection" do
943
+ it "should have respect an :after_connect proc that is called with each newly created connection" do
944
944
  x = nil
945
945
  @class.new(mock_db.call{123}, :after_connect=>proc{|c| x = [c, c]}).hold{}
946
- x.should == [123, 123]
946
+ x.must_equal [123, 123]
947
947
  @class.new(mock_db.call{123}, :after_connect=>lambda{|c| x = [c, c]}).hold{}
948
- x.should == [123, 123]
948
+ x.must_equal [123, 123]
949
949
  @class.new(mock_db.call{123}, :after_connect=>proc{|c, s| x = [c, s]}).hold{}
950
- x.should == [123, :default]
950
+ x.must_equal [123, :default]
951
951
  @class.new(mock_db.call{123}, :after_connect=>lambda{|c, s| x = [c, s]}).hold{}
952
- x.should == [123, :default]
952
+ x.must_equal [123, :default]
953
953
  end
954
954
 
955
- specify "should raise a DatabaseConnectionError if the connection raises an exception" do
956
- proc{@class.new(mock_db.call{|c| raise Exception}, {}).hold{}}.should raise_error(Sequel::DatabaseConnectionError)
955
+ it "should raise a DatabaseConnectionError if the connection raises an exception" do
956
+ proc{@class.new(mock_db.call{|c| raise Exception}, {}).hold{}}.must_raise(Sequel::DatabaseConnectionError)
957
957
  end
958
958
 
959
- specify "should raise a DatabaseConnectionError if the initialize block returns nil" do
960
- proc{@class.new(mock_db.call{}, {}).hold{}}.should raise_error(Sequel::DatabaseConnectionError)
959
+ it "should raise a DatabaseConnectionError if the initialize block returns nil" do
960
+ proc{@class.new(mock_db.call{}, {}).hold{}}.must_raise(Sequel::DatabaseConnectionError)
961
961
  end
962
962
 
963
- specify "should call the disconnection_proc option if the hold block raises a DatabaseDisconnectError" do
963
+ it "should call the disconnection_proc option if the hold block raises a DatabaseDisconnectError" do
964
964
  x = nil
965
- proc{@class.new(mock_db.call(proc{|c| x = c}){123}).hold{raise Sequel::DatabaseDisconnectError}}.should raise_error(Sequel::DatabaseDisconnectError)
966
- x.should == 123
965
+ proc{@class.new(mock_db.call(proc{|c| x = c}){123}).hold{raise Sequel::DatabaseDisconnectError}}.must_raise(Sequel::DatabaseDisconnectError)
966
+ x.must_equal 123
967
967
  end
968
968
 
969
- specify "should have a disconnect method that disconnects the connection" do
969
+ it "should have a disconnect method that disconnects the connection" do
970
970
  x = nil
971
971
  c = @class.new(mock_db.call(proc{|c1| x = c1}){123})
972
972
  c.hold{}
973
- x.should == nil
973
+ x.must_equal nil
974
974
  c.disconnect
975
- x.should == 123
975
+ x.must_equal 123
976
976
  end
977
977
 
978
- specify "should have a reentrent hold method" do
978
+ it "should have a reentrent hold method" do
979
979
  o = Object.new
980
980
  c = @class.new(mock_db.call{o}, {})
981
981
  c.hold do |x|
982
- x.should == o
982
+ x.must_equal o
983
983
  c.hold do |x1|
984
- x1.should == o
984
+ x1.must_equal o
985
985
  c.hold do |x2|
986
- x2.should == o
986
+ x2.must_equal o
987
987
  end
988
988
  end
989
989
  end
990
990
  end
991
991
 
992
- specify "should have a servers method that returns an array of shard/server symbols" do
993
- @class.new(mock_db.call{123}, {}).servers.should == [:default]
992
+ it "should have a servers method that returns an array of shard/server symbols" do
993
+ @class.new(mock_db.call{123}, {}).servers.must_equal [:default]
994
994
  end
995
995
 
996
- specify "should have a servers method that returns an array of shard/server symbols" do
996
+ it "should have a servers method that returns an array of shard/server symbols" do
997
997
  c = @class.new(mock_db.call{123}, {})
998
- c.size.should == 0
998
+ c.size.must_equal 0
999
999
  c.hold{}
1000
- c.size.should == 1
1000
+ c.size.must_equal 1
1001
1001
  end
1002
1002
  end
1003
1003
 
@@ -1010,6 +1010,7 @@ Sequel::ConnectionPool::CONNECTION_POOL_MAP.keys.each do |k, v|
1010
1010
  before do
1011
1011
  @class = Sequel::ConnectionPool.send(:connection_pool_class, opts)
1012
1012
  end
1013
- it_should_behave_like "All connection pools classes"
1013
+
1014
+ include AllConnectionPoolClassesSpecs
1014
1015
  end
1015
1016
  end