Last Updated: February 25, 2016
·
2.494K
· rylnd

Turnip Helper

Problem

I love <a href='https://github.com/jnicklas/turnip'>turnip</a>, but I was personally getting tired of typing out rspec spec/acceptance/my_feature.feature whenever I wanted to run tests.

Solution

I whipped up some bash functions to save me some time:

turnips() {
  args=${1:-'*'}
  find ./spec/acceptance -iname "${args}.feature"
}

turnip() {
  files=$(turnips $1 | tr '\n' ' ')
  echo "rspec $files"
  rspec $files
}

Explanation

First, we've got the helper function that finds all relevant turnip feature files:

turnips() {
  args=${1:-'*'}
  find ./spec/acceptance -iname "${args}.feature"
}

And this here's the main function that actually runs the tests (using turnips from above):

turnip() {
  files=$(turnips $1 | tr '\n' ' ')
  echo "rspec $files"
  rspec $files
}

So if your directory looks like this:

└── spec
    └── acceptance
        ├── admin
        │   └── baz.feature
        ├── bar.feature
        └── foo.feature

calling turnip will run all acceptance tests:

rspec ./spec/acceptance/admin/baz.feature ./spec/acceptance/bar.feature ./spec/acceptance/foo.feature

calling turnip foo will run

rspec ./spec/acceptance/foo.feature

and calling turnip baz will run

rspec ./spec/acceptance/admin/baz.feature

Enjoy!

2 Responses
Add your response

What's wrong with using guard? I have 2-3 screens. I code in one, have the docs in another alongside a terminal running Guard (re-runs tests everytime vim/IDE loses focus or you save)

I can see that this is good for running individual features, but Guard only runs the updated files.

over 1 year ago ·

I like the run-when-loses-focus heuristic! I wasn't aware of that.

There's certainly nothing wrong with using Guard. I tend to save habitually, so in my experience I'm usually waiting for a previous Guard run to finish before the run I want to happen occurs.

I prefer to simply run the test when both the code and I are ready, but to each his own.

over 1 year ago ·