Reputation: 4257
I am try testing a method call that receive a named argument, like this:
expect(@fake_task_search).to receive(:search).with({:query=>"a"})
@repo.all({query: "a"})
And the SUT
def all(params)
@search_task.search(query: params[:query]).load
end
When I ran this I receive this:w rong number of arguments (0 for 1).
Any help will be great.
Thanks
Upvotes: 3
Views: 7612
Reputation: 181
Call matcher the same way you call method .with(query: "a")
class Repo
def initialize(search_task)
@search_task = search_task
end
def all(params)
@search_task.search(query: params[:query])
end
end
it "calls" do
@search_task = SearchTask.new
@repo = Repo.new(@search_task)
expect(@search_task).to receive(:search).with(query: "a")
@repo.all({query: "a"})
end
Upvotes: 6