rspec : how to I do this ?

Hello,

I have followed the rspec course on code-school.

Now I try to make it work on my own project.

Let’s say I have this model :

class message < ActiveRecord::Base

attr_accessible :bericht, :user

belongs_to :user

belongs_to :category

end

Now I try to make a test so I can verify that a message has a title and a body.

How can I do this ?

Roelof

I would suggest you use the rspec generators to create a model or
scaffold and then use the generated tests as a guide.

(Seems like something that an "rspec course" would have covered...)

Thanks for the answer.

I will try to find out how this works. As far as I can find it this is not covered in this code school course.

Roelof

Thanks for the answer.
I will try to find out how this works. As far as I can find it this is not
covered in this code school course.

Try railstutorial.org, which is free to use online. It gives a good
introduction to testing.

Colin

You can use the gem shoulda-matchers[1] to test it.

She works very well with rspec.

And it is very easy to test this.

With it you can test the attributes, calls from models and stuff …

You can use the gem-rails factory-girl, best to test the interactions, writing less and being more efficient … :slight_smile:

[1] -> https://github.com/thoughtbot/shoulda-matchers
[2] -> https://github.com/thoughtbot/factory_girl_rails