Ruby on Rails development from scratch (Windows) (21)-Test model problems

Source: Internet
Author: User
Tags ruby on rails

The previous essays are written in accordance with the examples in the book, but, this time in the test model, according to the example of the book How the code can not go, so on the other way, this becomes a question.

According to the book, at the beginning of the PRODUCTS_TEST.RB, the test data is loaded into a hash based on the defined yml file, so that we can access a product object by the name of the use case in Yml file, for example:

def test_read_with_hash
assert_kind_of Product, @product
vc_book = @products ["Version_control_book"]
Assert_equal vc_book["id", @product. ID
assert_equal vc_book["title"], @product. Title
assert_equal vc_book[ "description"], @product. Description
assert_equal vc_book["Image_url"], @product. Image_url assert_equal
VC _book[' price ', @product. Price
assert_equal vc_book["date_available"], @product. date_available_before_type_ Cast End

However, depending on the error that always prompts Vc_book to be null when the test is run:

3) Error:

Test_read_with_hash (producttest):
nomethoderror:you have a nil object when you didn ' t expect it!
You are might have expected an Array of instance.
The error occurred while evaluating nil. []
test/unit/product_test.rb:41:in ' Test_read_with_hash '

What's going on? Even if the contents of the PRODUCT_TEST.RB to replace all the complete code in the book is still not, is not the version of the problem?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.