Ruby on rails testing custom message -


i wrote test:

  test "email validation should accept valid address"     valid_addresses = %w[user@eee.com r_rdd@adf.com user@gmail.com hi12@hi.co a]     valid_addresses.each |e|       @chef.email = e       assert @chef.valid?, '#{e.inspect} should valid'     end   end 

when rake test, message when fail

1) failure: cheftest#test_email_validation_should_accept_valid_address [/home/ubuntu/workspace/test/models/chef_test.rb:56]: #{e.inspect} should valid  20 runs, 23 assertions, 1 failures, 0 errors, 0 skips 

instead of whatever |e| should be... want see "a" should valid more descriptive message see variable , inspect method value. pleas help.

you need use string interpolation. can made using "", not ''.

assert @chef.valid?, "'#{e.inspect}' should valid" 

you don't need e.inspect, e enough. like:

assert @chef.valid?, "'#{e}' should valid" 

one more suggestion is, can use instance of class activemodel::errors containing errors :

assert @chef.valid?, @chef.errors[:email] 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -