【发布时间】:2016-11-14 23:47:32
【问题描述】:
我正在尝试运行控制器测试: 控制器代码是
def aix_service_accounts
@no_dn_users= Hash.new
record = 0
@no_dn_users[record]= Hash.new
@no_dn_users[record]['aix_username'] ="abc"
end
rspec 代码是
it "should show aix_service_accounts" do
get :aix_service_accounts
expect(assigns(:no_dn_users[0]['aix_username'])).to eq 'abc'
end
结果是
失败:
1) AixController 应该显示 aix_service_accounts 失败/错误:expect(assigns(:no_dn_users[0]['aix_username'])).to eq 'abc'
expected: "abc"
got: {"marked_for_same_origin_verification"=>true, "no_dn_users"=>{0=>{"aix_username"=>"abc"}}}
(compared using ==)
Diff:
@@ -1,2 +1,3 @@
-"abc"
+"marked_for_same_origin_verification" => true,
+"no_dn_users" => {0=>{"aix_username"=>"abc"}},
# ./spec/controllers/aix_controller_spec.rb:29:in `block (2 levels) in <top (required)>'
谁能帮我解释一下原因?谢谢!
【问题讨论】:
标签: ruby-on-rails ruby hash rspec controller