spec/mao_spec.rb in mao-0.0.8 vs spec/mao_spec.rb in mao-0.1.0
- old
+ new
@@ -5,223 +5,223 @@
before { prepare_spec }
describe ".connect!" do
let(:options) { double("options") }
let(:conn) { double("conn") }
- before { PG.should_receive(:connect).with(options).and_return(conn) }
- before { conn.should_receive(:internal_encoding=).with(Encoding::UTF_8) }
+ before { expect(PG).to receive(:connect).with(options).and_return(conn) }
+ before { expect(conn).to receive(:internal_encoding=).with(Encoding::UTF_8) }
before { Mao.disconnect! rescue false }
it { Mao.connect!(options) }
after { Mao.instance_variable_set("@conn", nil) }
end
describe ".disconnect!" do
- before { PG::Connection.any_instance.should_receive(:close) }
+ before { expect_any_instance_of(PG::Connection).to receive(:close) }
it { Mao.disconnect! }
end
describe ".sql" do
- before { PG::Connection.any_instance.should_receive(:exec).
+ before { expect_any_instance_of(PG::Connection).to receive(:exec).
with(:x).and_return(:y) }
- it { Mao.sql(:x).should eq :y }
+ it { expect(Mao.sql(:x)).to eq :y }
end
describe ".quote_ident" do
context "pass-thru" do
- before { PG::Connection.any_instance.should_receive(:quote_ident).
+ before { expect_any_instance_of(PG::Connection).to receive(:quote_ident).
with("table").and_return(%q{"table"}) }
- it { Mao.quote_ident("table").should eq %q{"table"} }
+ it { expect(Mao.quote_ident("table")).to eq %q{"table"} }
end
context "Symbols" do
- before { PG::Connection.any_instance.should_receive(:quote_ident).
+ before { expect_any_instance_of(PG::Connection).to receive(:quote_ident).
with("table").and_return(%q{"table"}) }
- it { Mao.quote_ident(:table).should eq %q{"table"} }
+ it { expect(Mao.quote_ident(:table)).to eq %q{"table"} }
end
end
describe ".escape_literal" do
describe "verify pass-thru String" do
- before { PG::Connection.any_instance.should_receive(:escape_literal).
+ before { expect_any_instance_of(PG::Connection).to receive(:escape_literal).
with("table").and_return(%q{'table'}) }
- it { Mao.escape_literal("table").should eq %q{'table'} }
+ it { expect(Mao.escape_literal("table")).to eq %q{'table'} }
end
describe "verify not pass-thru others" do
- before { PG::Connection.any_instance.
- should_not_receive(:escape_literal) }
- it { Mao.escape_literal(nil).should eq "null" }
+ before { expect_any_instance_of(PG::Connection).
+ not_to receive(:escape_literal) }
+ it { expect(Mao.escape_literal(nil)).to eq "null" }
end
describe "verify escape_literal-less PG::Connection" do
- before { PG::Connection.any_instance.should_receive(:respond_to?).
+ before { expect_any_instance_of(PG::Connection).to receive(:respond_to?).
with(:escape_literal).and_return(false) }
- before { PG::Connection.any_instance.should_receive(:escape_string).
+ before { expect_any_instance_of(PG::Connection).to receive(:escape_string).
with("xyz'hah").and_return("xyz''hah") }
- it { Mao.escape_literal("xyz'hah").should eq %q{'xyz''hah'} }
+ it { expect(Mao.escape_literal("xyz'hah")).to eq %q{'xyz''hah'} }
end
describe "actual values" do
- it { Mao.escape_literal("table").should eq %q{'table'} }
- it { Mao.escape_literal(42).should eq %q{42} }
- it { Mao.escape_literal(true).should eq %q{true} }
- it { Mao.escape_literal(false).should eq %q{false} }
- it { Mao.escape_literal(nil).should eq %q{null} }
- it { Mao.escape_literal([]).should eq %q{(null)} }
- it { Mao.escape_literal([1]).should eq %q{(1)} }
- it { Mao.escape_literal([1, "xzy"]).should eq %q{(1, 'xzy')} }
- it { Mao.escape_literal(Mao::Query.raw("\n\"'%")).should eq "\n\"'%" }
+ it { expect(Mao.escape_literal("table")).to eq %q{'table'} }
+ it { expect(Mao.escape_literal(42)).to eq %q{42} }
+ it { expect(Mao.escape_literal(true)).to eq %q{true} }
+ it { expect(Mao.escape_literal(false)).to eq %q{false} }
+ it { expect(Mao.escape_literal(nil)).to eq %q{null} }
+ it { expect(Mao.escape_literal([])).to eq %q{(null)} }
+ it { expect(Mao.escape_literal([1])).to eq %q{(1)} }
+ it { expect(Mao.escape_literal([1, "xzy"])).to eq %q{(1, 'xzy')} }
+ it { expect(Mao.escape_literal(Mao::Query.raw("\n\"'%"))).to eq "\n\"'%" }
# Times are escaped to UTC always.
- it { Mao.escape_literal(Time.new(2012, 11, 11, 6, 45, 0, 11 * 3600)).
- should eq %q{'2012-11-10 19:45:00.000000'} }
- it { Mao.escape_literal(Time.new(2012, 11, 10, 19, 45, 0, 0)).
- should eq %q{'2012-11-10 19:45:00.000000'} }
- it { Mao.escape_literal(Time.new(2012, 11, 10, 19, 45, 0.1, 0)).
- should eq %q{'2012-11-10 19:45:00.100000'} }
+ it { expect(Mao.escape_literal(Time.new(2012, 11, 11, 6, 45, 0, 11 * 3600))).
+ to eq %q{'2012-11-10 19:45:00.000000'} }
+ it { expect(Mao.escape_literal(Time.new(2012, 11, 10, 19, 45, 0, 0))).
+ to eq %q{'2012-11-10 19:45:00.000000'} }
+ it { expect(Mao.escape_literal(Time.new(2012, 11, 10, 19, 45, 0.1, 0))).
+ to eq %q{'2012-11-10 19:45:00.100000'} }
end
end
describe ".query" do
subject { Mao.query(:empty) }
- it { should be_an_instance_of Mao::Query }
- it { should be_frozen }
+ it { is_expected.to be_an_instance_of Mao::Query }
+ it { is_expected.to be_frozen }
end
describe ".transaction" do
context "empty" do
- before { PG::Connection.any_instance.should_receive(:exec).
+ before { expect_any_instance_of(PG::Connection).to receive(:exec).
with("BEGIN") }
- before { PG::Connection.any_instance.should_receive(:exec).
+ before { expect_any_instance_of(PG::Connection).to receive(:exec).
with("COMMIT") }
it { Mao.transaction {} }
end
context "success" do
- before { Mao.should_receive(:sql).with("BEGIN") }
- before { Mao.should_receive(:sql).with(:some_sql).and_return :ok }
- before { Mao.should_receive(:sql).with("COMMIT") }
- it { Mao.transaction { Mao.sql(:some_sql) }.
- should eq :ok }
+ before { expect(Mao).to receive(:sql).with("BEGIN") }
+ before { expect(Mao).to receive(:sql).with(:some_sql).and_return :ok }
+ before { expect(Mao).to receive(:sql).with("COMMIT") }
+ it { expect(Mao.transaction { Mao.sql(:some_sql) }).
+ to eq :ok }
end
context "failure" do
- before { Mao.should_receive(:sql).with("BEGIN") }
- before { Mao.should_receive(:sql).with(:some_sql).
+ before { expect(Mao).to receive(:sql).with("BEGIN") }
+ before { expect(Mao).to receive(:sql).with(:some_sql).
and_raise(Exception.new) }
- before { Mao.should_receive(:sql).with("ROLLBACK") }
+ before { expect(Mao).to receive(:sql).with("ROLLBACK") }
it { expect { Mao.transaction { Mao.sql(:some_sql) }
- }.to raise_exception }
+ }.to raise_exception Exception}
end
context "rollback" do
- before { Mao.should_receive(:sql).with("BEGIN") }
- before { Mao.should_receive(:sql).with(:some_sql).
+ before { expect(Mao).to receive(:sql).with("BEGIN") }
+ before { expect(Mao).to receive(:sql).with(:some_sql).
and_raise(Mao::Rollback) }
- before { Mao.should_receive(:sql).with("ROLLBACK") }
+ before { expect(Mao).to receive(:sql).with("ROLLBACK") }
it { expect { Mao.transaction { Mao.sql(:some_sql) }
}.to_not raise_exception }
end
context "nested transactions" do
# Currently not supported: the inner transactions don't add transactions
# at all.
- before { Mao.should_receive(:sql).with("BEGIN").once }
- before { Mao.should_receive(:sql).with("ROLLBACK").once }
+ before { expect(Mao).to receive(:sql).with("BEGIN").once }
+ before { expect(Mao).to receive(:sql).with("ROLLBACK").once }
it do
- Mao.transaction { Mao.transaction { raise Mao::Rollback } }.
- should be_false
+ expect(Mao.transaction { Mao.transaction { raise Mao::Rollback } }).
+ to be_falsey
end
end
end
describe ".normalize_result" do
- before { Mao.should_receive(:convert_type).
+ before { expect(Mao).to receive(:convert_type).
with("y", "zzz").and_return("q") }
- it { Mao.normalize_result({"x" => "y"}, {:x => "zzz"}).
- should eq({:x => "q"}) }
+ it { expect(Mao.normalize_result({"x" => "y"}, {:x => "zzz"})).
+ to eq({:x => "q"}) }
end
describe ".normalize_join_result" do
let(:from) { double("from") }
let(:to) { double("to") }
- before { from.should_receive(:table).and_return(:from) }
- before { from.should_receive(:col_types).and_return({:a => "integer"}) }
- before { to.should_receive(:table).and_return(:to) }
- before { to.should_receive(:col_types).
+ before { expect(from).to receive(:table).and_return(:from) }
+ before { expect(from).to receive(:col_types).and_return({:a => "integer"}) }
+ before { expect(to).to receive(:table).and_return(:to) }
+ before { expect(to).to receive(:col_types).
and_return({:b => "character varying"}) }
- it { Mao.normalize_join_result(
- {"c1" => "1", "c2" => "2"}, from, to).
- should eq({:from => {:a => 1},
+ it { expect(Mao.normalize_join_result(
+ {"c1" => "1", "c2" => "2"}, from, to)).
+ to eq({:from => {:a => 1},
:to => {:b => "2"}}) }
- it { Mao.normalize_join_result(
- {"c1" => "1"}, from, to).
- should eq({:from => {:a => 1}}) }
+ it { expect(Mao.normalize_join_result(
+ {"c1" => "1"}, from, to)).
+ to eq({:from => {:a => 1}}) }
end
describe ".convert_type" do
context "integers" do
- it { Mao.convert_type(nil, "integer").should be_nil }
- it { Mao.convert_type("42", "integer").should eq 42 }
- it { Mao.convert_type("42", "smallint").should eq 42 }
- it { Mao.convert_type("42", "bigint").should eq 42 }
- it { Mao.convert_type("42", "serial").should eq 42 }
- it { Mao.convert_type("42", "bigserial").should eq 42 }
+ it { expect(Mao.convert_type(nil, "integer")).to be_nil }
+ it { expect(Mao.convert_type("42", "integer")).to eq 42 }
+ it { expect(Mao.convert_type("42", "smallint")).to eq 42 }
+ it { expect(Mao.convert_type("42", "bigint")).to eq 42 }
+ it { expect(Mao.convert_type("42", "serial")).to eq 42 }
+ it { expect(Mao.convert_type("42", "bigserial")).to eq 42 }
end
context "character" do
- it { Mao.convert_type(nil, "character varying").should be_nil }
- it { Mao.convert_type("blah", "character varying").
- should eq "blah" }
- it { Mao.convert_type("blah", "character varying").encoding.
- should be Encoding::UTF_8 }
+ it { expect(Mao.convert_type(nil, "character varying")).to be_nil }
+ it { expect(Mao.convert_type("blah", "character varying")).
+ to eq "blah" }
+ it { expect(Mao.convert_type("blah", "character varying").encoding).
+ to be Encoding::UTF_8 }
- it { Mao.convert_type(nil, "character varying(200)").should be_nil }
- it { Mao.convert_type("blah", "character varying(200)").
- should eq "blah" }
- it { Mao.convert_type("blah", "character varying(200)").encoding.
- should be Encoding::UTF_8 }
+ it { expect(Mao.convert_type(nil, "character varying(200)")).to be_nil }
+ it { expect(Mao.convert_type("blah", "character varying(200)")).
+ to eq "blah" }
+ it { expect(Mao.convert_type("blah", "character varying(200)").encoding).
+ to be Encoding::UTF_8 }
- it { Mao.convert_type(nil, "text").should be_nil }
- it { Mao.convert_type("blah", "text").
- should eq "blah" }
- it { Mao.convert_type("blah", "text").encoding.
- should be Encoding::UTF_8 }
+ it { expect(Mao.convert_type(nil, "text")).to be_nil }
+ it { expect(Mao.convert_type("blah", "text")).
+ to eq "blah" }
+ it { expect(Mao.convert_type("blah", "text").encoding).
+ to be Encoding::UTF_8 }
end
context "dates" do
- it { Mao.convert_type(nil, "timestamp without time zone").
- should be_nil }
+ it { expect(Mao.convert_type(nil, "timestamp without time zone")).
+ to be_nil }
# Note: without timezone is assumed to be in UTC.
- it { Mao.convert_type("2012-11-10 19:45:00",
- "timestamp without time zone").
- should eq Time.new(2012, 11, 10, 19, 45, 0, 0) }
- it { Mao.convert_type("2012-11-10 19:45:00.1",
- "timestamp without time zone").
- should eq Time.new(2012, 11, 10, 19, 45, 0.1, 0) }
+ it { expect(Mao.convert_type("2012-11-10 19:45:00",
+ "timestamp without time zone")).
+ to eq Time.new(2012, 11, 10, 19, 45, 0, 0) }
+ it { expect(Mao.convert_type("2012-11-10 19:45:00.1",
+ "timestamp without time zone")).
+ to eq Time.new(2012, 11, 10, 19, 45, 0.1, 0) }
end
context "booleans" do
- it { Mao.convert_type(nil, "boolean").should be_nil }
- it { Mao.convert_type("t", "boolean").should eq true }
- it { Mao.convert_type("f", "boolean").should eq false }
+ it { expect(Mao.convert_type(nil, "boolean")).to be_nil }
+ it { expect(Mao.convert_type("t", "boolean")).to eq true }
+ it { expect(Mao.convert_type("f", "boolean")).to eq false }
end
context "bytea" do
- it { Mao.convert_type(nil, "bytea").should be_nil }
- it { Mao.convert_type("\\x5748415400", "bytea").should eq "WHAT\x00" }
- it { Mao.convert_type("\\x5748415400", "bytea").encoding.
- should eq Encoding::ASCII_8BIT }
+ it { expect(Mao.convert_type(nil, "bytea")).to be_nil }
+ it { expect(Mao.convert_type("\\x5748415400", "bytea")).to eq "WHAT\x00" }
+ it { expect(Mao.convert_type("\\x5748415400", "bytea").encoding).
+ to eq Encoding::ASCII_8BIT }
end
context "numeric" do
- it { Mao.convert_type(nil, "numeric").should be_nil }
- it { Mao.convert_type("1234567890123456.789", "numeric").
- should eq BigDecimal.new("1234567890123456.789") }
+ it { expect(Mao.convert_type(nil, "numeric")).to be_nil }
+ it { expect(Mao.convert_type("1234567890123456.789", "numeric")).
+ to eq BigDecimal.new("1234567890123456.789") }
end
end
end
# vim: set sw=2 cc=80 et: