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

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

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

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.

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...

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.

:slight_smile: