简体   繁体   中英

NoMethodError undefined method 'merge' when running RSpec integration test

I am following and I have followed the steps for the integration tests correctly. 并且已经正确执行了集成测试的步骤。 in I have a file named which looks like this. 我有一个名为的文件,看起来像这样。

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. If so, the command he used to generate the integration test is on page 178, Section 5.2.1

rails generate integration_test layout_links

The result is a file under spec/requests/layout_links_spec.rb


If you browse the source code for his app, there isn't a spec/integration folder. 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."

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM