I'm at rspec right now trying to make my models more accurate and accurate. Some things are still a little weird for me about rspec, and so I thought it would be nice if someone could clarify.
Say I have a User model. This one has: a name. The name should be between 4..15 characters (this is a secondary goal, at first it should simply exist). So now I think: what is the best way to test this so that it happens. To verify that the user must have a name, I wrote something like this:
describe User do let(:user) { User.new(:name => 'lele') } it "is not valid without a name" do user.name.should == 'lele' end end
Now I'm not quite sure that this is exactly what I want. It seems to me that I'm actually testing Rails with this. Moreover, if I want to check that the name cannot be more than 15 characters and less than 4, how can this be integrated?
EDIT:
Maybe this is better?
describe User do let(:user) { User.new(:name => 'lele') } it "is not valid without a name" do user.name.should_not be_empty end end
ruby-on-rails rspec
Spyros
source share