将多个参数传递给方法

时间:2014-08-11 21:19:07

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

以下是我的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

如何通过在this test pass内传递idauthorization来制作with

1 个答案:

答案 0 :(得分:0)

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

这意味着你将一个参数传递给'find':一个哈希。

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

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

相关问题