Permalink
Browse files

Modify adapter and integration tests to use cspecify for checked tests

This expands the use of cspecify to work on sqlite, mysql, and
postgres on the native, do, and jdbc adapters.  It also works
with h2 and amalgalite.  A future commit will handle cspecify
changes for Microsoft SQL Server on odbc and jdbc.

This expands the use of cspecify so it works in the adapter
tests, and also expands the API in the integration tests so
it accepts procs.

With these changes, the specs will show expected failures as
pending.  In most cases, these failures are due to limitations
either in the database itself or in the underlying database
driver that Sequel uses.
  • Loading branch information...
1 parent 5e04986 commit 8ff67426fc8a57857319187988b45deeb5a5d9b0 @jeremyevans jeremyevans committed Sep 8, 2009
View
2 spec/adapters/mysql_spec.rb
@@ -480,7 +480,7 @@ def logger.method_missing(m, msg)
@db[:items].first.should == nil
end
- specify "should handle multiple select statements at once" do
+ cspecify "should handle multiple select statements at once", :do, :jdbc do
@db.create_table(:items){String :name; Integer :value}
@db[:items].delete
@db[:items].insert(:name => 'tutu', :value => 1234)
View
2 spec/adapters/postgres_spec.rb
@@ -137,7 +137,7 @@ def logger.method_missing(m, msg)
@d.delete
end
- specify "should store milliseconds in time fields" do
+ cspecify "should store milliseconds in time fields", :do do
t = Time.now
@d << {:value=>1, :time=>t}
@d.literal(@d[:value =>'1'][:time]).should == @d.literal(t)
View
21 spec/adapters/spec_helper.rb
@@ -8,3 +8,24 @@
require File.join(File.dirname(File.dirname(__FILE__)), 'spec_config.rb')
rescue LoadError
end
+
+class Spec::Example::ExampleGroup
+ def self.cspecify(message, *checked, &block)
+ pending = false
+ checked.each do |c|
+ case c
+ when INTEGRATION_DB.class.adapter_scheme
+ pending = c
+ when Proc
+ pending = c if c.first.call(INTEGRATION_DB)
+ when Array
+ pending = c if c.first == INTEGRATION_DB.class.adapter_scheme && c.last == INTEGRATION_DB.call(INTEGRATION_DB)
+ end
+ end
+ if pending
+ specify(message){pending("Not yet working on #{Array(pending).join(', ')}", &block)}
+ else
+ specify(message, &block)
+ end
+ end
+end
View
2 spec/adapters/sqlite_spec.rb
@@ -68,7 +68,7 @@
proc {@db.temp_store = :invalid}.should raise_error(Sequel::Error)
end
- specify "should support timestamps and datetimes and respect datetime_class" do
+ cspecify "should support timestamps and datetimes and respect datetime_class", :do, :jdbc, :amalgalite do
@db.create_table!(:time){timestamp :t; datetime :d}
t1 = Time.at(1)
@db[:time] << {:t => t1, :d => t1.to_i}
View
4 spec/integration/dataset_test.rb
@@ -455,13 +455,13 @@
Date.today.should == @c2[@ds.get(:d)]
end
- it "should have working CURRENT_TIME" do
+ cspecify "should have working CURRENT_TIME", [:do, :mysql], [:jdbc, :sqlite] do
@db.create_table!(:constants){Time :t, :only_time=>true}
@ds.insert(:t=>Sequel::CURRENT_TIME)
(Time.now - @c[@ds.get(:t)]).should be_close(0, 1)
end
- it "should have working CURRENT_TIMESTAMP" do
+ cspecify "should have working CURRENT_TIMESTAMP", [:jdbc, :sqlite] do
@db.create_table!(:constants){DateTime :ts}
@ds.insert(:ts=>Sequel::CURRENT_TIMESTAMP)
(Time.now - @c[@ds.get(:ts)]).should be_close(0, 1)
View
10 spec/integration/schema_test.rb
@@ -81,7 +81,7 @@
INTEGRATION_DB.schema(:items).first.last[:ruby_default].should == 'blah'
end
- specify "should parse types from the schema properly" do
+ cspecify "should parse types from the schema properly", [:do, :mysql], [:jdbc, :mysql] do
INTEGRATION_DB.create_table!(:items){Integer :number}
INTEGRATION_DB.schema(:items).first.last[:type].should == :integer
INTEGRATION_DB.create_table!(:items){Fixnum :number}
@@ -183,7 +183,7 @@
@ds.all.should == [{:number=>10, :name=>nil}]
end
- specify "should add primary key columns to tables correctly" do
+ cspecify "should add primary key columns to tables correctly", :h2 do
@db.create_table!(:items){Integer :number}
@ds.insert(:number=>10)
@db.alter_table(:items){add_primary_key :id}
@@ -220,7 +220,7 @@
@ds.all.should == [{:n2=>'blah'}, {:n2=>'blah'}]
end
- specify "should rename columns with not null constraints" do
+ cspecify "should rename columns with not null constraints", [:mysql, :mysql] do
@db.create_table!(:items){String :n, :null=>false}
@ds.insert(:n=>'blah')
@db.alter_table(:items){rename_column :n, :n2}
@@ -231,7 +231,7 @@
proc{@ds.insert}.should raise_error(Sequel::DatabaseError)
end
- specify "should set column NULL/NOT NULL correctly" do
+ cspecify "should set column NULL/NOT NULL correctly", [:mysql, :mysql] do
@db.create_table!(:items){Integer :id}
@ds.insert(:id=>10)
@db.alter_table(:items){set_column_allow_null :id, false}
@@ -273,7 +273,7 @@
@ds.columns!.should == [:id, :item_id]
end
- specify "should remove columns from tables correctly" do
+ cspecify "should remove columns from tables correctly", :h2 do
@db.create_table!(:items) do
primary_key :id
String :name
View
13 spec/integration/spec_helper.rb
@@ -37,9 +37,18 @@ def self.cspecify(message, *checked, &block)
when 1
pending = c if c.first == INTEGRATION_DB.class.adapter_scheme
when 2
- pending = c if c.first == INTEGRATION_DB.class.adapter_scheme && c.last == INTEGRATION_DB.database_type
- end
+ if c.first.is_a?(Proc)
+ pending = c if c.first.call(INTEGRATION_DB) && c.last == INTEGRATION_DB.database_type
+ elsif c.last.is_a?(Proc)
+ pending = c if c.first == INTEGRATION_DB.class.adapter_scheme && c.last.call(INTEGRATION_DB)
+ else
+ pending = c if c.first == INTEGRATION_DB.class.adapter_scheme && c.last == INTEGRATION_DB.database_type
+ end
+ when 3
+ pending = c if c[0] == INTEGRATION_DB.class.adapter_scheme && c[1] == INTEGRATION_DB.database_type && c[2].call(INTEGRATION_DB)
+ end
end
+ break if pending
end
if pending
specify(message){pending("Not yet working on #{Array(pending).join(', ')}", &block)}
View
6 spec/integration/timezone_test.rb
@@ -31,19 +31,19 @@ def test_timezone
Sequel.datetime_class = Time
end
- specify "should support using UTC for database storage and local time for the application" do
+ cspecify "should support using UTC for database storage and local time for the application", [:do, proc{|db| db.database_type != :sqlite}] do
Sequel.database_timezone = :utc
Sequel.application_timezone = :local
test_timezone
end
- specify "should support using local time for database storage and UTC for the application" do
+ cspecify "should support using local time for database storage and UTC for the application", [:do, proc{|db| db.database_type != :sqlite}] do
Sequel.database_timezone = :local
Sequel.application_timezone = :utc
test_timezone
end
- specify "should support using UTC for both database storage and for application" do
+ cspecify "should support using UTC for both database storage and for application", [:do, proc{|db| db.database_type != :sqlite}] do
Sequel.default_timezone = :utc
test_timezone
end
View
2 spec/integration/transaction_test.rb
@@ -71,7 +71,7 @@
end
if INTEGRATION_DB.supports_savepoints?
- specify "should support nested transactions through savepoints using the savepoint option" do
+ cspecify "should support nested transactions through savepoints using the savepoint option", [:jdbc, :sqlite] do
@db = INTEGRATION_DB
@db.transaction do
@d << {:name => '1'}
View
10 spec/integration/type_test.rb
@@ -6,7 +6,7 @@ def create_items_table_with_column(name, type, opts={})
INTEGRATION_DB[:items]
end
- cspecify "should support casting correctly", :sqlite do
+ cspecify "should support casting correctly", [:sqlite, :sqlite] do
ds = create_items_table_with_column(:number, Integer)
ds.insert(:number => 1)
ds.select(:number.cast_string.as(:n)).map(:n).should == %w'1'
@@ -60,14 +60,14 @@ def create_items_table_with_column(name, type, opts={})
ds.all.should == [{:name=>'Test User'}]
end
- specify "should support generic date type" do
+ cspecify "should support generic date type", [:do, :sqlite], [:jdbc, :sqlite] do
ds = create_items_table_with_column(:dat, Date)
d = Date.today
ds.insert(:dat => d)
ds.first[:dat].should == d
end
- specify "should support generic datetime type" do
+ cspecify "should support generic datetime type", [:do, :sqlite], [:jdbc, :sqlite] do
ds = create_items_table_with_column(:tim, DateTime)
t = DateTime.now
ds.insert(:tim => t)
@@ -78,14 +78,14 @@ def create_items_table_with_column(name, type, opts={})
ds.first[:tim].strftime('%Y%m%d%H%M%S').should == t.strftime('%Y%m%d%H%M%S')
end
- specify "should support generic file type" do
+ cspecify "should support generic file type", [:do], :h2 do
ds = create_items_table_with_column(:name, File)
ds.insert(:name => ("a\0"*300).to_sequel_blob)
ds.all.should == [{:name=>("a\0"*300).to_sequel_blob}]
ds.first[:name].should be_a_kind_of(::Sequel::SQL::Blob)
end
- specify "should support generic boolean type" do
+ cspecify "should support generic boolean type", [:do, :sqlite], [:jdbc, :sqlite] do
ds = create_items_table_with_column(:number, TrueClass)
ds.insert(:number => true)
ds.all.should == [{:number=>true}]

0 comments on commit 8ff6742

Please sign in to comment.