How to turn off rails 3.1 verbosity in test unit - ruby-on-rails

I am trying to run rails tests in the old fashion i.e. dots as output but think I am missing something. I cant find where to turn off the verbosity mode and every time I run a rake task I get a list of test descriptions which at first look nice but end up being quite boring and not very helpful.
How can I turn off rails test unit verbosity mode and get back to old ....F....E..... ?
Thanks,

Remove the turn gem from your Gemfile.

Related

How to convert rails app to test files?

I like to create rspec test from working rails 5 app.
It' could be template to work on.
For example:
-scaffold will create test files template which is nice.
-Or simplecov to help increase test ratio (if I understand correctly)
-So if any tools that could run through each line of controller method and re-create each expected/result put in the test file.
Are there any gem or solution ?
Why ask this question?.
I understand this is not a purpose of test. However test is to save time in future and now as well. Many rails app don't have test, and to go back each line of running code will cost again, assuming the app is good at this stage. If we can have all test at this point and use it to control / run for future development that would be good
I found another gem that answer my question
rspec-kickstarter
But to use with Rails 5 it need to edit the path that created.

How can I decrease my Rails test overhead?

I'm using Test::Unit on a large app with a large number of gem dependencies (>75). I'm trying to develop using BDD, but it takes minutes for the app to load it's dependencies before it can run the tests. Is there a way to preload the dependencies and just auto-run the test on changes, or a similar solution?
I would look into Spork. It works wonders.
https://github.com/sporkrb/spork
https://github.com/sporkrb/spork-testunit
I am using RSpec and there's a great tool for it, called Spork. It basically loads your app once and then just reloads modified parts. If you combine it with Guard, you get "continuous testing". That is, you hit 'Save' in your editor and tests start executing, giving you instant feedback. This still amazes me after some months :)
Edit
As #THEM points out, there's a plugin for Spork to support TestUnit. You should look into it.
There was also an interesting article about test speed on the 37Signals blog a while back. Might be of interest even if you end up going with Spork or another solution.

rubymine only able to run model tests one by one

I am able to right-click on any of my 3 spec/models but when I right click the spec/models folder and select 'run all tests in models' I get 'Unable to attach test reporter to test framework'.
The first line of my model tests is: require 'spec_helper.rb'
I posted this answer for another question. It may help with this one as well:
On my system, the problem was the "redgreen" gem. It automatically colors the progress marks (dots) and the Test::Unit summary messages based on success or failure. There must be something in RubyMine that's trying to parse the Test::Unit results (the output of "rake test", I imagine), and it's choking on the ANSI sequences.
I commented out "require 'redgreen'" in my test/test_helper.rb, and the problem went away. I really like redgreen for executing "rake test" from the shell, though, so I put this in test_helper to make it work for both "rake test" and within RubyMine:
require 'redgreen' if $stdin.tty?
It may not be redgreen that's causing your problem, but be suspicious of anything which might create unconventional Test::Unit output.
Good luck!
I had the same issue and had to add the following to /etc/launcd.conf (I had to create this file as well):
setenv DYLD_LIBRARY_PATH /usr/local/mysql/lib/
and reboot. There are other ways to do it as well (a plist file, adding this environmental variable to RubyMine, etc… but this was most reliable. Of course, this assumes that you use MySQL.
The answer in the end for my setup was to fiddle around with the IDE settings including the ruby version, making sure it was 1.9.2 and the directories referenced in the config. screens were correct. This plus some restarts resolved the issue.

Speeding up rails tests during development by keeping Rails in memory?

When running rspec tests on my rails app using "rake" or "rake spec", it takes a long time to initialize Rails and start running tests.
Is there a way to keep Rails loaded in memory and run tests against it? I'm hoping there's something similar to using "grails interactive" like this How to speed up grails test execution but for Rails.
It's almost what Spork is all about.
See the most awesome railscast "How I test" http://railscasts.com/episodes/275-how-i-test
This uses guard to run a relevant test every time you save a file so you know almost instantly if the code you have written has caused a pass or a fail. Also if you are running on linux then you can use the libnotify and libnotify-rails gems which pop up a window for you (totally unobtrusively) indicating a pass or failure so you don't have to keep checking the console.
There is a Railscast called Spork that specifically discusses this problem at http://railscasts.com/episodes/285-spork and offers an excellent solution with a detailed walkthrough.

Ruby on Rails: Running Tests

When I want to run all my unit tests, I run rake test:units. To run all my functional tests, I run rake test:functionals. If I want to run all the test cases in one file, I run
ruby test/unit/username_test.rb
A few people have been telling me I should run rake instead such as
rake test:units TEST=test/unit/username_test.rb
For running tests, they say I should always run rake. I know I should run rake if I'm testing all my unit tests. But what if it's just one file or one particular test method in a file that I'm testing? Should I still use rake? Is there any difference between the two? Do I get any benefit from running rake over ruby? Is there any disadvantage to running ruby rather than rake?
Sadly, the two are not the same. Running the tests under rake can wind up pulling things from different places than when you run the test directly (more a problem when you have multiple versions of gems, etc. on your system).
The intent is that tests run under rake should be in an environment that matches what rails would produce; I can not attest to how closely they match, but I have seen tests that passed when run directly but failed when run via rake or rails (and visa versa).
Before checking in at the very least I'd recommend running rake to hit everything, in order to be assured that nothing unexpected has broken.
Plain ruby seems ideal for fast testing of single files during iterations.
Be aware that running everything through rake can produce different results to running everything individually, as I found to my confusion recently - I was doing something slightly wrong in one test that worked successfully in isolation but that left a problem lying around for a subsequent test that only showed up when I used rake.
No I dont think so. Rake seems to be a convenient way to run all tests, all unit tests or all functional/controller tests.
For a single file, I use the ruby object_test.rb approach.. shorter and works fine for my rails home project.
They should be identical. if they are not, you're definitely doing something wrong.
As I said in my other comments, if you get tests that pass in one, but fail in the other, you're doing something very wrong; this indicates a poor test setup, and is usually caused by a different test run order between the two test approaches; one of which causes tests to fail.
Usually the cause of this is that you are not using transactions and/or tests are not cleaning up after themselves. For example, not properly requiring the fixtures they later test for, and instead relying on the pre-existing database state.
you are free to use either method. if something breaks, you're doing something wrong in your tests, and you should fix your code.
The two are not the same. Rake will do some preliminary test loading.
The intent is that tests run under rake should be in an environment that matches what rails would produce;
One difference I've noticed is with rake some of the fixture loading happens which could be by-passed with ruby.
I'd recommend using rake, unless you are using the ruby command line to one just one test in the file with the -n option.

Resources