Unknown method key? Error in Rails 2.3.8 Testing Modules

I wrote block tests for my models for a while. After that, I tuned and continued to write unit tests again.

Previously, all of my unit tests worked - successfully. But now when I run them, he 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

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
+3
source share
1 answer

If it works, and now it is not, I would say that you could introduce some kind of error in your publication model. It's hard to say without the return line and code from your publishing model, but if you used the same code on your console, would you get the same error?

post = Post.new(:body=>"Some content")
post.save

From there, you should get a return route and a place to look for errors.

EDIT:

rake --trace, .

, , , - . assert test, .

assert false, "error message", . , , assert, - :

require 'test/unit'
include Test::Unit::Assertions
assert false, "error message"

:

Test::Unit::AssertionFailedError: this is a message.
<false> is not true.

, .

+1

Source: https://habr.com/ru/post/1754400/


All Articles