I managed to mess up my gemsets by mixing rvm and sudo. Ended up having to uninstall ruby, rvm and start from scratch. Now I've got everything up and running, except my RSpec isn't behaving as it should be. All it displays is:
bundle exec rspec spec/
..................................................................F.
In the past it would display a detailed failure report showing which test failed, and why, like:
1)
'User should be in any roles assigned to it' FAILED
expected in_role?("assigned role") to return true, got nil
./user_spec.rb:7:
Finished in 0.0172110000000001 seconds
1 example, 1 failure
I've tried playing with the various formatter options. The 'd' option gives me the most verbose results, but these are too verbose as every single test that succeeds is also printed in full on a new line, which quickly starts turning the report into pages.
What can I change to make RSpec work like before?
You need ask to rspec say the complete backtrace. The option is --backtrace or -b
You can define it in your .rspec file in your directory or in your rspec command line.
Related
I'm really hoping someone can answer a question for me. I've spent days configuring everything else I need for rubytutorial.org and I'm getting that familiar frustration that comes with Windows OS.
I am on section 3.6.3 Speeding up tests with Spork of Rubytutorial.org.
I just installed Guard and Spork.
Michael Hartl says, "Before running Spork, we can get a baseline for the testing overhead by timing our test suite as follows:"
$ time bundle exec rspec spec/requests/static_pages_spec.rb
......
6 examples, 0 failures
real 0m8.633s
user 0m7.240s
sys 0m1.068s
Below is what I receive.
time bundle exec rspec spec/requests/static_pages_spec.rb
The system cannot accept the time entered.
Enter the new time:
If anyone has an idea, I did try to search elsewhere... There's one resource by a guy http://someguyonrails.tumblr.com/post/29715188571/guard-spork-error-in-rails-tutorial-section-3-6, but his Gemfile is different than mine and the fix isn't the same. I think his is a work-around anyway.
Here is a quote from the page, "The first issue I encountered was when running the command "time bundle exec rspec spec/requests/static_pages_spec.rb —drb," I got the following message in my command window "The system cannot accept the time entered. Enter the new time:" This remains unresolved, but I assume this implies that my Windows command prompt is not interpreting the “time” command the way the Tutorial expects. I’m not sure about this one so, feel free to shed some light on this."
I couldn't find anything else with what I searched.
Thanks..
time is a Unix command that is not available natively on Windows. https://superuser.com/questions/228056/windows-equivalent-to-unix-time-command discussed a Powershell equivalent. I would instead recommend install Github for Windows, which will give you a bash shell, which is much more accommodating for Rails development. You should also strongly consider running Rails in Vagrant.
When running $ rspec on my Rails 4.1 application, some of the specs in user_spec.rb fail:
104 examples, 5 failures, 2 pending
And all 5 errors are because there are two errors on a certain field instead of only one:
1) User creating a guest validates presence of name
Failure/Error: expect(#guest).to have(1).error_on(:name)
expected 1 error on :name, got 2
# ./spec/models/user_spec.rb:43:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'
The errors are always double: #messages={:name=>["can't be blank", "can't be blank"]}>, but should be like this: #messages={:name=>["can't be blank"]}>.
Strangely, this doesn't happen, when running only the specified file ($ rspec ./spec/models/user_spec.rb).
22 examples, 0 failures
I tried $ git bisect, but couldn't locate the problem.
So if anybody could please try to checkout https://github.com/jmuheim/communes/commit/0dee0d4983809bc19b6cb97ff9bab071fc866b02 and run the specs ($ rspec and $ rspec ./spec/models/user_spec.rb) and tell me whether the double errors are occurring, and maybe try to help me debugging the problem, I would be really thankful.
I suspect Spring application pre-loader could be part of the problem, because sometimes, after Spring is explicitly stopped ($ spring stop), $ rspec passes, and sometimes it doesn't. Can't locate a pattern, looks very random to me:
$ spring stop
Spring stopped.
$ rspec
Finished in 3.66 seconds
104 examples, 0 failures, 2 pending
$ spring stop
Spring stopped.
$ rspec
104 examples, 5 failures, 2 pending
I can't really reproduce this pattern. Very strange and annoying/frustrating. Any help is highly appreciated.
This was the first answer I came across googling a similar problem so I wanted to add the fix I found that worked best to save others some searching.
rspec 3.3+ has a --bisect command that will determine the smallest subset of tests that will fail.
run it with a seed that is known to fail and let it churn out a small set of specs that you need to look at.
rspec --seed 1245 --bisect
https://relishapp.com/rspec/rspec-core/docs/command-line/bisect
What you have is a spec order dependency problem: your user specs fail if some of the other specs have run before. When running only the user specs, then they are ok. You've got rspec set to run specs in a random order (which is designed to expose this sort of problems) which is why the problem comes and goes.
It sounds like the problem is that the User class is being loaded a second time, which is causing the validations to be added a second time. When the specs fails rspec will output a line telling you what the seed for the ordering was: if you run the specs with the seed option rspec shows you then the order will remain constant, enabling you to home in on the problem.
One approach might be to put a breakpoint (or just output caller) right at the top of user.rb - it should then become evident if user.rb is being loaded more than once and what is causing it.
When I run my integration tests individually using "ruby -Itest test/integration/mytest.rb", it works just fine.
When I try to run rake test:integration to run all my integration tests in one command, I have to wait a few seconds but I never get any output. No good result, no error.
If I run rake --trace test:integration, everything seems to be fine until the Execute test:integration (which does not provide any output).
Looks as though the integration folder was not found or was empty.
Any ideas?
Thanks
Christian
I've just spent 3 hours trying to figure this out, and get this: your test files must end with "_test.rb" otherwise they are skipped
I wonder how to setup testing in my rails apps. When I run rake test, first thing odd, it launch a bunch of CREATE TABLE against my dev. database (hum.. do not like this..). So I launch rake test RAILS_ENV=test and I even try bundle exec rake test RAILS_ENV=test. Now, the CREATE TABLE is against my test database but all fails with this error :
** Execute test:units
test/unit/category_test.rb:5:in `test': unknown command 't' (ArgumentError)
from test/unit/category_test.rb:5:in `<class:CategoryTest>'
I have used basic generator in Rails 3 and do not change anything. So I have this in caterogy_test.rb :
require 'test_helper'
class CategoryTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
I use Rails 3.0.7 and basic config.
Any ideas ?
EDIT
I am becoming crazy, made a lot of tries, neither seems to work. When I start a new application with a few things, rake test works fine but when I try this on my current one, it launch always against my dev. db and do not work at all. I have tried to edit the test files, to revert them back, try to remove/setup test db with different ways, try different rake version, compare a lot of things on one side my current application and on the other a brand new one... Found nothing.. Help !
EDIT 2
Sounds lame, but is it normal that rake does the same thing than rake test ?
EDIT 3
Sounds odds, while I continue to work on what's wrong, I realize that every-time I run rake test, it does stuff on the dev environment and not the test one (watching the logs). It does this on my computer OSX and on our server FreeBSD for all the Rails 3.0.7 apps. Are you sure rake test is supposed to work on the test environment by default ?
EDIT 4
Please help!
EDIT 5 - SUMMARY
When running rake test in my computer or on our server in Rails 3.0.7 with different apps it does the following :
run CREATE TABLE and INSERT INTO migration against the dev. db.
do not empty the dev. db.
development.log gets written not the test.log
also an issue with the error unknowm comman 't' with one specific app.
EDIT 6 - db config
Nothing change from the default yet : https://gist.github.com/1006199
EDIT 7
rake db:test:prepare --trace -> nothing break (but keep printing (first_time)
https://gist.github.com/1007340
With RAILS_ENV="test" for rake, everything goes fine. It write on the test logs.
ruby -I test test/unit/category_test.rb same erros than with rake, but no write on the dev. or test logs.
a bunch of unorderd answers:
the "CREATE TABLE" statements usually means that your test_db is created from scratch (by default, before test task, a db:migrate is launched). are you sure they're called on dev_db?
also check your config/database.yml to see if there's some typo (eg: using same table for test and dev environments)
it looks like there's an error in some of your migration files (that 't' error remember blocks in migrations).
"rake test" is the default task, that's why it's run when you just launch "rake" without arguments.
EDIT:
according on what I see on edits, from 5 and above, it looks like you have some issue with environment files. so try to double-check:
* config/environments/test.rb
* config/application.rb
* config/environment.rb
if with RAILS_ENV="test", everything goes fine, then I'm almost sure you have changed some default behaviour in your app (configs, env variables, any particular gem?)
also, in your test/test_helper.rb, add RAILS_ENV='test' at the beginning of file, this should force test environment.
I had that same error message, except to me it said: in `test': unknown command 'i' (ArgumentError).
The 'fix' or 'workaround' was to simply use:
$> bundle exec rake test
instead of using 'rake test'
I have the file config/initializers/custom.rb
In the file, there is only one line:
`rake thinking_sphinx:start`
I thought this was supposed to just execute the line like when typing it from a command line. With this line of code, when I run "ruby script/server", the server freezes and outputs no error messages. Am I missing something?
Thanks!
Initializers load when your application loads. Rake tasks generally load your application. If you call a Rake task from an initializer, you're going to throw your app for a loop.
If you're worried about forgetting to start Sphinx in development, just give yourself a little warning:
# config/initializers/custom.rb
begin
ThinkingSphinx::Search.search "test" # test search
rescue ThinkingSphinx::ConnectionError
puts "** Oops! ThinkingSphinx is off! **"
end
I asked about how to get it to start up in dev mode via netbeans but the idea is the same. Bounty is still open.
My guess is that your not getting to the server starting because sphinx needs it's own process so it never returns to your custom initializer.