Help: Attempts to run specs quitting midstream

I am having a very frustrating problem running specs on my current
project. When I run tests en masse with “rake spec” or with autotest,
it frequently quits without completing all the tests. It also
sometimes runs the tests in multiple batches, giving more than one
result line for a single batch of tests.

For example, on my current project (which has in total 524 examples), it
currently runs a batch of 31 examples (with 0 failures), outputs a
result line, then runs a batch of 131 examples (with 3 failures),
outputs a result line, then reports “rake aborted” with “command failed”.

If I put --reverse in spec.opts, it quits in a different place after a
different number of specs.

If I run with --trace, it reports that the final complaint is in
spectask.rb line 177. This is a line that looks for error results when
it executes the command with system().

As far as I can tell, there is no way for me to know which spec file was
actually executing when it quit. Very frustrating.

System information:
OS X 10.5.5
Ruby 1.8.6
rspec 1.1.11

Below is an shell transcript. If this had run successfully, there
would be 524 examples run, instead of 31 and then 131. The particular
numbers change as I edit my files.

Thanks for any help, I’m tearing my hair out here.
-Evan


[17:16:12] unithrive$ rake spec --trace
(in /Users/evan/Development/Ruby/unithrive)
** Invoke spec (first_time)
** Invoke db:test:prepare (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:clone (first_time)
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:clone
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute spec
…F.FF…

‘LoanRequestsController responding to GET /loan_requests/new step 1
should assign step 1’ FAILED
expected: 1,
got: nil (using ==)
./spec/controllers/loan_requests_controller_spec.rb:130:

NoMethodError in ‘LoanRequestsController responding to GET
/loan_requests/new step 1 should create a new loan_request’
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.step
/Users/evan/Development/Ruby/unithrive/app/controllers/loan_requests_controller.rb:29:in
new' /Users/evan/Development/Ruby/unithrive/app/controllers/loan_requests_controller.rb:28:innew’
./spec/controllers/loan_requests_controller_spec.rb:140:

Spec::Mocks::MockExpectationError in ‘LoanRequestsController responding
to GET /loan_requests/new step 1 should assign the new loan_request for
the view’
Mock ‘LoanRequest_1032’ received unexpected message :step with (no args)
/Users/evan/Development/Ruby/unithrive/app/controllers/loan_requests_controller.rb:29:in
new' /Users/evan/Development/Ruby/unithrive/app/controllers/loan_requests_controller.rb:28:innew’
./spec/controllers/loan_requests_controller_spec.rb:145:

Finished in 6.80498 seconds

131 examples, 3 failures

Finished in 1.785438 seconds

31 examples, 0 failures
rake aborted!
Command
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
-I"/Users/evan/Development/Ruby/unithrive/vendor/plugins/rspec/lib"
“/Users/evan/Development/Ruby/unithrive/vendor/plugins/rspec/bin/spec”
“spec/controllers/activities_controller_spec.rb”
“spec/controllers/admin/forums_controller_spec.rb”
“spec/controllers/admin/people_controller_spec.rb”
“spec/controllers/admin/preferences_controller_spec.rb”
“spec/controllers/advanced_searches_controller_spec.rb”
“spec/controllers/advanced_searches_routing_spec.rb”
“spec/controllers/comments_controller_spec.rb”
“spec/controllers/connections_controller_spec.rb”
“spec/controllers/forums_controller_spec.rb”
“spec/controllers/home_controller_spec.rb”
“spec/controllers/loan_requests_controller_spec.rb”
“spec/controllers/loan_requests_routing_spec.rb”
“spec/controllers/messages_controller_spec.rb”
“spec/controllers/password_reminders_controller_spec.rb”
“spec/controllers/people_controller_spec.rb”
“spec/controllers/photos_controller_spec.rb”
“spec/controllers/posts_controller_spec.rb”
“spec/controllers/searches_controller_spec.rb”
“spec/controllers/sessions_controller_spec.rb”
“spec/controllers/topics_controller_spec.rb”
“spec/helpers/activities_helper_spec.rb”
“spec/helpers/advanced_searches_helper_spec.rb”
“spec/helpers/comments_helper_spec.rb”
“spec/helpers/communications_helper_spec.rb”
“spec/helpers/connections_helper_spec.rb”
“spec/helpers/forums_helper_spec.rb”
“spec/helpers/loan_requests_helper_spec.rb”
“spec/helpers/posts_helper_spec.rb”
“spec/helpers/preferences_helper_spec.rb”
“spec/helpers/searches_helper_spec.rb”
“spec/helpers/topics_helper_spec.rb” “spec/models/activity_spec.rb”
“spec/models/advanced_search_spec.rb” “spec/models/blog_post_spec.rb”
“spec/models/blog_spec.rb” “spec/models/comment_spec.rb”
“spec/models/connection_spec.rb” “spec/models/conversation_spec.rb”
“spec/models/email_verification_spec.rb” “spec/models/feed_spec.rb”
“spec/models/forum_post_spec.rb” “spec/models/forum_spec.rb”
“spec/models/loan_request_spec.rb” “spec/models/message_spec.rb”
“spec/models/person_mailer_spec.rb” “spec/models/person_spec.rb”
“spec/models/photo_spec.rb” “spec/models/preference_spec.rb”
“spec/models/topic_spec.rb”
“spec/views/advanced_searches/edit.html.erb_spec.rb”
“spec/views/advanced_searches/index.html.erb_spec.rb”
“spec/views/advanced_searches/new.html.erb_spec.rb”
“spec/views/advanced_searches/show.html.erb_spec.rb”
“spec/views/layouts/application.html.erb_spec.rb”
“spec/views/loan_requests/edit.html.erb_spec.rb”
“spec/views/loan_requests/index.html.erb_spec.rb”
“spec/views/loan_requests/new.html.erb_spec.rb”
“spec/views/loan_requests/show.html.erb_spec.rb”
“spec/views/people/show.html.erb_spec.rb” --options
“/Users/evan/Development/Ruby/unithrive/spec/spec.opts” failed
/Users/evan/Development/Ruby/unithrive/vendor/plugins/rspec/lib/spec/rake/spectask.rb:177:in
define' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1003:inverbose’
/Users/evan/Development/Ruby/unithrive/vendor/plugins/rspec/lib/spec/rake/spectask.rb:153:in
define' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:incall’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:ineach’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:ininvoke_with_call_chain’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:ininvoke_with_call_chain’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:ininvoke_task’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:ineach’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:instandard_exception_handling’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:inrun’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in
standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:inrun’
/Library/Ruby/Gems/1.8/gems/rake-0.8.1/bin/rake:31
/usr/bin/rake:19:in `load’
/usr/bin/rake:19

Evan D. wrote:

I am having a very frustrating problem running specs on my current
project. When I run tests en masse with “rake spec” or with autotest,
it frequently quits without completing all the tests. It also
sometimes runs the tests in multiple batches, giving more than one
result line for a single batch of tests.

I was having a similar problem. My specs would quit running after a
third of them ran. When I ran my specs using ./script/spec spec I’d get
a different count and my specs would run as two batches.

I decided to run each of my specs separately using something like:

ruby script/spec “spec/controllers/name_of_a_specific_spec.rb”

That showed that some of my specs were in fact failing. If I tried to
run ./script/specs with any options I’d get a report of:

0 examples, 0 failures

Then I decided to run each directory under spec/* separately so I could
try to narrow down which specs were causing the problem. I ran:

./script/spec spec/controllers
./script/spec spec/models
./script/spec spec/views

When I ran views I got the same “0 examples, 0 failures” message so I
ran each folder separately:

./script/spec spec/views/view_1
./script/spec spec/views/view_2

That let me narrow it down to specific views that were causing the
problem. Then I ran each spec separately.

My problem was caused by using
template.should_receive(:current_user).and_return(@user). Commenting
that out fixed RSpec for me. I can now run it using rake spec or even
rake spec:rcov and it works the same as running ./script/spec spec.

Hope that helps. I’m still not sure why RSpec is failing this way.

Matt G.

On Oct 30, 2008, at 8:21 PM, Evan D. wrote:

outputs a result line, then reports “rake aborted” with "command

Below is an shell transcript. If this had run successfully, there
would be 524 examples run, instead of 31 and then 131. The
particular
numbers change as I edit my files.

Thanks for any help, I’m tearing my hair out here.

I’d file this bug report at lighthouse:

http://rspec.lighthouseapp.com/dashboard

Scott

Matt W. wrote:

It would be really helpful if you could file a bug report so that
people can get onto fixing it:
Lighthouse - Beautifully Simple Issue Tracking

Yep I’m trying to narrow it down to the simplest repro case.
Unfortunately I can only reproduce it in my rails app. I was causing the
problem by calling should_receive in a meaningless way:

template.should_receive(:current_user, 2).and_return(@user)

Instead of:

template.should_receive(:current_user).twice.and_return(@user)

But the way RSpec handles this problem in my app is a bug that I’ll
submit with as much info to try and help someone narrow it down.

On 18 Nov 2008, at 17:06, Matt G. wrote:

get

Hope that helps. I’m still not sure why RSpec is failing this way.

It would be really helpful if you could file a bug report so that
people can get onto fixing it:
http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/new

cheers,
Matt

Matt W. wrote:

It would be really helpful if you could file a bug report so that
people can get onto fixing it:
Lighthouse - Beautifully Simple Issue Tracking

RSpec’s Lighthouse is broken. I’ve tried submitting 2 tickets with no
luck. If someone on the RSpec team needs more info I’d be happy to help
in any way.