【问题标题】:Passing multiple parameters to with method将多个参数传递给 with 方法
【发布时间】:2014-08-11 21:19:06
【问题描述】:

下面是我的model 方法,它接受一个id 和auth 令牌。

Project.find( id: '22', authorization: auth)

下面是我的测试。

require 'project'

RSpec.describe Project do
  it 'finds an project' do
    project = class_double("project")    
    expect(project).to receive(:find).with() 
                             // How can i send id and authorization inside with       
  end
end

如何通过在with 中传递id 和authorization 来生成this test pass?。

【问题讨论】:

  • 当您将 id 和 auth 都传递给 with 时,您看到了什么错误?如果您在某处定义 id 和 auth,您应该可以在代码中使用:expect(project).to receive(:find).with(id, auth)。

标签: ruby-on-rails ruby ruby-on-rails-4 rspec rspec3


【解决方案1】:

Project.find(id: '22', authorization: auth) 是以下的简写: Project.find({id: '22', authorization: auth})

这意味着您将一个参数传递给“查找”:哈希。

expect(project).to receive(:find).with({id: the_id, authorization: the_auth})

如果你愿意,你可以省略花括号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    相关资源
    最近更新 更多