2012-02-17 5 views
0

좋은 하루 모두 메신저는 내가 메신저 내 코드 메신저 인수 잘못된 번호에 문제가 어떤 문제가있는 것 같아요 내 문제가 될 것으로 보인다 궁금해 내 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 

편집 : 내가 무슨 잘못

012을 파악 도움을 감사를 통해서 문제를 해결할 에서 실행 39,

음은 우리

+0

전달 테스트 또는 전체 테스트 파일을 게시 할 수 있습니까? – bdon

+0

@bdon 파일은 이미 게시 해 주셔서 감사합니다. – Led

답변

0

-3.1 루비 1.9

덕분에 더 많은 전력을 내가 문제를 알아낼 수 없습니다입니다 레일. 위의 코드에서 setup,teardown 메서드를 사용하지 않기 때문입니다. 전체 테스트 케이스를 제공하거나 setupteardown 메소드에 인수 작업이 있는지 확인하십시오. 그 문제는 그와 관련이 있습니다.