0

I'm doing a coding challenge and have a simple 1 file ruby program (e.g. processor.rb) that accepts arguments via a file passed on the command line, like so:

$ ruby processor.rb < inputs.txt

I'm fairly lost with how to implement tests (I'm used to having it all ready to go in a Rails app). Do I add them to the same file (processor.rb)? Do I create a separate test file and run that with a separate command?

Any help much appreciated. On the surface this might seem similar to this question but none of those answers are what I'm looking for.

2
  • As a matter of convention, you'd make a directory spec, and in it processor_spec.rb; but it is not a law. Commented Jul 14, 2015 at 8:24
  • You can use aruba-rspec Bridge RSpec and Aruba/ArubaDoubles to test command-line tools Commented Jul 14, 2015 at 8:24

1 Answer 1

1

There are a few ways of doing it, but this is what I do. Run rspec --init in the top level directory of your project, which will create a spec directory containing a spec_helper.rb file. It also creates a .rspec hidden file in your top level directory, which will automatically require your helper when running rspec.

You can then start creating spec files in the spec directory. By convention, files are named <subject>_spec.rb. For example, if you have a class called FileTree (and therefore a file named file_tree.rb), your corresponding spec file will be file_tree_spec.rb.

You can organise your specs in directories - it makes no difference. However, I tend to mimic the structure of the code that I'm testing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.