Unable to get cucumber working with Ruby 2.x under Windows - ruby

When I run cucumber, I get the following messages:
*** WARNING: You must use ANSICON 1.31 or higher (http://adoxa.110mb.com/ansicon) to get coloured output on Windows
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/core_ext/disable_mini_and_test_unit_autorun.rb:3:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:21:in `initialize'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:40:in `new'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:40:in `execute!'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/bin/cucumber:23:in `load'
C:/RailsInstaller/Ruby2.1.0/bin/cucumber:23:in `<main>'
MiniTest::Unit::TestCase is now Minitest::Test. From C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit/testcase.rb:8:in `<module:Unit>'
undefined method `_run_suite' for class `Test::Unit::Runner' (NameError)
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:676:in `<class:Runner>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:261:in `<module:Unit>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:15:in `<module:Test>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:7:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/core_ext/disable_mini_and_test_unit_autorun.rb:25:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:21:in `initialize'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:40:in `new'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:40:in `execute!'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/bin/cucumber:23:in `load'
C:/RailsInstaller/Ruby2.1.0/bin/cucumber:23:in `<main>'
bundle list gives me:
DL is deprecated, please use Fiddle
Gems included by the bundle:
* builder (3.2.2)
* bundler (1.7.7)
* cucumber (1.2.1)
* diff-lcs (1.1.3)
* gherkin (2.11.8)
* json (1.8.1)
* minitest (4.7.5)
* multi_json (1.10.1)
* rspec-expectations (2.11.2)
Based on a similar question on stack exchange, I have the following in `features\support\env.rb':
require 'minitest'
module MiniTestAssertions
def self.extended(base)
base.extend(MiniTest::Assertions)
base.assertions = 0
end
attr_accessor :assertions
end
World(MiniTestAssertions)
What's my next step to getting cucumber working?
Edit:
I've tried running cucumber in a completely empty directory (expecting to get a warning that no features are defined), but get exactly the same message: the warning about minitest, then the error about undefined method '_run_suite'. Evertyhing I can find on the web about this either relates to Rails (which I'm not using) or says it's an old problem that has been fixed, so I'm completely stuck. :(

Any reason why you can't use ruby 1.9 for going through this exercise?
The latest version of the The Cucumber Book - version 3.0 - was released in Mar 2014 when ruby 1.9.3 was the most prevalently used ruby version.
The code for the book was tested with ruby 1.9.3-p194 (as mentioned in Appendix 2 - Installing Cucumber section).
The authors/pragprog may come up with a new edition of the book, and at that time they will ensure the code in the book work with ruby 2.2 or the then most commonly used version of ruby.
It is quite possible to figure out how to make these examples work for ruby 2.0 or higher version, but that is a headache I would recommend you not concern yourself at this time. Given that you are just now starting to learn about cucumber, it would be best to follow the text in the book based on the version it recommends.
After getting familiar with cucumber, and other components of the ruby world, you will appreciate why I find "How do I persuade it to use RSpec?" to be very funny. :-)

