2012-02-17 15 views
0

良い一日一人一人のIMはちょうど私がイムは私のコードイムは、引数の間違った番号に問題を持つ任意の問題を抱えていると思ういけない私の問題であると思われるだろうか、私のtest_image_url試験でエラー間違った引数のユニットテスト

============================================================================== 
SUITE test,test/unit/helpers,test/unit,test/performance,test/functional (SEED 49459) 
============================================================================== 
ActionController::TestCase 
ActionDispatch::IntegrationTest 
ActionView::TestCase 
ActiveRecord::TestCase 
ActiveSupport::TestCase 
ProductTest 
    test_image_url           0:00:00:163 ERROR 
     wrong number of arguments (1 for 0) 
     Exception `ArgumentError' at: 
     /home/led/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/testing/setup_and_teardown.rb:35:in `block in run' 
     /home/led/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:408:in `_run_setup_callbacks' 
     /home/led/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:81:in `run_callbacks' 
     /home/led/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/testing/setup_and_teardown.rb:34:in `run' 
    test_product_attributes_must_not_be_empty    0:00:00:317 PASS 
    test_product_must_be_postive_price      0:00:00:326 PASS 
ProductsHelperTest 
============================================================================== 
    pass: 2, fail: 0, error: 1 
    total: 3 tests with 10 assertions in 0.3286295 seconds 
============================================================================== 
rake aborted! 
Command failed with status (1): [/home/led/.rvm/rubies/ruby-1.9.2-p290/bin/...] 

Tasks: TOP => test:units 
(See full trace by running task with --trace) 

私のユニットテスト:

 require 'test_helper' 

class ProductTest < ActiveSupport::TestCase 

    def new_product 
     product = Product.new(:title => "MyBook", 
          :description => "Famouse myBook", 
          :image_url => "zz.jpg") 

    end 

    test "product attributes must not be empty" do 
     product = Product.new 
     assert product.invalid? 
     assert product.errors[:title].any? 
     assert product.errors[:description].any? 
     assert product.errors[:price].any? 
     assert product.errors[:image_url].any? 
    end 

    test "product must be postive price" do 
     product = Product.new(:title => "MyBook", 
          :description => "Famouse myBook", 
          :image_url => "zz.jpg") 

     product.price = -1 
     assert product.invalid? 
     assert_equal "must be greater than or equal to 0.01", 
     product.errors[:price].join('; ') 

     product.price = 0 
     assert product.invalid? 
     assert_equal "must be greater than or equal to 0.01", 
     product.errors[:price].join('; ') 

     product.price = 1 
     assert product.valid? 
    end 


    test "image url" do 
     ok = %w{fred.gif fred.jpg fred.png FRED.JPG FRED.PNG FRED.GIF 
        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} shoudn't be invalid" 
      end 


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








end 

EDIT:私はいただきました!間違っ

012を考え出し助けを 感謝をsovled

ええと、私たちにレール3.1 ルビーで1.9

おかげで、より多くの電力を実行している

+0

あなたは合格テスト、または全体のテストファイルを投稿できますか? – bdon

+0

@bdonファイルが既に投稿されました – Led

答えて

0

私はあなたの問題を理解することはできませんよ。上記のコードでsetup,teardownメソッドを使用していないためです。完全なテストケースを提供するか、メソッドsetupteardownに引数の操作を確認してください。それに関連する問題のみ。

関連する問題