Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Savon mocks, cannot stub a request without a message. #402

Closed
jessegoodnoe opened this issue Mar 1, 2013 · 7 comments
Closed

Using Savon mocks, cannot stub a request without a message. #402

jessegoodnoe opened this issue Mar 1, 2013 · 7 comments
Milestone

Comments

@jessegoodnoe
Copy link

Per the documentation, I'd expect that I could stub a request without a message and with a return. But when there's an actual request that has a message, the expectation fails.

I would have thought that stubbing the request without a message would allow any message on the actual request.

From: http://savonrb.com/version2.html#options

If you're trying to "stub" a request, you can simply leave out the #with method, but you need to call the #returns method to return a response that Savon can work with.

Example

Here's an rspec example that illustrates what I'm trying to do. It can be put into spec/savon/mock_spec.rb.

  it "works with no message and a return" do
    authentication_message = { :username => "luke", :password => "secret" }
    savon.expects(:authenticate).returns("<fixture/>")
    expect { new_client.call(:authenticate, :message => authentication_message) }.to_not raise_error
  end
@rubiii
Copy link
Contributor

rubiii commented Mar 19, 2013

thanks. i'll test that.

@rubiii
Copy link
Contributor

rubiii commented Mar 19, 2013

i was a little confused by this as well, but as it turns out, there's actually a spec for it.
i don't know if it makes sense to always have to specify the message in your tests though.

@jessegoodnoe
Copy link
Author

I agree, I don't think you should always have to specify the message.

In my use case, I don't care what's in the message, I care about the return. Other stubbing frameworks I've used stub the method but don't care about the message unless it's specified.

My preference would be:

# Message required and must match. (existing functionality.)
savon.expects(:find_user).with(:message => some_message).returns("<fixture/>")

# Message is ignored whether it exists or not
savon.expects(:find_user).returns("<fixture/>")

But, maybe a way to fix it without breaking people's existing tests is something like this:

# Message required and must match. (existing functionality.)
savon.expects(:find_user).with(:message => some_message).returns("<fixture/>")
# No message expected (existing functionality.)
savon.expects(:find_user).returns("<fixture/>")

# Some message required, but contents don't matter
savon.expects(:find_user).with(:message => :any).returns("<fixture/>")

@rubiii
Copy link
Contributor

rubiii commented Mar 19, 2013

thanks for following up. that would certainly be an easy fix. i think i'm ok with that.
i'm not having the time to do this, but if you want to give it a try ...

@jessegoodnoe
Copy link
Author

Sure, but I'm not clear which fix you like, the (:message => :any) or changing the existing behavior so that the lack of a message will not result in an exception.

@rubiii
Copy link
Contributor

rubiii commented Mar 22, 2013

oh sorry, i would go with the message: :any option for now, because it's backwards compatible.

@rubiii
Copy link
Contributor

rubiii commented Apr 19, 2013

@jessegoodnoe any updates on this one?

koppen added a commit to koppen/savon that referenced this issue May 12, 2013
Previously, there was no way to create a mock without expectation of the
specific message to be sent to the SOAP action.

Contrary to the documentation, leaving out the `with` method would result in an
expectation that the action be called without a message.

This change adds a special case to `#with` so that calling `#with(message: :any)`
ends up setting an expectation that the SOAP action be called, but
without caring about the actual message sent to the action.

This way the following will pass:

    savon.expects(:authenticate).with(message: :any)
    client.call(:authenticate)
    client.call(:authenticate, message: { username: "luke", password: "secret" })
@rubiii rubiii closed this as completed in 90f56e0 May 12, 2013
rubiii added a commit that referenced this issue May 12, 2013
Allow Savon mocks to receive any message. Closes #402
@rubiii rubiii mentioned this issue Jul 20, 2013
27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants