“赋值"是什么意思?在 Ruby on Rails 中做什么? [英] What does "assigns" do in Ruby on Rails?

查看:38
本文介绍了“赋值"是什么意思?在 Ruby on Rails 中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试学习 Ruby on Rails 和测试框架 RSpec.assigns 在这个 RSpec 测试中做了什么?

I am currently attempt to learn Ruby on Rails, and the testing framework RSpec. What does assigns do in this RSpec test?

 describe "GET index" do
    it "assigns all mymodel as @mymodel" do
      mymodel = Factory(:mymodel)
      get :index
      assigns(:mymodels).should eq([mymodel])
    end
  end

推荐答案

assigns 只是检查您在控制器中设置的实例变量的值.

assigns simply checks the value of the instance variables you set in your controller.

这里检查@mymodels.

这篇关于“赋值"是什么意思?在 Ruby on Rails 中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