diff --git a/spec/binary_spec.rb b/spec/binary_spec.rb index a0d7949..a36af3d 100644 --- a/spec/binary_spec.rb +++ b/spec/binary_spec.rb @@ -14,7 +14,7 @@ assert_creates(Pet, [{:name => name, :zipped_biography => zipped_biography}]) do upsert.row({:name => name}, {:zipped_biography => Upsert.binary(zipped_biography)}) end - Zlib::Inflate.inflate(Pet.find_by_name(name).zipped_biography).should == biography + expect(Zlib::Inflate.inflate(Pet.find_by_name(name).zipped_biography)).to eq(biography) end end end diff --git a/spec/correctness_spec.rb b/spec/correctness_spec.rb index 5e47885..14acfc2 100644 --- a/spec/correctness_spec.rb +++ b/spec/correctness_spec.rb @@ -11,26 +11,26 @@ u = Upsert.new($conn, :pets) selector = {:name => 'Jerry', :tag_number => 6} u.row(selector) - Pet.find_by_name('Jerry').tag_number.should == 5 + expect(Pet.find_by_name('Jerry').tag_number).to eq(5) # won't change anything because selector is wrong u = Upsert.new($conn, :pets) selector = {:name => 'Jerry', :tag_number => 10} setter = { :tag_number => 5 } u.row(selector, setter) - Pet.find_by_name('Jerry').tag_number.should == 5 + expect(Pet.find_by_name('Jerry').tag_number).to eq(5) u = Upsert.new($conn, :pets) selector = { :name => 'Jerry' } setter = { :tag_number => 10 } u.row(selector, setter) - Pet.find_by_name('Jerry').tag_number.should == 10 + expect(Pet.find_by_name('Jerry').tag_number).to eq(10) u = Upsert.new($conn, :pets) selector = { :name => 'Jerry', :tag_number => 10 } setter = { :tag_number => 20 } u.row(selector, setter) - Pet.find_by_name('Jerry').tag_number.should == 20 + expect(Pet.find_by_name('Jerry').tag_number).to eq(20) end it "really limits its effects to the selector" do @@ -39,34 +39,34 @@ p.gender = 'blue' p.tag_number = 777 p.save! - Pet.find_by_name_and_gender('Jerry', 'blue').tag_number.should == 777 + expect(Pet.find_by_name_and_gender('Jerry', 'blue').tag_number).to eq(777) u = Upsert.new($conn, :pets) selector = {:name => 'Jerry', :gender => 'red'} # this shouldn't select anything setter = {:tag_number => 888} u.row(selector, setter) - Pet.find_by_name_and_gender('Jerry', 'blue').tag_number.should == 777 + expect(Pet.find_by_name_and_gender('Jerry', 'blue').tag_number).to eq(777) end # https://github.com/seamusabshere/upsert/issues/18 it "uses nil selectors" do - Pet.count.should == 0 + expect(Pet.count).to eq(0) now = Date.today u = Upsert.new($conn, :pets) 5.times do u.row(:gender => nil, :birthday => now) end - Pet.count.should == 1 + expect(Pet.count).to eq(1) end it "uses nil selectors on columns with date type" do - Pet.count.should == 0 + expect(Pet.count).to eq(0) u = Upsert.new($conn, :pets) 5.times do u.row(:birthday => nil) end - Pet.count.should == 1 + expect(Pet.count).to eq(1) end it "uses nil selectors (another way of checking)" do @@ -80,10 +80,10 @@ it "tells you if you request a column that doesn't exist" do u = Upsert.new($conn, :pets) - lambda { u.row(:gibberish => 'ba') }.should raise_error(/invalid col/i) - lambda { u.row(:name => 'Jerry', :gibberish => 'ba') }.should raise_error(/invalid col/i) - lambda { u.row(:name => 'Jerry', :gibberish => 'ba') }.should raise_error(/invalid col/i) - lambda { u.row(:name => 'Jerry', :gibberish => 'ba', :gender => 'male') }.should raise_error(/invalid col/i) + expect { u.row(:gibberish => 'ba') }.to raise_error(/invalid col/i) + expect { u.row(:name => 'Jerry', :gibberish => 'ba') }.to raise_error(/invalid col/i) + expect { u.row(:name => 'Jerry', :gibberish => 'ba') }.to raise_error(/invalid col/i) + expect { u.row(:name => 'Jerry', :gibberish => 'ba', :gender => 'male') }.to raise_error(/invalid col/i) end end diff --git a/spec/database_functions_spec.rb b/spec/database_functions_spec.rb index 03c2518..4782d81 100644 --- a/spec/database_functions_spec.rb +++ b/spec/database_functions_spec.rb @@ -18,7 +18,7 @@ io.rewind hits = io.read.split("\n").grep(/Creating or replacing/) - hits.length.should == 2 + expect(hits.length).to eq(2) ensure Upsert.logger = old_logger end @@ -42,7 +42,7 @@ io.rewind hits = io.read.split("\n").grep(/Creating or replacing/) - hits.length.should == 2 + expect(hits.length).to eq(2) ensure Upsert.logger = old_logger end @@ -65,7 +65,7 @@ io.rewind hits = io.read.split("\n").grep(/Creating or replacing/) - hits.length.should == 1 + expect(hits.length).to eq(1) ensure Upsert.logger = old_logger end @@ -88,8 +88,8 @@ io.rewind lines = io.read.split("\n") - lines.grep(/went missing/).length.should == 1 - lines.grep(/Creating or replacing/).length.should == 1 + expect(lines.grep(/went missing/).length).to eq(1) + expect(lines.grep(/Creating or replacing/).length).to eq(1) ensure Upsert.logger = old_logger end diff --git a/spec/database_spec.rb b/spec/database_spec.rb index 5b4abf5..4bc38a5 100644 --- a/spec/database_spec.rb +++ b/spec/database_spec.rb @@ -36,7 +36,7 @@ upsert.row({:name => 'Jerry'}, {:gender => 'male'}) upsert.row({:name => 'Jerry'}, {:gender => 'neutered'}) end - Pet.where(:gender => 'male').count.should == 0 + expect(Pet.where(:gender => 'male').count).to eq(0) end it "works for a single row with implicit nulls" do upsert = Upsert.new $conn, :pets @@ -72,8 +72,8 @@ upsert = Upsert.new $conn, :tasks upsert.row({:id => task.id}, :name => 'Clean kitchen') task.reload - task.created_at.should eql task.created_at - task.created_on.should eql task.created_on + expect(task.created_at).to eql task.created_at + expect(task.created_on).to eql task.created_on end it "converts symbol values to string" do @@ -114,7 +114,7 @@ upsert.row({:name => 'Jerry'}, :gender => 'neutered') end end - Pet.where(:gender => 'male').count.should == 0 + expect(Pet.where(:gender => 'male').count).to eq(0) end end end diff --git a/spec/hstore_spec.rb b/spec/hstore_spec.rb index ed338ed..e2443e8 100644 --- a/spec/hstore_spec.rb +++ b/spec/hstore_spec.rb @@ -19,7 +19,7 @@ upsert.row({:name => 'Uggy'}, :crazy => {:uggy => uggy}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Uggy'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'uggy' => uggy } + expect(crazy).to eq({ 'uggy' => uggy }) end it "just works" do @@ -27,36 +27,36 @@ upsert.row({:name => 'Bill'}, :crazy => nil) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) - row['crazy'].should == nil + expect(row['crazy']).to eq(nil) upsert.row({:name => 'Bill'}, :crazy => {:a => 1}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1' } + expect(crazy).to eq({ 'a' => '1' }) upsert.row({:name => 'Bill'}, :crazy => nil) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) - row['crazy'].should == nil + expect(row['crazy']).to eq(nil) upsert.row({:name => 'Bill'}, :crazy => {:a => 1}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1' } + expect(crazy).to eq({ 'a' => '1' }) upsert.row({:name => 'Bill'}, :crazy => {:whatdat => 'whodat'}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'whatdat' => 'whodat' } + expect(crazy).to eq({ 'a' => '1', 'whatdat' => 'whodat' }) upsert.row({:name => 'Bill'}, :crazy => {:whatdat => "D'ONOFRIO"}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'whatdat' => "D'ONOFRIO" } + expect(crazy).to eq({ 'a' => '1', 'whatdat' => "D'ONOFRIO" }) upsert.row({:name => 'Bill'}, :crazy => {:a => 2}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '2', 'whatdat' => "D'ONOFRIO" } + expect(crazy).to eq({ 'a' => '2', 'whatdat' => "D'ONOFRIO" }) end it "can nullify entire hstore" do @@ -65,11 +65,11 @@ upsert.row({:name => 'Bill'}, :crazy => {:a => 1}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1' } + expect(crazy).to eq({ 'a' => '1' }) upsert.row({:name => 'Bill'}, :crazy => nil) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) - row['crazy'].should == nil + expect(row['crazy']).to eq(nil) end it "deletes keys that are nil" do @@ -77,47 +77,47 @@ upsert.row({:name => 'Bill'}, :crazy => nil) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) - row['crazy'].should == nil + expect(row['crazy']).to eq(nil) upsert.row({:name => 'Bill'}, :crazy => {:a => 1}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1' } + expect(crazy).to eq({ 'a' => '1' }) upsert.row({:name => 'Bill'}, :crazy => {}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1' } + expect(crazy).to eq({ 'a' => '1' }) upsert.row({:name => 'Bill'}, :crazy => {:a => nil}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == {} + expect(crazy).to eq({}) upsert.row({:name => 'Bill'}, :crazy => {:a => 1, :b => 5}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'b' => '5' } + expect(crazy).to eq({ 'a' => '1', 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'b' => '5' } + expect(crazy).to eq({ 'a' => '1', 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {:a => nil}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'b' => '5' } + expect(crazy).to eq({ 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {:a => 1, :b => 5}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'b' => '5' } + expect(crazy).to eq({ 'a' => '1', 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {:a => nil, :b => nil, :c => 12}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'c' => '12' } + expect(crazy).to eq({ 'c' => '12' }) end it "takes dangerous keys" do @@ -125,47 +125,47 @@ upsert.row({:name => 'Bill'}, :crazy => nil) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) - row['crazy'].should == nil + expect(row['crazy']).to eq(nil) upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => 1}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'foo"bar' => '1' } + expect(crazy).to eq({ 'foo"bar' => '1' }) upsert.row({:name => 'Bill'}, :crazy => {}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'foo"bar' => '1' } + expect(crazy).to eq({ 'foo"bar' => '1' }) upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => nil}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == {} + expect(crazy).to eq({}) upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => 1, :b => 5}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'foo"bar' => '1', 'b' => '5' } + expect(crazy).to eq({ 'foo"bar' => '1', 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'foo"bar' => '1', 'b' => '5' } + expect(crazy).to eq({ 'foo"bar' => '1', 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => nil}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'b' => '5' } + expect(crazy).to eq({ 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => 1, :b => 5}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'foo"bar' => '1', 'b' => '5' } + expect(crazy).to eq({ 'foo"bar' => '1', 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {:'foo"bar' => nil, :b => nil, :c => 12}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'c' => '12' } + expect(crazy).to eq({ 'c' => '12' }) end it "handles multiple hstores" do @@ -173,9 +173,9 @@ upsert.row({:name => 'Bill'}, :crazy => {:a => 1, :b => 9}, :cool => {:c => 12, :d => 19}) row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'b' => '9' } + expect(crazy).to eq({ 'a' => '1', 'b' => '9' }) cool = PgHstore.parse row['cool'] - cool.should == { 'c' => '12', 'd' => '19' } + expect(cool).to eq({ 'c' => '12', 'd' => '19' }) end it "can deletes keys from multiple hstores at once" do @@ -184,36 +184,36 @@ upsert.row({:name => 'Bill'}, :crazy => {:a => 1}, :cool => {5 => 9}) row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1' } + expect(crazy).to eq({ 'a' => '1' }) cool = PgHstore.parse row['cool'] - cool.should == { '5' => '9' } + expect(cool).to eq({ '5' => '9' }) # NOOP upsert.row({:name => 'Bill'}, :crazy => {}, :cool => {}) row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1' } + expect(crazy).to eq({ 'a' => '1' }) cool = PgHstore.parse row['cool'] - cool.should == { '5' => '9' } + expect(cool).to eq({ '5' => '9' }) upsert.row({:name => 'Bill'}, :crazy => {:a => nil}, :cool => {13 => 17}) row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == {} + expect(crazy).to eq({}) cool = PgHstore.parse row['cool'] - cool.should == { '5' => '9', '13' => '17' } + expect(cool).to eq({ '5' => '9', '13' => '17' }) upsert.row({:name => 'Bill'}, :crazy => {:a => 1, :b => 5}) row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'b' => '5' } + expect(crazy).to eq({ 'a' => '1', 'b' => '5' }) upsert.row({:name => 'Bill'}, :crazy => {:b => nil}, :cool => {5 => nil}) row = Pet.connection.select_one(%{SELECT crazy, cool FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == {'a' => '1'} + expect(crazy).to eq({'a' => '1'}) cool = PgHstore.parse row['cool'] - cool.should == {'13' => '17' } + expect(cool).to eq({'13' => '17' }) end it "deletes keys whether new or existing record" do @@ -222,12 +222,12 @@ upsert.row({:name => 'Bill'}, :crazy => {:z => 1, :x => nil}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'z' => '1' } + expect(crazy).to eq({ 'z' => '1' }) upsert.row({:name => 'Bill'}, :crazy => {:a => 1}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'z' => '1' } + expect(crazy).to eq({ 'a' => '1', 'z' => '1' }) end it "can turn off eager nullify" do @@ -236,12 +236,12 @@ upsert.row({:name => 'Bill'}, {:crazy => {:z => 1, :x => nil}}, :eager_nullify => false) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'z' => '1', 'x' => nil } + expect(crazy).to eq({ 'z' => '1', 'x' => nil }) upsert.row({:name => 'Bill'}, :crazy => {:a => 1}) row = Pet.connection.select_one(%{SELECT crazy FROM pets WHERE name = 'Bill'}) crazy = PgHstore.parse row['crazy'] - crazy.should == { 'a' => '1', 'z' => '1', 'x' => nil} + expect(crazy).to eq({ 'a' => '1', 'z' => '1', 'x' => nil}) end end diff --git a/spec/logger_spec.rb b/spec/logger_spec.rb index d3ac2b3..bb2652b 100644 --- a/spec/logger_spec.rb +++ b/spec/logger_spec.rb @@ -12,7 +12,7 @@ Upsert.logger.warn "hello" io.rewind - io.read.chomp.should == 'hello' + expect(io.read.chomp).to eq('hello') end ensure Upsert.logger = old_logger @@ -33,12 +33,12 @@ log = io.read.chomp case u.connection.class.name when /sqlite/i - log.should =~ /insert or ignore/i + expect(log).to match(/insert or ignore/i) when /mysql/i - log.should =~ /call #{Upsert::MergeFunction::NAME_PREFIX}_pets_SEL_name/i + expect(log).to match(/call #{Upsert::MergeFunction::NAME_PREFIX}_pets_SEL_name/i) when /p.*g/i # [54ae2eea857] Possibly much more useful debug output - log.should =~ /selector:/i + expect(log).to match(/selector:/i) else raise "not sure" end diff --git a/spec/precision_spec.rb b/spec/precision_spec.rb index e4ea621..c9386c2 100644 --- a/spec/precision_spec.rb +++ b/spec/precision_spec.rb @@ -5,7 +5,7 @@ small = -0.00000000634943 upsert = Upsert.new $conn, :pets upsert.row({:name => 'NotJerry'}, :lovability => small) - Pet.first.lovability.should be_within(1e-11).of(small) # ? + expect(Pet.first.lovability).to be_within(1e-11).of(small) # ? end end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 91635b6..dde0cce 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -183,7 +183,7 @@ def lotsa_records def assert_same_result(records, &blk) blk.call(records) ref1 = Pet.order(:name).all.map { |pet| pet.attributes.except('id') } - + Pet.delete_all Upsert.batch($conn, :pets) do |upsert| @@ -198,7 +198,7 @@ def assert_same_result(records, &blk) def assert_creates(model, expected_records) expected_records.each do |selector, setter| # should i use setter in where? - model.where(selector).count.should == 0 + expect(model.where(selector).count).to eq(0) end yield expected_records.each do |selector, setter| @@ -213,7 +213,7 @@ def compare_attribute_sets(expected, found) e = expected.map { |attrs| simplify_attributes attrs } f = found.map { |attrs| simplify_attributes attrs } f.each_with_index do |fa, i| - fa.should == e[i] + expect(fa).to eq(e[i]) end end @@ -237,7 +237,7 @@ def assert_faster_than(competition, records, &blk) Pet.delete_all sleep 1 # -- - + ar_time = Benchmark.realtime { blk.call(records) } Pet.delete_all @@ -250,7 +250,7 @@ def assert_faster_than(competition, records, &blk) end end end - upsert_time.should be < ar_time + expect(upsert_time).to be < ar_time $stderr.puts " Upsert was #{((ar_time - upsert_time) / ar_time * 100).round}% faster than #{competition}" end end diff --git a/spec/type_safety_spec.rb b/spec/type_safety_spec.rb index 80464bb..1c523d3 100644 --- a/spec/type_safety_spec.rb +++ b/spec/type_safety_spec.rb @@ -3,9 +3,9 @@ describe "type safety" do it "does not attempt to typecast values" do upsert = Upsert.new $conn, :pets - lambda do + expect do upsert.row :tag_number => '' - end.should raise_error + end.to raise_error PG::InvalidTextRepresentation end end end if ENV['DB'] == 'postgresql'