On Wednesday, October 21, 2015 at 5:06:47 PM UTC-7, Pietro wrote:
>
> I'd like to unit test my models without requiring a database connection,
> I'm currently using a mock database but I'm not sure if this is the right
> approach since the model have no attribute accessors.
>
> db = Sequel.mock
>
> class MyModel < Sequel::Model
> def started?
> Time.now >= @start_time
> end
> end
>
> foo = MyModel.new do |m|
> m.start_time = Time.now
> # undefined method `start_time=' for #<MyModel @values={}>
> (NoMethodError)
> end
>
> foo.started?
>
>
> I'm probably missing something obvious, any help is appreciated. Thanks!
>
IMO, it's a bad idea to use a mock database for unit testing. Test using a
database of the same type and schema as your production database. Only
mock what you must (e.g. 3rd party code you don't control), or you run the
risk of production failures even when the related code passes tests.
If you want to do this anyway, you can use the schema_caching extension,
dump the schema cache in production to a file, and load it in testing right
after creating the mock database connection.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" 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].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.