![]() The reason feature specs are time-consuming to write is that, unlike a model spec where you can exercise e.g. (It’s slower to have to bring up a web browser than to not have to.) Feature specs are also relatively time-consuming to write. Feature specs are relatively time-consuming to run because you’re running more stuff than in a model spec. There’s a cost to this, though, in that feature specs are relatively “expensive”. Unlike model specs, feature specs do tell you whether all the parts of your application are working together. The strengths and weaknesses of feature specsįeature specs have basically the opposite pros and cons. In such a case the model specs could pass even though there’s no working feature built on top of the model code. You can understand what I mean if you imagine a Rails model that works perfectly by itself but doesn’t have have any working HTML/CSS/JavaScript plugged into that model to make the whole application work. A disadvantage of model specs is that they don’t tell you anything about whether your whole application actually works from the user’s perspective. It tends to be slower to actually load the pages of an application and switch among them than to just test model code by itself with no browser involved. Compared to feature specs, model specs are relatively fast to run and relatively fast to write. The strengths and weaknesses of model specsĪn advantage of model specs is that they’re “inexpensive”. Neither type of spec is better or worse (and it’s not an “either/or” situation anyway), the two types of specs just have different strengths and weaknesses in different scenarios. Speaking loosely, model specs test ActiveRecord models by themselves and feature specs test the whole “stack” including model code, controller code, and any HTML/CSS/JavaScript together. What are model specs and feature specs for, and what’s the difference? Feature specs and model specs Let’s focus on these two types of specs for a bit. There are two types of tests I use way more than any other types of specs: model specs and feature specs. Some types of specs I never use at all (e.g. I asked myself: Why do these different types of tests exist? Do I need to use all of them? Are some more important than others?Īs I’ve gained experience with Rails testing I’ve come to believe that yes, some types of tests (or, to use the RSpec terminology, “specs”) are more important than other types of specs and no, I don’t need to use all of types of specs that RSpec offers. I encountered terms like “model spec”, “controller spec”, “view spec”, “request spec”, “route spec”, “feature spec”, and more. When I started learning about Rails testing and RSpec I discovered that there are many different kinds of tests. Where to go next What exactly are integration tests? The many different types of RSpec specs Part 2: A Rails Integration Test Tutorial ![]() What do I write integration tests for, and how? What’s the difference between integration tests, acceptance tests, end-to-end tests, system tests, and feature specs? Part 1: Common Integration Test Questions
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |