- loading...
hash bang cucumber
I don’t know if this is a good idea or not, but often I just wish I could copy and paste a cucumber feature file into the command line and have it just run the frigging scenarios without having to prefix it with “cucumber”.

Perhaps I’m a bit delirious but I think it would be fun to paste features/112_users_crud.feature into the console and it would run the scenarios:
$ features/users_crud.feature
instead of having to always do the extra key strokes:
$ cucumber features/users_crud.feature
Solution?
Two steps:
- At the very top of each feature file add:
#!/usr/bin/env cucumber - Run
chmod +x features/*.feature
Shazam!
Hash bang me up!
To apply this to all your feature files, jump into script/console or irb and run the following code within your project:
Dir["**/*.feature"].each do |feature|
contents = File.read(feature)
File.open(feature, "w") do |f|
f << "#!/usr/bin/env cucumber\n\n"
f << contents
end
`chmod +x "#{feature}"`
end
Related posts:
- Cucumber: building a better World (object) How to write helper libraries for your Cucumber step definitions...
- Testing outbound emails with Cucumber My testimonial for Cucumber still stands even in 2009....
[...] This post was mentioned on Twitter by eladmeidar. eladmeidar said: 1. hash bang cucumber 2. … 3. profit! http://bit.ly/BwvzJ (via @drnic) [...]
Alternatively or additionally, you could alias cucumber to ‘c’ or ‘cu’ in your shell environment.
seems dangerous… how about an alias for cucumber? I have ‘cuke.’
Danger is one of my middle names. Another middle name is “um, that looks unnecessary”.
Yes, the ‘c’ alias might be better.
No no no, I love pasting and hitting return. Oh I love it so.
Very nifty!
I’ve been using another approach (as I was keen to keep the feature files pure). I created a formatter which extends the pretty formatter but in the comment line it outputs:
Scenario: We like cukes #c features/blah.feature:20
Where c is aliased to cucumber.
with zsh: alias -s feature=”cucumber”
I did something similar using Fish Shell. I’ve whipped up a blog post explaining it for anyone who uses Fish. Instead of making each feature file executable, it does the equivalent of Ruby’s “method_missing” — if a command given to fish isn’t runnable it’ll call a special script (which you write) which can then decide what to do.
Here’s the blog post: http://bjeanes.com/2009/10/07/using-fish-shells-event-system-to-behave-like-method-missing
Very cooool
In Windows
>assoc .feature=CucumberFile
.feature=CucumberFile
>ftype CucumberFile=C:\ruby\bin\cucumber.bat %1
CucumberFile=C:\ruby\bin\cucumber.bat %1
>features\users_crud.feature
Alias are good but you still need to type features/foo.feature
I used this function that I called cu in zsh
cucumber features/$1.feature:$2
in order to run the line 6 of the foo feature I just write
cu foo 6
Pasting and hitting return? Drag & drop FTW!
Nice tip. Simple. Love it.
Maybe I’m missing something but it seems to me the easiest is to hit Command-R from textmate (if you have the cucumber bundle). I guess this requires you to be in the feature file though…