Writing on spec involves reading the writer’s guidelines of a newspaper or magazine, online or in print, and deciding to submit an article, poem, piece of art work, or story to that publication, according to their guidelines.
The on-spec part is that the piece isn’t guaranteed publication once one sends it. It may be accepted or rejected. That’s the risk the writer or contributor takes in submitting on-spec.
All that hard work and it gets rejected. Well, you try another publisher and another one, until it gets accepted or until one has exhausted the possibilities and you realize that it will never get published as it is. Re-write it, perhaps, and try again.
Submitting on spec is a treadmill at times and it’s hard to write on-spec when you don’t have guarantee it will get published. Writing on assignment is guaranteed but writing on-spec can be a test of a writer’s perseverance when there’s a chance of getting it rejected. Why bother?
But if one can get in the mood to write on-spec, why not? One may get published somewhere along the line. Write it well, send it well. Go well. See what happens.