Unit test runs three times - ruby-on-rails

I'm trying to run a single unit test in my Rails app, I'm using the following command to run the test (say my model is users)
rake test TEST=test/unit/user_test.rb
It runs with out a problem, but for some reason it runs three times; can anyone explain me why is that and if I'm doing something wrong above? Following is my gem env, and I'm using Rails 2.3.2.
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/sameera/.rvm/gems/ruby-1.8.7-p357
- RUBY EXECUTABLE: /home/sameera/.rvm/rubies/ruby-1.8.7-p357/bin/ruby
- EXECUTABLE DIRECTORY: /home/sameera/.rvm/gems/ruby-1.8.7-p357/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/sameera/.rvm/gems/ruby-1.8.7-p357
- /home/sameera/.rvm/gems/ruby-1.8.7-p357#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/

In a rails app rake test runs 3 subtasks, test:units, test:functionals, test:integration.
Each of those tasks just runs all the tests from the corresponding folder, but your environment variable overrides that search process and so the same file is found each time.
You could either do
rake test:units TEST=...
or
ruby -I test test/unit/user_test.rb

Related

No rails in ubuntu whem i "cd" to project dir

I lose my patience to rails on ubuntu. So far I have used the ready environment on c9, but it is slowly closing. I'm learning how to deal with rails and I have a problem with Ubuntu.
I use tutorials (many) to install it. Finally, I did it, and I created a small project. One page + one model + one controller. Commit, exit, turn off a notebook.
Today when I want to back to programming I opened a terminal and go to project dir /Desktop/Projc/test. And after typed rails s I got the message:
Command 'rails' not found, but can be installed with:
sudo apt install ruby-railties
And what is weird, If I open a terminal in home dir rails are ok. I can create a new project etc. But in the existing project rails "are not installed".
I spent a few hours to look for a solution, reads many posts (so: 10918685, 7788946, 16884034) but nothing help.
I'm afraid that I just did a bigger mess.
Can someone try to help me with my case?
My configs:
gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.1
- RUBY VERSION: 2.6.1 (2019-01-30 patchlevel 33) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/iso/.rvm/gems/ruby-2.6.1
- USER INSTALLATION DIRECTORY: /home/iso/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /home/iso/.rvm/rubies/ruby-2.6.1/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /home/iso/.rvm/gems/ruby-2.6.1/bin
- SPEC CACHE DIRECTORY: /home/iso/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /home/iso/.rvm/rubies/ruby-2.6.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/iso/.rvm/gems/ruby-2.6.1
- /home/iso/.rvm/rubies/ruby-2.6.1/lib/ruby/gems/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/iso/.rvm/gems/ruby-2.6.1/bin
- /home/iso/.rvm/gems/ruby-2.6.1#global/bin
- /home/iso/.rvm/rubies/ruby-2.6.1/bin
- /home/iso/.rvm/bin
- /home/iso/.rbenv/plugins/ruby-build/bin
- /home/iso/.rbenv/shims
- /home/iso/.rbenv/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
- /snap/bin
echo $PATH:
/home/iso/.rvm/gems/ruby-2.6.1/bin:/home/iso/.rvm/gems/ruby-2.6.1#global/bin:/home/iso/.rvm/rubies/ruby-2.6.1/bin:/home/iso/.rvm/bin:/home/iso/.rbenv/plugins/ruby-build/bin:/home/iso/.rbenv/shims:/home/iso/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
rails -v: 5.2.3
ruby -v: 2.6.0p0
Can someone see a solution? And in the terminal, I have a checked a "run as start shell".

cap command not found [Cygwin + Capistrano]

I've installed ruby, rubygems and rails through Cygwin setup.
Then I've installed a gem:
gem install capistrano --verbose
No problem here. But when I try to run cap command, Cygwin tells me:cap: command not found
When I execute in ./bin/cap it works:
$ ./bin/cap
Stage not set, please call something such as 'cap production deploy', where production is a stage you have defined.
Here is my gem environment:
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.1
- RUBY VERSION: 2.0.0 (2014-11-13 patchlevel 598) [i386-cygwin]
- INSTALLATION DIRECTORY: /home/Moretti/.gem/ruby
- RUBY EXECUTABLE: /usr/bin/ruby.exe
- EXECUTABLE DIRECTORY: /home/Moretti/bin
- SPEC CACHE DIRECTORY: /home/Moretti/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86-cygwin
- GEM PATHS:
- /home/Moretti/.gem/ruby
- /usr/share/gems
- /usr/local/share/gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /usr/bin
- /cygdrive/c/Program Files (x86)/Intel/iCLS Client
- /cygdrive/c/Program Files/Intel/iCLS Client
- /cygdrive/c/WINDOWS/system32
- /cygdrive/c/WINDOWS
- /cygdrive/c/WINDOWS/System32/Wbem
- /cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0
- /cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/DAL
- /cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/IPT
- /cygdrive/c/Program Files (x86)/Intel/Intel(R) Management Engine Componen ts/DAL
- /cygdrive/c/Program Files (x86)/Intel/Intel(R) Management Engine Componen ts/IPT
- /usr/bin
The EXECUTABLE DIRECTORY is correct, but the binaries aren't working outside the ~/bin/.
What can I do?
I created a cap file in /usr/local/bin/ and made it executable.
$ cat /usr/local/bin/cap
#!/bin/bash
ruby ~/.gem/ruby/gems/capistrano-3.3.5/bin/cap "$#"
Location of capistrano gem files can be found using gem which capistrano.
I personally do not know if this is the best way of doing it, but I've just set it up yesterday and have managed to get it working for my usecase

