How to use Webmock to stub request with any body and header? I tried to use regex
WebMock.stub_request(:post, 'api.quickblox.com/').with(:body => /.*?/, :headers => /.*?/).to_return(:status => 201, :body => "", :headers => {})
in rspec but it doesn't work, it has
NoMethodError:
undefined method `map' for /.*?/:Regexp
You should be able to just use
If you don't specify the body or headers on the stub itself, it will allow anything for the body or headers. This does not apply to query parameters.
For example, this sample project's test passes:
bundle exec rspec
output:lib/test.rb
spec/test_spec.rb
.ruby-version
Gemfile
Gemfile.lock
Check out the
Webmock
docs onheaders
. You need to provide it a hash with further details on what you are matching.