small medium large xlarge

Generic-user-small
30 Oct 2011, 18:13
Denis Rhoden (10 posts)

Hi Everyone,

Thanks for reading my question. I just installed rbenv / rbenv-build and I am experiencing the following issues in Ch 7. How do I make the testing suite work in my depot app?

When I run rake tasks in this chapter I get the following exceptions:

$ bundle exec rake test
(in /home/rhodee/GitRepos/projects/depot)
rake aborted!
uninitialized constant Rake::DSL
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:6:in `<module:Rake>'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:3:in `<top (required)>'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `require'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `<top (required)>'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/test_unit/testing.rake:2:in `require'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/test_unit/testing.rake:2:in `<top (required)>'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/test_unit/railtie.rb:12:in `load'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/test_unit/railtie.rb:12:in `block in <class:TestUnitRailtie>'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie.rb:183:in `call'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie.rb:183:in `block in load_tasks'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie.rb:183:in `each'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie.rb:183:in `load_tasks'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:395:in `block in load_tasks'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/application/railties.rb:8:in `each'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/application/railties.rb:8:in `all'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:395:in `load_tasks'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/application.rb:99:in `load_tasks'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/rhodee/GitRepos/projects/depot/Rakefile:7:in `<top (required)>'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/rake.rb:2373:in `load'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/rake.rb:1991:in `run'
/home/rhodee/.rbenv/versions/1.9.2-p290/bin/rake:31:in `<main>'
It also occurs when I run rake db:migrate rollback …

Last thing:: I created an alias for bundle exec in bash_profile: b = bash_profile…It works when I wish to start a server (e.g. b thin start) but it doesn’t work when I run this in my terminal ~~~ b rake test:units ~~~ Does this occur bc thin is my Gemfile explicitly? I don’t believe that is the case, but I need to start some where -

Cheers!

Denis

Samr_small_pragsmall
30 Oct 2011, 18:13
Sam Ruby (634 posts)

If I read that call stack correctly, you have two different versions of rake installed. What does gem list rake produce on your system?

Related reading:

http://forums.pragprog.com/forums/148/topics/9582#posts-26072

http://stackoverflow.com/questions/6181312/how-to-fix-the-uninitialized-constant-rakedsl-problem-on-heroku/6263256#6263256

Offhand, I don’t know the answer to your bundle exec alias question, but I will say that I haven’t had to explicitly use bundle exec. But perhaps that’s because I only have one version of rake installed, and use rails server.

Generic-user-small
31 Oct 2011, 01:20
Denis Rhoden (10 posts)

Thanks Sam,

I really appreciate being able to the read the book while you write AND you being so responsive. Cheers to you and Prag Prog!

So I remove rake 0.87 and added require ‘rake/dsl_definition’ and require ‘rake’ to my Rakefile. Now I receive the following warnings and test output:

$ rake test
LOADED SUITE test,test/performance,test/functional,test/unit,test/unit/helpers
ActionController::TestCase
ActionDispatch::IntegrationTest
ActionView::TestCase
ActiveRecord::TestCase
ActiveSupport::TestCase
MiniTest::Spec
ProductTest
     test_image_url                                                       FAIL
        fred.doc shouldn't be valid.
        Assertion at /home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/testing/setup_and_teardown.rb:35:in `block in run'
     test_product_descriptions_must_not_be_empty                          PASS
     test_product_is_not_valid_without_a_unique_title_-_il8n             ERROR
        uninitialized constant ProductTest::Il8n
        STDERR:
        Exception `NameError' at /home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/testing/setup_and_teardown.rb:35:in `block in run'
        /home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:408:in `_run_setup_callbacks'
        /home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
        /home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/testing/setup_and_teardown.rb:34:in `run'
ProductsHelperTest
Test::Unit::TestCase
==============================================================================
  pass: 1,  fail: 1,  error: 1
  total: 3 tests with 13 assertions in 0.354887927 seconds
==============================================================================
LOADED SUITE test,test/performance,test/functional,test/unit,test/unit/helpers
ActionController::TestCase
ActionDispatch::IntegrationTest
ActiveRecord::TestCase
ActiveSupport::TestCase
MiniTest::Spec
ProductsControllerTest
     test_should_create_product                                           FAIL
        "Product.count" didn't change by 1.
        <4> expected but was
        <3>.
        Assertion at /home/rhodee/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/testing/assertions.rb:60:in `block in assert_difference'
     test_should_destroy_product                                          PASS
     test_should_get_edit                                                 PASS
     test_should_get_index                                                PASS
     test_should_get_new                                                  PASS
     test_should_show_product                                             PASS
     test_should_update_product                                           PASS
Test::Unit::TestCase
==============================================================================
  pass: 6,  fail: 1,  error: 0
  total: 7 tests with 9 assertions in 0.695084038 seconds
==============================================================================
Errors running test:units, test:functionals!

</pre>

Samr_small_pragsmall
31 Oct 2011, 02:09
Sam Ruby (634 posts)

There probably are three real errors in your code some place, probably typos or the like. Without seeing your code, this is hard to diagnose (except for the second one!).

The first failure indicates that validation on urls is not taking place. Try creating a product using the web page with a URL of fred.doc and verify that you are getting the error you expect. The validation code that you are testing here should be in app/models/product.rb.

The second failure looks like a simple typo: il8n should be i18n.

The final failure is the opposite of the first: you are unable to create a product, presumably because of a validation failure. Look in test/functional/products_controller_test.rb for something wrong with the values that you are assigning to @update. Again, it might be helpful if you try entering these values using the web interface and verifying that you can create a product with these attributes.

Generic-user-small
31 Oct 2011, 14:02
Denis Rhoden (10 posts)

Consider it solved. You were right on all front regarding typos - off I go to ch 8!

You must be logged in to comment