Note that there are some explanatory texts on larger screens.

plurals
  1. POwrong argument unit test
    text
    copied!<p>good day every one im just wonder what seems to be my problem i dont think im have any problem with my code im having problem with a <strong>wrong number of arguments</strong> error in my test_image_url test</p> <pre><code>============================================================================== 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 =&gt; test:units (See full trace by running task with --trace) </code></pre> <p>my unit test:</p> <pre><code> require 'test_helper' class ProductTest &lt; ActiveSupport::TestCase def new_product product = Product.new(:title =&gt; "MyBook", :description =&gt; "Famouse myBook", :image_url =&gt; "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 =&gt; "MyBook", :description =&gt; "Famouse myBook", :image_url =&gt; "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 </code></pre> <p>EDIT: sovled thanks for the help i figured out whats wrong</p> <pre><code>require 'test_helper' class ProductTest &lt; ActiveSupport::TestCase def new_product(image_url) product = Product.new(:title =&gt; "MyBook", :description =&gt; "Famouse myBook", :price =&gt; 1 , :image_url =&gt; image_url) 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 =&gt; "MyBook", :description =&gt; "Famouse myBook", :image_url =&gt; "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} 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 =begin ok.each do |name| assert new_product(name).valid?, "#{name} shoudn't be invalid" end bad.each do |name| assert new_product(name).invalid?, "#{name} shoudn't be valid" end =end end end </code></pre> <p>um running in rails 3.1 ruby 1.9</p> <p>thanks more power to us</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload