# Unknown Method key? error in Rails 2.3.8 Unit testing

**URL:** <https://www.ruby-forum.com/t/unknown-method-key-error-in-rails-2-3-8-unit-testing/191501>\
**Category:** Rails\
**Created:** [July 13, 2010, 3:27pm UTC](https://www.ruby-forum.com/t/unknown-method-key-error-in-rails-2-3-8-unit-testing/191501 "2010-07-13T15:27:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luckydev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/eb8c5e/32.png) [@luckydev](https://www.ruby-forum.com/u/luckydev)\
**Post date:** [July 13, 2010, 3:27pm UTC](https://www.ruby-forum.com/t/unknown-method-key-error-in-rails-2-3-8-unit-testing/191501/1 "2010-07-13T15:27:07Z")

</div>

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.

1. Error:  
test\_presence\_of\_body(PostTest):  
NoMethodError: undefined method `key?’ for #String:0x103519a88

2. Error:  
test\_presence\_of\_body\_and\_title(PostTest):  
NoMethodError: undefined method `key?’ for #String:0x1034dd420

3. Error:  
test\_presence\_of\_title(PostTest):  
NoMethodError: undefined method `key?’ for #String:0x1034af750

4. 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
