Keeping your tests small sounds a bit odd, but it's quite easy to get in a test flow and to write spaghetti tests, testing too much at once. Stay focussed on what to test, and just test this single aspect of your code!
1 2 describe "A user's display name" do
3 it "should reflect the user's name" do
4 user = User.new(:login => 'alto')
5 user.display_name.should eql('alto')
6
7 user.firstname = 'Thorsten'
8 user.display_name.should eql('Thorsten')
9
10 user.lastname = 'Böttger'
11 user.display_name.should eql('Thorsten Böttger')
12 end
13 end
14
This test is hard to read, since it tests three aspects at once. Even the dscription block is a bit ambiguous. The test is unfocused, and as a matter of result, in case your test contains an error itself, it's hard to debug. The following three tests are much better:
1 2 describe "A user's display name" do
3 before do
4 @user = User.new(:login => 'alto')
5 end
6 it "should equal the login name if no other name is given" do
7 @user.display_name.should eql('alto')
8 end
9 it "should equal his firstname if it is given" do
10 @user.firstname = 'Thorsten'
11 @user.display_name.should eql('Thorsten')
12 end
13 it "should equal his fullname if firstname and lastname are given" do
14 @user.firstname = 'Thorsten'
15 @user.lastname = 'Böttger'
16 @user.display_name.should eql('Thorsten Böttger')
17 end
18 end
19