On Wednesday, March 21, 2012 8:54:04 PM UTC-7, Tyler Lemburg wrote:
>
> Hi, 
>
> I'm trying to run RSpec test cases with the following code in my test 
> case: 
>
> prof = Profile[8] 
> prof.values.should be_an_instance_of(Hash) 
> prof.ProfileID.should eq(8) 
> prof.FirstName.should eq("Karen") 
>
> with Profile < Sequel::Model of course from another file. How can I 
> set the DB for the prof.Profile[8] call to use a Sequel.mock adapter? 
> I know I can do 
>
> DB = Sequel.mock 
> ds = DB[:tblProfiles] 
> ds._fetch = [{:ProfileID => 8, :FirstName => 'Karen'}] 
>
> or similar in my test case, but this seems to only affect new uses of 
> that DB constant. Would I need to somehow re-declare my Profile class 
> to re-invoke the Sequel::Model stuff? Or is there another better way 
> to mock the actual database behind my Model.[] call? 
>

 Well, you could do:

  Profile.dataset = Sequel.mock[:tblProfiles] 
  Profile.dataset._fetch = [{:ProfileID => 8, :FirstName => 'Karen'}] 

to set the Database object used by the model to a mocked database and set 
the hashes that will be returned.

One more note: this is only my second week of Ruby, so feel free to 
> explain anything I'm missing :)


Well, mocking the database when unit testing Sequel::Model classes in 
applications is not necessarily a good idea.  It's useful in some 
situations, but for my own apps, I generally don't mock the database in the 
unit tests.  However, Sequel::Model's own specs use a mocked database, so 
it is certainly useful in some cases.  If you have your own reasons for 
mocking, then by all means continue, but if you've just heard it's a good 
idea from others, you may want to reconsider.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/a3wuBIVpcyMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to