Ruby Rails webrick server using old version of ruby

ruby -v give me ruby-1.9.3-p194.
which ruby gives /home/ubuntu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
rails -v gives Rails 3.2.7
which rails gives /home/ubuntu/.rvm/gems/ruby-1.9.3-p194/bin/rails
"sudo bundle exec rails s" gives:
ubuntu#ip-10-117-73-5:~/ruby/users$ sudo bundle exec rails s
=> Booting WEBrick
=> Rails 3.2.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-09-11 20:13:08] INFO WEBrick 1.3.1
[2012-09-11 20:13:08] INFO ruby 1.8.7 (2011-06-30) [i686-linux]
[2012-09-11 20:13:08] INFO WEBrick::HTTPServer#start: pid=4240 port=3000
rvn info gives me:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [i686-linux]
- INSTALLATION DIRECTORY: /home/ubuntu/.rvm/gems/ruby-1.9.3-p194
- RUBY EXECUTABLE: /home/ubuntu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
- EXECUTABLE DIRECTORY: /home/ubuntu/.rvm/gems/ruby-1.9.3-p194/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/ubuntu/.rvm/gems/ruby-1.9.3-p194
- /home/ubuntu/.rvm/gems/ruby-1.9.3-p194#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
However when I run rails server I see below.
[2012-09-11 18:19:53] INFO ruby 1.8.7 (2011-06-30) [i686-linux]
I have no clue where this is coming from.
I have done "bundle install" and "bundle update" and a whole slew of things - it still is using the wrong ruby version. What do I need to do?
EDIT:
$PATH variable also only shows me 1.9.3 relevant information, how the heck is Webrick getting 1.8.7! If I remove that folder - it just doesn't start at all
Well seems what i needed was
rvmsudo rails server
I am just now learning when to use sudo and when not to - this was a painful experience.
Problem was that 1.8.7 was installed for sudo - while everything else was right for my user. But since I couldn't run 'rails server' by itself due to my previous incorrect installation, i had to use 'sudo rails server' - which ended up using the older ruby version.

Command Not Found even after changing path variable

Using heroku for deployment while learning Rails with the Ruby On Rails tutorial by Michael Hartl, on Ubuntu 11.04 Natty Narwhal. I installed it using
sudo gem install heroku
and the commands seemed to run fine for that session in the terminal. The next time I went to work, I tried the command "heroku open" and I was told "heroku: command not found". Looking at some of the answers to similar problems here, it seemed the answer was to run
gem enviroment
which returned the following:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /var/lib/gems/1.8
- /home/richard/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I then ran
$ export PATH=$PATH:/var/lib/gems/1.8/bin
which seemed to fix the problem. However, the next time I tried to run heroku in the terminal, I was told "command not found" again! Running the "export PATH=$PATH" command seems to fix the problem every time, but I would rather I didn't have to run this command everytime I want to use heroku. Is there any permanent solution to the problem?
If you're using bash as your shell, then add that export line to .bash_profile in your home directory. The equivalent for zsh is .zshrc, and other shells have their own files to automatically load for every shell session.

Thin HTTP WebServer on Windows

I'm currently trying to get Thin webserver running on Windows, to form a basic cluster behind a NGINX proxy, but this is proving to be rather difficult.
I was wondering if anyone actually succeeded in getting this up and running?
To give some examples of the things I have tried:
C:\Users\arne.de.herdt.TENFORCE2\RubymineProjects\ESCO>thin start
C:/Ruby/lib/ruby/site_ruby/1.9.1/rubygems.rb:926:in `report_activate_error': Rub
yGem version error: thin(1.2.11 not >= 0) (Gem::LoadError)
from C:/Ruby/lib/ruby/site_ruby/1.9.1/rubygems.rb:244:in `activate_dep'
from C:/Ruby/lib/ruby/site_ruby/1.9.1/rubygems.rb:236:in `activate'
from C:/Ruby/lib/ruby/site_ruby/1.9.1/rubygems.rb:1307:in `gem'
from C:/Ruby/bin/thin:18:in `<main>'
I really don't get this error message. I've included below the environmental output of my system that I'm trying this on (my development system)
RubyGems Environment:
- RUBYGEMS VERSION: 1.7.2
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: C:/Ruby/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/Ruby/lib/ruby/gems/1.9.1
- C:/Users/arne.de.herdt.TENFORCE2/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Hoping someone has been experimenting with this.
Also I must say that it's starting to annoy me that the lack for Windows support is such a serious issue with Ruby on Rails. I really enjoy the language and programming in it, but it's a pain getting things to work on Windows machines because of uncompilable dependencies...
Thin ain't supported under Windows.....

Resources