0

I'm going through Agile Web Development with Rails 4 (beta) and in the Model testing section (iteration B2). Things we're going fine until I added the following code in my test/models/product_test.rb file. It's copy an pasted from the pdf. I'm getting a weird error when I try to run the tests for models. I also posted in the publisher's forum.

def new_product(image_url)
    Product.new(title: "My Book Title",
            description: "yyy", 
            price: 1, 
            image_url: image_url)
end

test "image url" do
    ok = %w{ fred.gif fred.jpg fred.png FRED.JPG FRED.Jpg http://a.b.c/x/y/z/fred.gif }
    bad = %w{ fred.doc fred.gif/more fred.gif.more }

    ok.each do |name|
        assert new_product(name).valid?, "#{name} shouldn't be invalid"
    end

    bad.each do |name|
        assert new_product(name).invalid?, "#{name} shouldn't be valid"
    end 
end

Here is the error I got after running rake test:models --trace in terminal.

➜  depot git:(master) ✗ rake test:models --trace  
** Invoke test:models (first_time)  
** Invoke test:prepare (first_time)  
** Invoke db:test:prepare (first_time)  
** Execute db:test:prepare  
** Invoke db:test:load (first_time)  
** Invoke db:test:purge (first_time)  
** Invoke environment (first_time)  
** Execute environment  
** Invoke db:load_config (first_time)  
** Execute db:load_config  
** Execute db:test:purge  
** Execute db:test:load  
** Invoke db:test:load_schema (first_time)  
** Invoke db:test:purge   
** Execute db:test:load_schema  
** Invoke db:schema:load (first_time)  
** Invoke environment   
** Invoke db:load_config   
** Execute db:schema:load  
** Invoke db:abort_if_pending_migrations (first_time)  
** Invoke environment   
** Execute db:abort_if_pending_migrations  
** Execute test:prepare  
** Execute test:models  
rake aborted!  
unknown command 'i'  
/Users/admin/Dropbox/code/rails/depot/test/models/product_test.rb:39:in `test'  
/Users/admin/Dropbox/code/rails/depot/test/models/product_test.rb:39:in `<top (required)>'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:228:in `require'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:228:in `block in require'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:213:in `load_dependency'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:228:in `require'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/railties-4.0.0.rc1/lib/rails/test_unit/sub_test_task.rb:73:in `block (3 levels) in define'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/railties-4.0.0.rc1/lib/rails/test_unit/sub_test_task.rb:73:in `each'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/railties-4.0.0.rc1/lib/rails/test_unit/sub_test_task.rb:73:in `block (2 levels) in define'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/railties-4.0.0.rc1/lib/rails/test_unit/sub_test_task.rb:72:in `each'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/railties-4.0.0.rc1/lib/rails/test_unit/sub_test_task.rb:72:in `block in define'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'  
/Users/admin/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/bin/rake:23:in `load'  
/Users/admin/.rvm/gems/ruby-1.9.3-p385@rails3tut/bin/rake:23:in `<main>'  
Tasks: TOP => test:models  
Run options: --seed 9617  

# Running tests:  

..  

Finished tests in 0.550033s, 3.6361 tests/s, 18.1807 assertions/s.  
BvuRVKyUVlViVIc7
  • 11,641
  • 9
  • 59
  • 111
Nikola
  • 817
  • 13
  • 19

1 Answers1

1

The trace is telling you that you have unknown command 'i' at line 39 of the file product_test.rb (that's what that product_test.rb:39) means.

Do you have some misplaced i somewhere on that line? It might be outside of the snippet you quoted -- I can't tell without your line numbers.

T.J. Schuck
  • 3,645
  • 2
  • 19
  • 20
  • there's nothing off screen. Here's more info: When I edit line 39 to look like this: `test "mage url" do` the error is `unknown command 'm'` This makes me think that the code is not being parsed properly at some point. – Nikola Jul 01 '13 at 20:10
  • @Nikola You said you copied and pasted from a PDF -- it's possible there are some "hidden" characters there you didn't intend -- possibly smart/curly quotes? Delete that line and type it manually -- does that fix your issue? – T.J. Schuck Jul 01 '13 at 20:15
  • Well, I originally typed the whole thing in manually and got the same error. I copy and pasted it from the pdf later because I assumed I mis-typed something. I get the same error in both cases. – Nikola Jul 01 '13 at 20:18
  • 2
    I found my mistake. All of the tests need to be inside of `class ProductTest < ActiveSupport::TestCase ... end` the last two were outside of the ProductTest Class. – Nikola Jul 01 '13 at 20:24
  • @Nikola Glad you figured it out! – T.J. Schuck Jul 01 '13 at 20:26