Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby NameError:未初始化的常量链接\u测试::Nill_Ruby_Linked List_Nameerror - Fatal编程技术网

Ruby NameError:未初始化的常量链接\u测试::Nill

Ruby NameError:未初始化的常量链接\u测试::Nill,ruby,linked-list,nameerror,Ruby,Linked List,Nameerror,我正试图通过minitest创建一个测试来测试我的类LinkedList 我收到此错误消息: 1) Error: Linked_ListTest#test_next_node_after_head_is_nil: NameError: uninitialized constant Linked_ListTest::Nil test/linked_list_test.rb:26:in `test_next_node_after_head_is_nil' This is my test: 24 d

我正试图通过minitest创建一个测试来测试我的类LinkedList

我收到此错误消息:

1) Error:
Linked_ListTest#test_next_node_after_head_is_nil:
NameError: uninitialized constant Linked_ListTest::Nil
test/linked_list_test.rb:26:in `test_next_node_after_head_is_nil'

This is my test:
24 def test_next_node_after_head_is_nil
25  list = LinkedList.new
26  assert_equal Nil, head.next_node
27 end
我的预期行为是:

list.head.next_节点 =>零

这是我的LinkedList类

class LinkedList

 attr_reader :head


 def initialized(data = nil)
  @head = Node.new(data)
 end

 def append(sound)
 "doop"
 end

 def next_node
  nil
 end


end

我不确定这个错误对第26行意味着什么。

记住,情况很重要,nil存在于ruby中表示NULL,但nil不存在;因此,在断言中使用nil而不是nil:

assert_equal nil, head.next_node

一定是因为没有休息让我忽略了这一点。谢谢@山姆很乐意帮忙!请不要忘记点击勾号接受答案:没问题!我只是没有足够的重复次数believe@Sam仅当您要向上投票单击向上箭头或向下投票单击向下箭头时,才需要Rep;他回答;但是,您可以在没有任何限制的情况下,通过单击任何代表的勾号将答案标记为已接受。