Created
June 18, 2010 13:06
-
-
Save bcantin/443610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you can turn two tests into one if you are testing almost the same thing | |
# example | |
before(:each) do | |
@project = Project.new | |
end | |
it "should contain errors on a blank url" do | |
@project.save | |
@project.errors.should include({:url=>["can't be blank"]}) | |
end | |
it "should contain erros on a blank name" do | |
@project.save | |
@project.errors.should include({:name=>["can't be blank"]}) | |
end | |
#The above tests are very clear and lets the developer know what is going on, but it is | |
# duplicated except for the attribute being tested... so lets refactor! | |
it "should contain errors on a blank url or name" do | |
@project.save | |
[:url,:name].each do |attrib| | |
@project.errors.should include({attrib=>["can't be blank"]}) | |
end | |
end | |
# You should not feel that you HAVE to refactor the above two into one, as most of the time | |
# readability in tests should trump the DRY principal. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment