简体   繁体   English

运行RSpec集成测试时,NoMethodError未定义方法“合并”

[英]NoMethodError undefined method 'merge' when running RSpec integration test

I am following Micheal Hartl's Ruby on rails tutorial 2.3 Edition and I have followed the steps for the integration tests correctly. 我正在遵循Micheal Hartl的Ruby on Rails教程2.3版,并且已经正确执行了集成测试的步骤。 in /sample_app/spec/integration I have a file named layout_links_spec.rb which looks like this. / sample_app / spec / integration中,我有一个名为layout_links_spec.rb的文件,看起来像这样。

require 'spec_helper'
describe "Layout links" do
 it "should have a Home page at '/'" do
  get '/'
   response.should render_template('pages/home')
  end
 end

When i do 当我做

$ spec spec/

I am getting the following error 我收到以下错误

1)
NoMethodError in 'Layout links should have a Home page at '/''
undefined method `merge' for nil:NilClass
 /home/rails_projects/sample_app/spec/integration/layout_links_spec.rb:4:

Finished in 0.060225 seconds

1 example, 1 failure

Please help me with this error 请帮我解决这个错误

Based on this question, it looks to me like you are following the 1st edition of his tutorial. 基于这个问题,在我看来,您正在关注他的教程的第1版。 If so, the command he used to generate the integration test is on page 178, Section 5.2.1 如果是这样,他用来生成集成测试的命令在第178页的5.2.1节。

rails generate integration_test layout_links

The result is a file under spec/requests/layout_links_spec.rb 结果是spec / requests / layout_links_spec.rb下的文件


If you browse the source code for his app, there isn't a spec/integration folder. 如果您浏览他的应用程序的源代码,则没有spec / integration文件夹。 Take a look here and see if this helps. 在这里看看,是否有帮助。 Hope so. 希望如此。

PS: He comments "In RSpec, integration tests are also called request specs - the origins of this terminology are obscure to me." PS:他评论说:“在RSpec中,集成测试也称为请求规范 -该术语的起源对我来说是晦涩的。”

In the RSpec docs , I found this: Request specs provide a thin wrapper around Rails' integration tests, and are designed to drive behavior through the full stack, including routing (provided by Rails) and without stubbing (that's up to you). 在RSpec 文档中 ,我发现了这一点:请求规范为Rails的集成测试提供了一个薄薄的包装,并旨在在整个堆栈中推动行为,包括路由(由Rails提供)而没有存根(由您决定)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在其中一种方法上运行RSpec测试时遇到NoMethodError:undefined method`user&#39; - I'm getting NoMethodError: undefined method `user' when I run an RSpec test on one of my methods NoMethodError:运行rspec并进行get / visit调用时未定义的方法`get' - NoMethodError: undefined method `get' when running rspec and making get/visit calls NoMethodError:rspec测试中未定义的方法`symbolize_keys&#39; - NoMethodError:undefined method `symbolize_keys' in rspec test 使用存根运行rspec测试时的未定义方法 - Undefined Method when running rspec test using a stub NoMethodError:未定义的方法`user =&#39;rspec - NoMethodError: undefined method `user=' rspec NoMethodError:RSpec的未定义方法“ get” - NoMethodError: undefined method `get' for RSpec Rails-RSpec NoMethodError:未定义的方法 - Rails - RSpec NoMethodError: undefined method RSpec NoMethodError:未定义的方法`assign&#39; - RSpec NoMethodError: undefined method `assign' NoMethodError:#的未定义方法“访问” - NoMethodError: undefined method `visit' for #<RSpec:: Rails 5集成测试失败,出现NoMethodError:使用Devise helper sign_in时nil:NilClass的未定义方法&#39;[] =&#39; - Rails 5 Integration test fails with NoMethodError: undefined method `[]=' for nil:NilClass when using Devise helper sign_in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM