views:

201

answers:

1

Ok, total Cucumber newbie here so please be gentle. As a learning Ruby/Cucumber/MongoDB endeavor I'm building a simple contact manager. I have a Person (parent) model and an have been able to write a simple test as follows:

Scenario: Show people
  Given the following person exists
 | firstname | lastname |
 | Bob      | Jones    |
  When I am on the home page
  Then I should see "Bob"

So far so good....however now I am adding an array of "Address" child objects to it...problem is now that above test fails....I 'think' it's because I'm not describing my table correctly anymore in the above test, since it now has an address property too.

My question is how do I correctly write the above test if I want to check the child objects?

My two classes follow:

class Person < MongoBase
  key :firstname, String, :required=>true
  key :lastname, String, :required=>true

  many :addresses
end

class Address <MongoBase

  key :person_id, ObjectId
  key :street, String
  key :city, String
  key :State, String
  key :Zip, String

  belongs_to :person
end

Thanks in advance!

Update: the original test now passes but I still can't figure out how to set up the test so that Bob Jones has a child address.

A: 

I think the $1,000,000 is "what's the failure"? Also - if you're using MongoMapper than you'll want to explicitly set Address as an EmbeddedDocument (include MongoMapper::EmbeddedDocument) - this is most likely what your failure is since (I don't think) you can use many:XXX with a regular MongoMapper::Document.

Rob Conery
Pfft...like an error message has ever helped anyone...lolIt's undefined contast Addres ... which reading aloud helped me figure out...in my person class my many :address was wrong...it should have been pluralized... So now the initial test passes...but I'm left with the same question about how to write the cucumber test so that Bob Jones has an address.
Webjedi
Ahhh - in the step class set the table to a hash (the table is an argument that is passed by Cuke) and run an each over the hash, which loads the data to the test db.So:table.hashes.each do |hash| p=Person.new(hash) p.addresses << Address.new(...) p.saveend
Rob Conery
So in that example I'd be specifiying the creation of the address in the step, not in the Cuke... I guess that will work...couldn't wrap my head around how to draw that with the pipes anyway. :)
Webjedi