DEV Community

Cover image for Can I use RSpec without Rails?
tiff
tiff

Posted on

Can I use RSpec without Rails?

πŸ“Έ Photo by Joshua Fuller on Unsplash

I am working on a static site generator using just Ruby and a few gems.

It seems that testing with RSpec is the way to go, however most tutorials or blog posts associate RSpec with Rails and I don't have, want, or need a Rails component to this; it's just a CLI tool.

My question is can I use RSpec with a pure Ruby CLI tool or should I try something like Minitest instead?

**Oh and maybe someone would be willing to take a look at what I've got?"

GitHub logo twhite96 / static-gen-ruby

A static site generator scaffold built with Ruby

Static Gen

A static site generator built with Ruby.

GitHub commit activity GitHub Maintenance Made with Ruby

How to use:

  1. πŸŒ€ Clone the repo at https://github.com/twhite96/static-gen-ruby.git or with GitHub CLI gh repo clone twhite96/static-gen-ruby
  2. πŸƒ Run: bundle to install dependencies.
  3. 🎊 Have fun with it.

Motivation for this app

I wanted to show that I could build something, even if it was small, on my own, with little guidance.

Ben Halpern started a thread about his generator on DEV and I took his scaffold and ran with it.

πŸ₯ž Stack

Ruby and ruby-handlebars

πŸ‘ŠπŸ½ Wins

Just getting the script running is a win for me, as I am not a Ruby dev at all.

😐 Difficulties

Ruby is a whole other animal compared to JavaScript and React. No semicolons, defining different methods (Ruby is class based, so there are more methods than functions in this instance), etc. I spent a whole month stuck on what this method did:

…
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
faraazahmad profile image
Syed Faraaz Ahmad

You can totally use Rspec for testing your non-Rails CLI! RuboCop does it too, here's an example: github.com/rubocop/rubocop/pull/11...