I was writing unit tests for my models for a while. After that I was
tweaking around and again continued writing unit tests.
Earlier all my unit tests were working - successfully. But now WHen I
run them, it gives me
Loaded suite unit/post_test
Started
EEEE
Finished in 0.112698 seconds.
-
Error:
test_presence_of_body(PostTest):
NoMethodError: undefined method `key?’ for #String:0x103519a88 -
Error:
test_presence_of_body_and_title(PostTest):
NoMethodError: undefined method `key?’ for #String:0x1034dd420 -
Error:
test_presence_of_title(PostTest):
NoMethodError: undefined method `key?’ for #String:0x1034af750 -
Error:
test_title_minimum_width_3(PostTest):
NoMethodError: undefined method `key?’ for #String:0x103481a80
And my test cases are
class PostTest < ActiveSupport::TestCase
def test_presence_of_title
post = Post.new(:body=>“Some content”)
assert !post.save,“Saved post without title”
end
def test_presence_of_body
post = Post.new(:title=>“Some title”)
assert !post.save,“saved post without body”
end
def test_presence_of_body_and_title
post = Post.new(:title=>“Some title”,:body=>"")
assert !post.save,“Saved Post without body”
post = Post.new(:title => "",:body=>"Some body")
assert !post.save,"Saved Post without title"
post = Post.new(:title =>"",:body=>"")
assert !post.save,"Saved Post with title and body"
end
def test_title_minimum_width_3
post1 = Post.new(:title=>“a”,:body=>“This will not be saved”)
assert !post1.save,“Saved post with title length less than 3”
post2 = Post.new(:title=>"abcd",:body=>"This will be saved")
assert post2.save,"Couldnot save a valid post record"
post3 = Post.new(:title=>"abc",:body=>"This will be saved")
assert post3.save,"Could not save a valid record"
end
end
Please help
Thanks