【问题标题】:How to pass a hash in double如何以双精度传递哈希
【发布时间】:2019-05-17 06:25:43
【问题描述】:

在这种情况下,我有多个具有相同值的键,因此为了避免重复,我做了类似下面的操作

sports = [:cricket,:football,:basketball,:baseball,:rugby,:swimming,:table_tennis,:soccer,:karate]

final_hash = Hash.new

sports.each{|d| final_hash[d] = OpenStruct.new(categories: [], count: [], user_hash: {}, sport_count: [],  options: {}, period: "",stat_type: "" )  }

现在我想在我的双块中传递这个哈希,但是每当我这样做时都会出错

context 'For users details Page' do
  it 'should give the data' do
    ###now I want to pass the hash SO can anyone guide me how can I do it
    presenter =  double(UserPresenter, id: 1, sector_name: nil, final_hash)
  end
end

【问题讨论】:

  • **final_hash 应该这样做。 ** 会将Hash 分解为参数
  • @engineersmnky 成功了,谢谢

标签: ruby-on-rails rspec rspec3


【解决方案1】:

正如@engineersmnky 所建议的,在哈希上使用双 splat 运算符(**hash)对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 2010-10-31
    • 1970-01-01
    • 2015-08-22
    • 2015-06-05
    • 2020-10-18
    • 1970-01-01
    相关资源
    最近更新 更多