Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/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 on rails 4 RSpec include未能找到对象_Ruby On Rails 4_Rspec - Fatal编程技术网

Ruby on rails 4 RSpec include未能找到对象

Ruby on rails 4 RSpec include未能找到对象,ruby-on-rails-4,rspec,Ruby On Rails 4,Rspec,首先,我对使用RSpec还比较陌生,对Rails也比较陌生,所以与我过去的语言经验相比,我仍然在弄清楚这项技术是如何工作的 问题是,RSpec没有通过测试,我不知道我遗漏了什么 测试正在测试控制器的GET索引 测试: it "populates an array of profiles" do profile = create(:profile) get :index expect(:profiles).to include(profile) end 结果是: 1) Profil

首先,我对使用RSpec还比较陌生,对Rails也比较陌生,所以与我过去的语言经验相比,我仍然在弄清楚这项技术是如何工作的

问题是,RSpec没有通过测试,我不知道我遗漏了什么

测试正在测试控制器的GET索引

测试:

it "populates an array of profiles" do
  profile = create(:profile)
  get :index
  expect(:profiles).to include(profile)
end
结果是:

 1) ProfilesController GET #index populates an array of profiles
 Failure/Error: expect(:profiles).to include(profile)

   expected :profiles to include #<Profile id: 3, user_id: 2, name: "Kasandra Goldner", about: nil, country_code: nil, state_code: nil...15", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil>, but it does not respond to `include?`
   Diff:
   @@ -1,2 +1,2 @@
   -[#<Profile id: 3, user_id: 2, name: "Kasandra Goldner", about: nil, country_code: nil, state_code: nil, city: nil, created_at: "2017-02-27 03:42:15", updated_at: "2017-02-27 03:42:15", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil>]
   +:profiles

 # ./spec/controllers/profiles_controller_spec.rb:15:in `block (3 levels) in <top (required)>'
1)ProfilesController获取#索引填充一个配置文件数组
失败/错误:期望(:配置文件)。包括(配置文件)

预期:配置文件将包括#尝试在分配中包装
:配置文件
,以获取在控制器中设置的实例变量:

expect(assigns(:profiles)).to include(profile)

谢谢你,克里斯!