How to use whitespaces in feature names in Cucumber - ruby

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.

Related

How do I run individual tests on Rails 5 with ruby-test on Atom

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}/"

Ruby Aruba testing can't find command in PATH-variable

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.

How to run several tests in rspec

I run several tests via rspec. The names are test1.rb, test2.rb, and so on. How do I run all of them in a queue and not one by one in the linux console? I tried an
rspec -e"test"
variant, but the console says all examples were filtered out. Please help.
Before I proceed, please note that all specs filename should end with _spec.rb. In your case it should be: test1_spec.rb, test2_spec.rb, and so on. I'd encourage you to checkout RSpec documentation on command line usage. To run all specs which are inside ./spec directory. You can run:
$ rspec .
You can pass --order option to run all specs in random order: $ rspec --order rand. If you want to run particular spec files then you can pass path/to/your/file:
$ rspec spec/test1_spec.rb spec/test2_spec.rb
Please check -e or --example command option, which runs the specs with description passed as argument to -e option for more clarity.

How to use parallel_tests with specific tags

I'm using Ruby + Cucumber + Watir WebDriver to create functional tests for my web project. I've divided my scenarios by priorities using simple tags: #critical, #major, etc. I'm using Rake to run my features. I've created several tasks in my Rakefile.
Now I try to use parallel_tests gem to run my features in parallel mode. I've created special task 'parallel' in my Rakefile:
task :parallel do
'parallel_cucumber features -n 4'
end
My question is: can I parallel my features execution AND use tags at the same time (for example run parallel_cucumber only for "#critical" scenarios in features)?
You can create configuration called "parallel" in your cucumber.yml file and add all of the parameters from the other configurations (for example tags). After that you can run parallel_cucumber and it will use this configuration automatically.
You could try using the -o option. Try something like this:
parallel_cucumber features/ -n 4 -o '-r features -t #critical'
You can even use ENV['tags'] to read from the command line, and pass that to the above inside your task.

Calling Rspec with syntax like ruby -I

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

Resources