Reputation: 3405
I decided to try out MiniTest and noticed pretty quickly that it supported something called "specs". I had seen these referenced before but thought it was just an alternate test syntax associated with factories, but if that were the case then why would MiniTest need to support them both?
We only covered tests when I was taught Ruby on Rails, so I don't really know anything about specs. When I Google specs I find a lot of stuff about how to write good ones but nothing explaining what they are. What's the difference between tests and specs?
Upvotes: 69
Views: 54725
Reputation: 28928
In practice, there is 1 difference I see too often in projects.
Developers joining a project using *.spec.[ts/js]
ask where are the "test files". It would be much clearer if test files are called test files.
When writing tests, I say "I wrote a test", not "I wrote a specification". "Writing tests". Unit testing, system testing, integration testing, smoke testing... Not smoke specification 🤔, "system specification" (confusing?), "integration specification". This is also confusing when you work on projects with actual specifications, e.g. ably specification.
Upvotes: 7
Reputation: 2665
A spec, short for specification, comes from behavior driven testing, and encourages the mindset where you are defining 'what' the software does.
Calling it a test leads to a much more general way of thinking about the code, and does not reinforce the idea that you should be testing the interface (instead of the implementation) as well.
That said, regardless of how you write them, or what you call them, the point is to have an automated way of verifying the correctness of your code, so that you can proceed with confidence.
Upvotes: 104
Reputation: 1293
Google for tests vs. Specs. Some good reads pop up:
My opinion is, that specs read more 'natural' and feel more like true specifications of the functionality of the code when compared to mini-test et.al.
Rspec is a good example of a DSL, specifically written to write tests that make sense when read, even for people less technically inclined.
But in the end, use whatever makes you feel more comfortable. A test written is almost always better then no test written, because you feel uncomfortable using the testing framework
edit
After rereading your question, you seem to specifically ask about mini-test specs. It is an addition to minitests which adds rspec-like syntax to minitest. Everything above still applies.
Upvotes: 41