Having trouble testing :( "superclass mismatch" and can't load "test_helper"

30 views
Skip to first unread message

daze

unread,
Dec 14, 2010, 10:43:52 PM12/14/10
to Ruby on Rails: Talk
I'm having trouble testing my Rails 3 application. Unit testing
doesn't work. If I try ruby article_test.rb directly, I get a "no
such file to load" error, and if I try rake test:units or ruby unit/
article_test.rb I get this odd "superclass mismatch for class
ArticlesController" error!

I'm hoping I can get this settled...
My test files were generated by the generator...

C:\Users\Family\workspace\jdrampage\test\unit>ruby article_test.rb
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- test_helper
(LoadError)
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `require'
from article_test.rb:1

C:\Users\Family\workspace\jdrampage\test\unit>cd..

C:\Users\Family\workspace\jdrampage\test>ruby unit/article_test.rb
C:/Users/Family/workspace/jdrampage/app/controllers/
articles_controller.rb:1: superclass mismatch for class
ArticlesController (TypeError)
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/
active_support/dependencies.rb:239:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/
active_support/dependencies.rb:239:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/
active_support/dependencies.rb:227:in `load_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/
active_support/dependencies.rb:239:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/
active_support/dependencies.rb:346:in `require_or_load'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/
active_support/dependencies.rb:300:in `depend_on'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/
active_support/dependencies.rb:216:in `require_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/engine.rb:138:in `eager_load!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/engine.rb:137:in `each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/engine.rb:137:in `eager_load!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/engine.rb:135:in `each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/engine.rb:135:in `eager_load!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/application.rb:108:in `eager_load!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/application/finisher.rb:41
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/initializable.rb:25:in `instance_exec'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/initializable.rb:25:in `run'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/initializable.rb:50:in `run_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/initializable.rb:49:in `each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/initializable.rb:49:in `run_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/application.rb:134:in `initialize!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/application.rb:77:in `send'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/
rails/application.rb:77:in `method_missing'
from C:/Users/Family/workspace/jdrampage/config/environment.rb:
5
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `gem_original_require'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `require'
from ./test_helper.rb:2
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `gem_original_require'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `require'
from unit/article_test.rb:1

David Kahn

unread,
Dec 14, 2010, 10:58:56 PM12/14/10
to rubyonra...@googlegroups.com
On Tue, Dec 14, 2010 at 9:43 PM, daze <dmono...@gmail.com> wrote:
I'm having trouble testing my Rails 3 application.  Unit testing
doesn't work.  If I try ruby article_test.rb directly, I get a "no
such file to load" error, and if I try rake test:units or ruby unit/
article_test.rb I get this odd "superclass mismatch for class
ArticlesController" error!

I'm hoping I can get this settled...
My test files were generated by the generator...

C:\Users\Family\workspace\jdrampage\test\unit>ruby article_test.rb
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- test_helper
(LoadError)
       from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `require'
       from article_test.rb:1

C:\Users\Family\workspace\jdrampage\test\unit>cd..

C:\Users\Family\workspace\jdrampage\test>ruby unit/article_test.rb
C:/Users/Family/workspace/jdrampage/app/controllers/
articles_controller.rb:1: superclass mismatch for class
ArticlesController (TypeError)

Did you look at your ArticlesController for clues?

Also, does your app function through the browser but not running the tests?

Would not hurt to copy your ArticlesController here, and maybe also your Environment.rb
 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


Colin Law

unread,
Dec 15, 2010, 4:02:08 AM12/15/10
to rubyonra...@googlegroups.com
On 15 December 2010 03:43, daze <dmono...@gmail.com> wrote:
> I'm having trouble testing my Rails 3 application.  Unit testing
> doesn't work.  If I try ruby article_test.rb directly, I get a "no
> such file to load" error, and if I try rake test:units or ruby unit/
> article_test.rb I get this odd "superclass mismatch for class
> ArticlesController" error!
>
> I'm hoping I can get this settled...
> My test files were generated by the generator...
>
> C:\Users\Family\workspace\jdrampage\test\unit>ruby article_test.rb

If you want to run a test directly like this you have to tell it to
include the test directory so it can find the helpers, so from the
root of your app
ruby -I test test/unit/article_test.rb

That is a capital i (for Include)

Colin

daze

unread,
Dec 16, 2010, 12:07:49 AM12/16/10
to Ruby on Rails: Talk
On Dec 15, 4:02 am, Colin Law <clan...@googlemail.com> wrote:

> If you want to run a test directly like this you have to tell it to
> include the test directory so it can find the helpers, so from the
> root of your app
> ruby -I test test/unit/article_test.rb
>
> That is a capital i (for Include)
>
> Colin

Okay - I guess that solves one of my problems in which I got the "no
such file to load -- test_helper" error.

daze

unread,
Dec 16, 2010, 12:09:11 AM12/16/10
to Ruby on Rails: Talk
On Dec 14, 10:58 pm, David Kahn <d...@structuralartistry.com> wrote:

> Did you look at your ArticlesController for clues?

Um...yes. But I didn't see anything odd.

> Also, does your app function through the browser but not running the tests?

Yes, running rails server works fine. It's the tests that give this
error.

> Would not hurt to copy your ArticlesController here, and maybe also your
> Environment.rb

Okay. I'm in Rails 3, though, so environment.rb is probably useless
to look at...
Here's the articles controller:

class ArticlesController < ApplicationController
# GET /articles
# GET /articles.xml
def index
@articles = Article.all(:limit => 6)

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @articles }
end
end

# GET /articles/1
# GET /articles/1.xml
def show
@article = Article.find(params[:id])
@section = @article.section

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @article }
end
end

# GET /articles/new
# GET /articles/new.xml
def new
@article = Article.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @article }
end
end

# GET /articles/1/edit
def edit
@article = Article.find(params[:id])
end

# POST /articles
# POST /articles.xml
def create
@article = Article.new(params[:article])

respond_to do |format|
if @article.save
flash[:notice] = 'Article was successfully created.'
format.html { redirect_to(@article) }
format.xml { render :xml => @article, :status
=> :created, :location => @article }
else
format.html { render :action => "new" }
format.xml { render :xml => @article.errors, :status
=> :unprocessable_entity }
end
end
end

# PUT /articles/1
# PUT /articles/1.xml
def update
@article = Article.find(params[:id])

respond_to do |format|
if @article.update_attributes(params[:article])
flash[:notice] = 'Article was successfully updated.'
format.html { redirect_to(@article) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @article.errors, :status
=> :unprocessable_entity }
end
end
end

# DELETE /articles/1
# DELETE /articles/1.xml
def destroy
@article = Article.find(params[:id])
@article.destroy

respond_to do |format|
format.html { redirect_to(articles_url) }
format.xml { head :ok }
end
end
end

I hope this helps. Though this class is pretty standard...

daze

unread,
Dec 20, 2010, 9:43:12 PM12/20/10
to Ruby on Rails: Talk
I figured it out.

I simply forgot to put "Admin::" for the articles controller in the
admin namespace. Making the controllers start with "class
Admin::ArticlesController" resolved the issue.
Of course I had to add "Admin:: to any other controllers in the admin
namespace that were missing it too.

:)
Reply all
Reply to author
Forward
0 new messages