small medium large xlarge

Generic-user-small
08 Jul 2016, 10:11
karo (1 post)

Hi, I am on Task B: Validation and Unit Testing, trying to do Iteration B2: Unit Testing of Models, actually playtime. I have to change the error message associated with one of my validations. I`ve taken code from http://www.pragprog.com/wikis/wiki/RailsPlayTime:

test “product title must be at least 10 characters long” do (…) product.title = “Any title” assert product.invalid? min_title_size = Product.validators_on(:title).select { |v| v.class == ActiveModel::Validations::LengthValidator}.first.options[:minimum] assert_equal [“must have at least #{min_title_size} characters”], product.errors[:title] end

When I run tests, i have something like this:

Error: ProductTest#test_product_title_must_be_at_least_10_characters_long: NoMethodError: undefined method options' for nil:NilClass test/models/product_test.rb:72:in block in '

I tried to look on google, but no chance to find the answer. Can u explain whats happening here?I hope u can give me any advice!

You must be logged in to comment