Question: New to TDD here, d'oh!

Here's what I want to test ([ruby library](https://www.twilio.com/docs/ruby/install)), in brief:

```
 account = Twilio::RestAccount.new(ACCOUNT_SID, ACCOUNT_TOKEN)
    resp = account.request(
        "/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/SMS/Messages",
        'POST',
        smsInfo
    )

```

And here's test code attempt:

```
describe Text do
  it "should call the Twilio API with credentials" do
    #pending "mocking api although not passed in.."
    t = mock(Twilio::RestAccount)
    twapi = mock("new twapi").should_receive(:request).and_return(Net::HTTPSuccess)
    t.stub(:new).and_return(twapi)

    Twilio::RestAccount.should_receive(:new)

    sms = Factory.create(:boring_sms)
    sms.send_sms
  end
end

```

which generates the error: undefined method `request' for nil:NilClass

Am I taking the right approach? thanks!

Answer: 
I would use three different tables with foreign keys to link them. But you may also nest comments (or whatever) by having a 'parent'-row on the comment-table, which is a foreign-key to this tables primary key.

```
CREATE TABLE IF NOT EXISTS `comment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent_comment` int(11) DEFAULT NULL COMMENT 'allows commenting on comments (annotations)',
  `user` int(11) NOT NULL,
  `headline` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `content` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_comment_parent` (`parent_comment`),
  KEY `fk_comment_user` (`user`)
);

ALTER TABLE `comment`
  ADD CONSTRAINT `fk_comment_parent` FOREIGN KEY (`parent_comment`) REFERENCES `comment` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_comment_user` FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON UPDATE CASCADE;

```
You're looking for "foreign key references." You will likely find yourself with three tables: questions, answers, and comments on answers. Answers will have a field referencing the id of the question it's responding to, and likewise you will have a field in the comments table referencing the id of the answer it's responding to. I hope these links can be helpful:

[Wikipedia](http://en.wikipedia.org/wiki/Foreign_key)

[w3c](http://www.w3schools.com/sql/sql_foreignkey.asp)

This is an important area of database design that requires some heavier reading than it sounds like you're expecting.