Globbing doesn't work with Minitest - Only one file is run - ruby

I have placed all my specs in specs/*.rb.
However, when I run Minitest with ruby spec/**/*_spec.rb, only one file is run.
What gives?

This is not minitest specific, but Ruby. You are effectively running a ruby program which knows nothing about the program being run.
Ruby does not support running multiple files at once afaik, so if you want to get a similar result you could try something like:
for file in spec/**/*_spec.rb; do ruby $file; done
UPDATE: for what you want you should probably create a Rake task as described here

You can use the testrbl third party gem to run multiple Minitest files on the command line. You could also use the mtest bin from maxitest extensions.
Using a for loop in bash will incur overhead of loading your application/library for every test you pass it. If you have just ten tests, and you're testing a Rails app that takes 5 seconds to boot, that's over a minute of totally unnecessary load time.

Related

Trying to understand the error

I was learning about the gem Rspec through a tutorial when this error came up.The last thing I typed in was
$ rspec spec spec\hello_world_spec.rb
I had only installed the Rspec gem and nothing else.
the output message from the cmd
Try to get rid of spec
rspec spec\hello_world_spec.rb
You're passing spec and spec\hello_world_spec.rb as arguments to rspec. These are interpreted as files to run, or directories to search through for files to run. Since you're already running in the spec\ directory, rspec is looking for spec\spec\ and spec\spec\hello_world_spec.rb, which don't exist. Try running that from one directory up (in a typical ruby project, the "root" of your project) and it should run.
i.e. Instead of:
\rspec_tutorial\spec>rspec spec spec\hello_world_spec.rb
try:
\rspec_tutorial>rspec spec spec\hello_world_spec.rb
Also, as #Ursus points out, running rspec spec spec\hello_world_spec.rb is redundant. Rspec will search through spec\ for files to run and will run hello_world_spec.rb automatically since it's under spec. If you only want to run hello_world_spec.rb–which seems to be your intent–then drop the spec from the command, per #Ursus' answer.

How do I easily condense a whole ruby program into one file?

I really like writing command line applications in ruby. However, when working on lots of ruby projects I end up switching between different ruby versions with something like rvm, rbenv or chruby. This means I need to install ruby command line utilities for every version of ruby I work on. I've gotten used to this, but when distributing ruby command line apps to other devs they get confused when running whateverrubyapp that worked in one directory now doesn't work in another directory because the ruby version is different, or even worse they're using gemsets.
Is there an easy way to bundle up a ruby application with all it's dependencies including gems into a single file so that I can just have people put that file in their ~/bin dir so that it behaved somewhat as though it were a compiled application?
For example, I whipped up a little rake task to take a project with no gem dependencies and put it all into one file https://github.com/mmrobins/git-rank/blob/master/Rakefile. However, I have much more complex command line apps that have gem dependencies I would want to include into a single file for easy distribution.

Ruby - watch for file with extension being updated

I am trying to auto compile my less files on centos.
Is it possible in ruby to watch a directory for changes to files ending in a specific extension and then execute a command when that happens?
I have tried inotify in a simple shell script but there are always problems when an ide creates temporary files etc.
You want inotify. A Ruby wrapper, rb-notify, is available.
The ZenTest gem includes the autotest command-line tool, which watches a test directory and runs tests when one of the files changes.
Go look at how that tool works. Using inotify is helpful but not necessary.
The basic idea for this is to write a loop with a sleep inside it. Use Ruby's Find class to locate the files that are candidates for processing. The Find documentation has example code to get that part started.

Ruby minitest-ci gem

The documentation for the minitest-ci gem (seemingly the only option for producing test results for a CI tool such as Jenkins) has the extremely annoying habit of not preserving the results of rake minitest:models when invoked as rake minitest - the test results from running minitest:models are deleted prior to running the rest of the tests. minitest-ci's barely-extant documentation claims adding this to test_helper.rb will disable the troublesome auto-clean behavior, but it doesn't:
# Why do SO and GitHub have to use completely different ways of indicating inline code?
# test/helper.rb
MiniTest::Ci.auto_clean = false
Has anyone out there managed to get minitest-ci to preserve all the test result files? I'm reaching wits' end here.
I think ci_reporter gem supports miniTest. This could be another option.

Ruby Gem Testing Workflow

What is the standard for testing while creating ruby gem?
Do most people run something like guard, or write tests and trigger them manually from the command line?
In Ruby there isn't really a "standard", instead people usually use what works well for them. If you don't like things like guard and prefer to run the tests from the command line, run the tests from the command line.
When I'm coding I run my tests manually from the command-line, but I also have a cron job that will run the tests against the latest commits and email the results every night.

Resources