Rimian
Rimian

Reputation: 38458

Ruby Mocha expect the first argument to be a symbol

I'm trying to assert a method call happens where the first argument is a symbol like so:

Foo.bar(:some_key, {})

I don't really care what the second argument is at this stage.

I've tried:

Foo.expects(:bar).with(includes(:some_key))

and other variations found in the documentation here. The test passes when I expect the method call with any arguments.

Any ideas?

Upvotes: 1

Views: 522

Answers (1)

Thomas
Thomas

Reputation: 1633

Have you tried this :

Foo.expects(:bar).with(:some_key, anything)

If you need to be more specific you can also use a block :

Foo.expects(:bar).with do |first_arg, second_arg|
  first_arg == :some_key
end

Upvotes: 5

Related Questions