3

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

2
  • what is the full error? on which line is it? Commented Dec 14, 2014 at 6:28
  • line: @search_task.search(query: params[:query]).load message: wrong number of arguments (0 for 1). Commented Dec 14, 2014 at 11:36

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.