I'm working in a project which involves ruby, sequel and sinatra. I read
about which testing framework to use, and RSpec seems to be the most used
by the community.
The project consists in a CRUD application, using DAO as the persistence
pattern.
require 'sequel'
DB = Sequel.sqlite
DB.create_table :foos do
primary_key :id
int :foo_attribute1
int :foo_attribute2
end
class Foo
attr_accessor :id, :foo_attribute1, :foo_attribute2
end
module FooDAO
extend self
def save(f)
DB[:foos].insert(foo_attribute1: f.foo_attribute1, foo_attribute2:
f.foo_attribute2)
end
def [](id)
DB[:foos].where(id: id).first
end
def update(f)
DB[:foos].where(id: f.id).update(foo_attribute1: f.foo_attribute1,
foo_attribute2: f.foo_attribute2)
end
def count
DB[:foos].count
end
end
describe FooDAO do
context 'save' do
f = Foo.new
f.foo_attribute1 = 1
f.foo_attribute2 = 2
FooDAO.save f
it { expect(FooDAO.count).to eq 1 }
end
context 'get' do
it { expect(FooDAO[1][:foo_attribute1]).to eq 1 }
it { expect(FooDAO[1][:foo_attribute2]).to eq 2 }
end
context 'update' do
f = Foo.new
f.id = 1
f.foo_attribute1 = 2
f.foo_attribute2 = 3
FooDAO.update f
it { expect(FooDAO[1][:foo_attribute1]).to eq 2 }
it { expect(FooDAO[1][:foo_attribute2]).to eq 3 }
end
end
In this case, the context `get` won't pass the examples. But if I comment
the context `update`, they will.
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/46177435-e16e-4c9a-a3e8-9bcd017a777c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.