[rspec-users] more rspec questions

Patrick J. Collins patrick at collinatorstudios.com
Tue Apr 27 17:51:22 EDT 2010


> What if they didn't? Is there a different way you could design this so
> that the interesting bits (The small methods) didn't depend so much on
> the other bits around them?

Well this is for importing vCards...

So for example, I would like to just make a spec that does:


  before(:all) do
    card_data = File.read(RAILS_ROOT + "/spec/fixtures/vcard/kirk_no_photo.vcf")
    @vcard = Vcard.create!(:data => card_data)
  describe "finding a contact" do
    it "should find the contact when an email for the contact exists" do
      email = Email.create!(:address => "kirk at enterprise.com")
      contact = Contact.create!(:first_name => 'James', :last_name => 'Kirk')
      contact.emails << email
      @vcard.find_contact.should == contact


But, like I said, I am not quite sure how to structure it so that my @card ivar gets set..

> Make them public. Move them to their own classes that encapsulate the
> stuff they need to know about (e.g. the "setup".) When you test the
> higher level methods you can mock this stuff. When you test the small
> methods you should call them directly.

So is it bad practice then to use private methods?  I have a habit of doing
that-- but from what you're saying there is no way to test those things individually....

Patrick J. Collins

More information about the rspec-users mailing list