I'm teaching myself the basics of how to make my own Ruby Gem using Bundler's guide. However when I get to setting up CLI tests with aruba/cucumber I keep running into a problem:
Command "co2domain" not found in PATH-variable "C:/.../PATH variables". (Aruba::LaunchError)
The only differences I made is to change some of the names of the example as I'd eventually like to build a gem that converts company names to their proper domains.
Here is my company.feature file:
Feature: Company
In order to portray Company
As a CLI
I want to be as objective as possible
Scenario: Positive number
When I run `co2domain portray --num 2`
Then the output should contain "positive"
Scenario: Negative number
When I run `co2domain portray --num -22`
Then the output should contain "negative"
This is my company.rb file:
module Co2domain
class Company
def self.portray(num)
if num > 0
"positive"
else
"negative"
end
end
end
end
As I am a beginner and the guide is for beginners I feel like I'm missing something small but important. Help appreciated.
The error you are seeing is equivalent to the sh: foodie: command not found error found in the guide you are using. The difference is you are using a windows machine, and the guide is using a *nix machine.
The cucumber tests are testing running a command from the shell, and the shell is not able to find the command to run. If you add the directory your program is in to your PATH, or move your program to a directory in your path, cucumber should be able to run it.
Related
When I left my company I also lost my license to RubyMine so I started working with Atom. One feature I really missed from RubyMine was the ability to run individual tests directly from the editor.
After poking around a bit I found a library for Atom that accomplished this: https://atom.io/packages/ruby-test
This package is great, except I found that whenever I ran a test that had spaces in the name, the test wouldn't actually run.
How can I get the package to run tests that have spaces in their name?
The command the package was using was:
ruby -I test {relative_path} -n "/{regex}/"
If you go into the settings, you can modify this to use TESTOPTS which supports spaces in the names:
ruby -I test {relative_path} TESTOPTS="-n /{regex}/"
I am using Windows and trying to run an existing feature pack which was initially built on Mac OS which allows them to get around the issue with using " \ " with the whitespace.
I am using Ruby 2.2.3 and Cucumber.
The feature names contain white spaces and I am unable to change this. I tried to use " " and ' ' to get around the white spaces but have the same issue each time.
Here is an example of the issue. If I run:
cucumber features/'Name containing whitespaces.feature'
it works OK.
But when I run:
cucumber -p my_profile
and cucumber.yml contains:
my_profile: features/'Name containing whitespaces.feature'
Then it fails with:
No such file or directory - features/'Name. You can use `cucumber --init` to get started.
Can anyone help me get round this issue as renaming is not an option in my case.
You can test specific features using Cucumber's # tags. I like using #wip, which stand for work in progress. For Example
In login.feature
Feature: Log in
#wip
Scenario: Successful Login
Given I do some things
Then I should be logged in
Then in the terminal you would run
cucumber --tags #wip
and it will only run the tests under that scenario or feature.
This will allow you to test specific features or scenarios in cucumber without having to worry about the whitespacing in the names.
This seems simple but I can't find a reputable solution via Google or searching SO.
I'm using foreman with a Rails 4 app to load ENV via a .env file. To run my tests properly, I have to execute foreman run rspec [optional files].
This gets tedious and occasionally I forget the foreman run part. I'd like to override the rspec command for a single app so that:
rspec [files] => foreman start [files]
Looked at binstubs but I don't fully understand them and they don't look exactly like what I want.
I can create a bash script that does this, but now that's specific to my local machine instead of built into the app codebase.
I ended up creating a script in my ~/scripts folder (where I store my own scripts added to my PATH).
Here's what I have in ~/scripts/tester (with executable permissions):
#!/bin/bash
#==================================================
# Created: 2014-04-01 / Updated: 2014-04-01
# Desc: Shorten syntax to run tests properly.
#==================================================
# For developers who may not use bash at all...
# $0 = filename and path
# $1 = first arg...
cmd="foreman run rspec $1"
echo "#--------------------------------------------------"
echo "# EXECUTING: $0"
echo "# '$cmd'"
echo "#--------------------------------------------------"
$cmd
I can execute with tester in my rails app directory and it will run foreman run rspec which executes all tests or I can pass in specific files or wildcard-names and it will run the matched tests.
It outputs the file location so if I pass this script on to others they know what files being run so they can modify it...I do this because I've actually run into a situation where a new developer was Googling a "tester" script for rails wondering why he couldn't find it as part of core rails...this way newbies know exactly what's being run and where the file's located at.
Chose tester as the script name because it wouldn't clash with any other known commands AFAIK.
Sample input:
tester => foreman run rspec # all specs
tester spec/models => foreman run rspec spec/models # run all model specs
How to find files in a directory which were edited in last n minutes?
In unix which is -mmin -60.
In host
ruby /home/ava/test works fine!
Net::SSH.start('host', 'ava') do |ssh|
`ruby /home/ava/test`
end
gives ruby: No such file or directory -- /home/ava/test (LoadError)
You could get a list of files using Dir.[], and use File.mtime on each one to filter them:
Dir["*"].select { |fname| File.mtime(fname) > (Time.now - 60) }
The problem with your code is that Ruby isn't control on the remote system you connect to, instead, the shell on that system is, and you're merely able to issue commands, as if you'd ssh'd into your own local system. Ruby's built-in commands, like Dir.chdir only apply locally, not to the remote session.
Your best bet is to write a script you execute that resides on that system, otherwise the task of executing commands becomes more difficult and you'll need to anticipate prompts and possibly various responses from commands on that system as your code executes things.
The Net::SSH gem includes examples showing how to issue remote commands; You need to remember that once you've connected you're issuing commands to the shell, not to Ruby.
Net::SSH.start('host', 'ava') do |ssh|
`ruby /home/ava/test`
end
gives ruby: No such file or directory -- /home/ava/test (LoadError)
The best way to diagnose this is to start by SSHing to your own local box and executing the code locally, or using surrogate code that only echoes the commands you'd be using in real life on the other machine. Then you can test to see if the actions would be called.
Instead of:
ruby /home/ava/test
issue a command like:
ls -al /home/ava
first, to see what files are visible.
Follow that with something like:
ruby -pe '%x(ls /home/ava)'
to see if Ruby is found and it can execute that command in the path.
Dealing with remote systems isn't the same as running scripts locally. Your environment can be different, meaning your PATH or variables you expect might not be the same.
I am trying to use https://github.com/rifraf/Vendorize which is run using a command like
D:\projects\SomeLibrary\lib>ruby -I..\..\Vendorize\lib -rvendorize some_lib.rb
It does something clever where it intercepts required files and logs them, but only the ones that get executed in your command line. On it's documentation pages it says
You can run the program several times with different options if the
required files depend on the options.
Or just run your tests…
I want to run all the tests with the -I function from the command line above, so that all the different avenues of code are run, and the libraries loaded (and logged). Given that I can run them like:
D:\projects\SomeLibrary\lib>rspec ..\spec\some_spec.rb
How do I do this? Thanks!
NB: I am a/ a ruby newbie and b/ running windows
I would try writing something like this at the top of some_spec.rb:
require_relative '..\..\Vendorize\lib\vendorize'
You might need to change that a bit depending on what your working directory is.
Then just runs your specs with rspec as you normally do without any extra commands.
If that doesn't work, then locate the rspec.rb executable and run:
ruby -I..\..\Vendorize\lib -rvendorize path/to/rspec.rb ..\spec\some_spec.rb