As you know, the configuration of your development environment is a tedious and error-prone task. I prefer to work in a *nix-type environment, which you could achieve on your Windows box using, say, VirtualBox or some Docker-for-Windows arrangement.
If you can get such a Docker configuration for Windows up and running, then this may be your best bet to solve the issue quickly, since Docker is all about sharing/reusing pre-configured environments/deployments, which can be a real time-saver! There are already some fine Dockerfile configurations that should help you see which components to install. See: this and that.
BTW, if you prefer to use rspec over minitest (and who wouldn't?), you'll want to use some sample code that doesn't "require 'minitest'". If you only are interested to get the current example working, you might entertain the idea that is given by the error message to "require 'minitest/autorun'". I hope it helps you--good luck!

Related

what does this ruby error with <<~ and &. mean?

reviving and old codebase. installed it in new docker env. when i start the app, i get this error. i'm not a ruby guy, dunno what this <<~ nor &. means. i've already bundle installed from the Gemfile. this app is still running in another environment but I don't have shell access to that environment currently.
WARNING: If you plan to load any of ActiveSupport's core extensions to Hash, be
sure to do so *before* loading Sinatra::Application or Sinatra::Base. If not,
you may disregard this warning.
Set SINATRA_ACTIVESUPPORT_WARNING=false in the environment to hide this warning.
rake aborted!
SyntaxError: /usr/local/bundle/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record/base.rb:22: syntax error, unexpected <<
<<~SQL
^
/usr/local/bundle/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record/base.rb:62: syntax error, unexpected '.'
...veRecord::Base.configurations&.configs_for(name: db)&.config...
... ^
/usr/local/bundle/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record/base.rb:62: syntax error, unexpected '.'
...ations&.configs_for(name: db)&.configuration_hash
... ^
/usr/local/bundle/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record/transaction.rb:1:in `require'
/usr/local/bundle/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record/transaction.rb:1:in `<top (required)>'
/usr/local/bundle/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record.rb:3:in `require'
/usr/local/bundle/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record.rb:3:in `<top (required)>'
/usr/local/bundle/gems/database_cleaner-2.0.1/lib/database_cleaner.rb:1:in `require'
/usr/local/bundle/gems/database_cleaner-2.0.1/lib/database_cleaner.rb:1:in `<top (required)>'
/app/config/environments/shared.rb:9:in `<top (required)>'
/app/tasks/db.rake:2:in `require_relative'
/app/tasks/db.rake:2:in `block in <top (required)>'
/usr/local/bundle/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
Tasks: TOP => dl:start:all => dl:start:job_queue => dl:start:queue => environment
(See full trace by running task with --trace)
As engineersmnky already pointed out in the comment, both operators – the squiggly heredocs (<<~) and the safe navigation operator (&.) – were introduced in Ruby version 2.3. This means your application needs at least Ruby 2.3 and does not support older versions.
At the same time, when updating your Ruby environment to the latest version, your application complains about Fixnum and Bignum missing. Both classes were deprecated in Ruby 2.4 and removed shortly after. That means your application doesn't support Ruby 2.4 or above.
That said: It looks like your application is only able to run against Ruby 2.3. I suggest installing the latest Ruby 2.3 version which is 2.3.8 and try again.
Please note that even the 2.3.8 version is already more than two and a half years old and that Ruby 2.3 reached end-of-life, is unmaintained, and will not get any bug fixes or security updates anymore. Even if your application worked with Ruby 2.3.8, I highly recommend updating it to Ruby 2.7.3 or – even better Ruby 3.0.1

Why gem is not loaded: require gems gives error no such file

I installed gem 'ssh-net'. From the console I tried to require the gem like this:
irb(main):009:0* require 'ssh-net'
LoadError: cannot load such file -- ssh-net
from /var/lib/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from /var/lib/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `block in require'
from /var/lib/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:240:in `load_dependency'
from /var/lib/gems/2.3.0/gems/activesupport-4.2.10/lib/active_support/dependencies.rb:274:in `require'
from (irb):9
from /home/csrhub/git/csrhub-api/bin/console:150:in `<top (required)>'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:63:in `load'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:63:in `kernel_load'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli/exec.rb:28:in `run'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:476:in `exec'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:30:in `dispatch'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/cli.rb:24:in `start'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/exe/bundle:46:in `block in <top (required)>'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
from /var/lib/gems/2.3.0/gems/bundler-2.1.1/exe/bundle:34:in `<top (required)>'
from /usr/local/bin/bundle:23:in `load'
from /usr/local/bin/bundle:23:in `<main>'
Then I tried with a gem that works:
irb(main):023:0* require 'memcache'
=> false
I printed the gems locations:
csrhub#csrhub:~/git/csrhub-api$ bundle info 'net-ssh'
* net-ssh (5.2.0)
Summary: Net::SSH: a pure-Ruby implementation of the SSH2 client protocol.
Homepage: https://github.com/net-ssh/net-ssh
Path: /var/lib/gems/2.3.0/gems/net-ssh-5.2.0
csrhub#csrhub:~/git/csrhub-api$ bundle info 'memcache'
* memcache-client (1.8.5)
Summary: A Ruby library for accessing memcached.
Homepage: http://github.com/mperham/memcache-client
Path: /var/lib/gems/2.3.0/gems/memcache-client-1.8.5
csrhub#csrhub:~/git/csrhub-api$
I see that both gems are placed in the same directory. Why memcache is invokable and the ssh-net is not? What am I missing?
May be it has something to do with this ?
I installed gem 'ssh-net'.
No, you didn't. You installed the gem net-ssh, as you can clearly see in the output of bundle info that you posted:
csrhub#csrhub:~/git/csrhub-api$ bundle info 'net-ssh'
* net-ssh (5.2.0)
Summary: Net::SSH: a pure-Ruby implementation of the SSH2 client
Here you can see that the name of the gem is net-ssh and not ssh-net and that the name of the primary class is Net::SSH.
From the console I tried to require the gem like this:
irb(main):009:0* require 'ssh-net'
LoadError: cannot load such file -- ssh-net
The primary class in this gem is called Net::SSH. (It integrates in the Net namespace of the Ruby standard library, which has libraries like Net::FTP, Net::HTTP, Net::IMAP, Net::POP, Net::SMTP, and Net::Telnet.)
According to standard Ruby naming conventions, a class named Net::SSH should be located in a file named lib/ssh.rb. This is the file you need to require.
This is also shown in the very first line of the very first code sample of the very first page of the documentation:
require 'net/ssh'
I see that both gems are placed in the same directory. Why memcache is invokable and the ssh-net is not? What am I missing?
In 99.9% of all cases where a computer tells you it cannot find something, it is because that thing you told it to find is indeed not there. Computers are very, very good at finding things.
The same thing is the case here: you told Ruby
require 'ssh-net'
which means "go through each directory in the $LOAD_PATH and look for a file named ssh-net.rb". Such a file simply does not exist, ergo, you get a LoadError exception.

Cannot run rspec anymore

I had ruby 2.0 with rspec 3.0. I uninstalled all rspec 3.0 gems and replaced them with 2.0. I did this to get rid of deprecation warnings. Now, my specs are not working. I am getting the error below. What does the error tell me and how do i fix it ? None of the stack overflow posts on this were helpful.
/zombie/spec/spec_helper.rb:29:in `block (2 levels) in <top (required)>': undefined method `include_chain_clauses_in_custom_matcher_descriptions=' for #<RSpec::Matchers::Configuration:0x00000001a73928> (NoMethodError)
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:398:in `expect_with'
from /home/lsusr/Code/Rspec/zombie/spec/spec_helper.rb:21:in `block in <top (required)>'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core.rb:92:in `configure'
from /home/lsusr/Code/Rspec/zombie/spec/spec_helper.rb:17:in `<top (required)>'
from /home/lsusr/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/lsusr/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `block in requires='
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `map'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `requires='
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:20:in `block in configure'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `each'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `configure'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:21:in `run'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
Okay, I found a fix.
I just removed all the unnecessary gems using
for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
Then, I just reinstalled rspec using gem install rspec which gave me rspec 3.0 and fixed all the problems. But, i get the deprecation warnings again.
Please tell me why the error occurred. The tutorial author said that it should work with rspec 2.10.0 or higher.
The tutorial author said that it should work with rspec 2.10.0 or higher.
Likely the author meant 2.10 or higher, within the 2.x range. RSpec 3.x has breaking changes.
Try uninstalling the gems like you did before, then this:
gem install rspec '>=2.10', '<3'
Then run your code.
The deprecation warnings that happen when you use RSpec 3 are not bad; they are coaching to tell you that the RSpec methods that you are calling are going to be phased out. These kinds of warnings are typical and fine when moving an entire version number e.g. 2.x to 3.x.
The errors you get when you use RSpec 2.0 are because that's a very old version, and the method you're calling didn't exist in 2.0. This is probably why the tutorial author said to use 2.10 or higher.
Most likely the tutorial is out of date, so the best solution is to wrote the tutorial author and let him/her know to update it.
If you're curious about how RSpec does its version numbers, here's a link to Semantic Versioning.

Ruby version errors / crack/xml in irb

Because of a bug with Float#round in Ruby 1.8.6, I was forced to upgrade to 1.9.3 and boy was that awful. After install, irb didn't work, complaining of a lack of psych. So I tried to install the gem, but it was angry that libyaml didn't exist, so I installed that. Not sure why they weren't included if they were so important.
Now when I use require 'Location.rb' (after having to specify that I actually do want to look in the current folder... using $LOAD_PATH), I get this error:
LoadError: cannot load such file -- crack/xml
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/ap-0.1.1/lib/ap.rb:2:in `<top (required)>'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/tyre77/Dropbox/Aurora/GMap.rb:4:in `<top (required)>'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):3
from /usr/local/bin/irb:12:in `<main>'
What does this mean? Also, when I execute ruby -v, it lists my version as 1.9.3p0 but this is dicking around in 1.9.1? All I want is my irb back and working!
It turned out that Ruby was looking for an XML parser called 'crack'. I don't know why it is referencing 2 versions of Ruby or why these dependencies aren't included in the Ruby build (since irb won't work without them) but to fix I installed the crack gem. sudo gem install crack
you can use
require_relative 'Location.rb'
or
require './Location.rb'

Inability to find a required service_manager gem

I'm working on some cucumber tests from The Cucumber Book. I've got the code that tries to use a transaction processor and there is a file with the following code:
require 'service_manager'
ServiceManager.start
This is on Mac OS X 10.6.8 using Ruby 1.9.2. When this file executes, I get the following:
no such file to load -- service_manager (LoadError)
/opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
/opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
/opt/local/lib/ruby1.9/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/Users/gpollice/MyCucumber/ATMBookExample/features/support/services.rb:6:in `<top (required)>'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/cucumber-1.1.2/lib/cucumber/rb_support/rb_language.rb:143:in `load'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/cucumber-1.1.2/lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/cucumber-1.1.2/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/opt/local/lib/ruby1.9/gems/1.9.1/gems/cucumber-1.1.2/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
The service_manager gem is installed in /opt/local/lib/ruby1.9/gems/1.9.1/gems as are other gems that the application uses. Until I added the code for this iteration, there were no problems. I've looked for reasons why the gem is not found and just can't figure out why. Any help would be appreciated.
It appears to be a load path issue.
Is require "rubygems" invoked prior to this require statement?
Also, if you're using bundler, you have to add this gem to your Gemfile, as bundler attempts to sandbox your dependencies. If you're using bundler, try the following after adding the gem to the Gemfile:
bundle exec rake cucumber

Resources