Skip to main content
Code Review

Return to Revisions

3 of 3
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/

Dan's answer is great. I'd add a control test, to make sure that the entry object is actually valid by default, e.g.:

it "is valid with a user and project" do
 expect(entry).to be_valid
end

Otherwise, your following tests may be false positives. If the entry was invalid to begin with, the tests prove nothing. It also serves to test your FactoryGirl code.

You could also take a look at the Shoulda gem, which simplifies validation/association testing. Here's an example from their readme:

describe Post do
 it { should belong_to(:user) }
 it { should validate_presence_of(:title) }
end

In general though, expect some duplication-looking-code in tests. For one, you may be testing two very similar-but-not-quite-identical situations. If you were testing manually, you'll also be repeating a lot of steps if you're being thorough. But your tests should also be pretty self-contained, so while it's tempting to structure your code for reuse and maximum DRYness, you actually want to structure it so any single test can be run entirely on its own. Lastly, you just don't want to get too clever in your tests. Of course they should be well-written, but you can end up writing a lot of clever code for you tests - which you then need to test. You can see where that'll lead.

As Dan said, your current code is fine, and can't really get much drier.

Flambino
  • 33.3k
  • 2
  • 46
  • 90
default

AltStyle によって変換されたページ (->オリジナル) /