I am stubbing an http request with stub_request
. This http request is basically a slack notification, that contains some random string (e.g. a timestamp.)
So, I can not just reuse the snippet, rspec
spits out to me, because body differs on every execution. Is there any possibility to stub a request with, say, pattern, or I am stuck to hook e.g. the Slack#ping
?
The dried code, jic:
mutation
class MyMutation < Mutations::Command
def run
slack.ping "#{rand (1..1000)}"
end
end
spec
describe MyMutation do
# ??? stub_request ???
it 'succeeded' do
expect(MyMutation.new.run.outcome).to be_success
end
end
Thanks.
UPD stub request:
stub_request(:post, "https://hooks.slack.com/services/SECRETS").
with(:body => {"payload"=>"{SLACK_RELATED_PROPS,\"text\":\"MY_RANDOM_HERE\"}"},
:headers => {'Accept'=>'*/*', MORE_HEADERS}).
to_return(:status => 200, :body => "", :headers => {})