Skip to content

Instantly share code, notes, and snippets.

@briankung
Last active December 24, 2015 00:09
Show Gist options
  • Save briankung/6715158 to your computer and use it in GitHub Desktop.
Save briankung/6715158 to your computer and use it in GitHub Desktop.
Notes from the Rails Tutorial spec suite

Notes from the Rails Tutorial spec suite

  • Almost all of the model validations are should respond_to or should be_valid

  • A few specs for relationships

  • FactoryGirl vs Fabrication: After a bit of research, it seems like the general consensus is that Fabrication is better, even though FactoryGirl is used in the RailsTutorial.

  • Request specs test each page.

  • Composition:

    Controller Specs: 1 file, 4 examples, 2.7%

    Helper Specs: 1 file, 3 examples, 2.0%

    Model Specs: 3 file, 57 examples, 38.8%

    Request Specs: 4 files, 83 examples, 56.5%

Observation:

Resourceful controllers seem not to need their own specs. The standard seven are assumed to work if the request specs pass.

Conclusion

Write a shit ton of request specs, followed by model specs. Toss in a few helper or controller specs.

Yesterday, I went through the Rails Tutorial's spec suite to glean what I could of how to test an application what I found was a great deal of request specs driven by Capybara, followed by model specs, and then a handful of helper and controller specs - almost none to speak of, really.

What I realized is that web apps, at least in the style of Michael Hartl, are very presentation heavy. In terms of unit testing, there's not actually that much that goes on outside the model. The bulk of the specs happen at the request level.

What this means for me, however, is that I'll have to know very specifically what I want on any given page before I implement it. This is a good thing for learning, but it's difficult and I don't know what pitfalls are associated with it for a beginner. Especially since I have very little experience in front-end development or design.

Decomposing the Rails Tutorial has proven helpful so far - isolating the setup instructions and analyzing the specs - because the tutorial's narrative style can be a bit slow. Important details are found here and there and you have to treasure hunt in order to find them. Basically, it makes it difficult to do anything BUT follow the tutorial in a narrative style.

This can be difficult for more advanced readers who are looking to speed along and even beginners who find themselves looking back for things that they missed. It's likely that the detail they were looking for was hard to spot in the first place, so going back to hunt and peck is tedious.

The Rails Tutorial can be found here and the source code for the finished application can be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment