Sha256: 07b435c758e5b88277d629908d07b8e18753b53df376f6d5220bae082f17274f
Contents?: true
Size: 1.78 KB
Versions: 2
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true require 'spec_helper' describe Pandorified do describe '#talk!' do let(:input) { 'Are you a robot?' } let(:botid) { 'np218q9s7r346nqo' } let(:custid) { nil } let(:request_body) do { 'botid' => botid, 'custid' => nil, 'input' => input } end context 'when successful' do subject { described_class.talk!(input, botid, custid) } let(:that) { 'Of course not!' } let(:response_body) do <<~XML <result status="0" botid="#{botid}" custid="fec7cfc40e5b751a"><input>#{input}</input><that>#{that}</that></result>" XML end let(:response_headers) do { content_type: 'text/xml' } end before :each do stub_request(:post, 'https://www.pandorabots.com/pandora/talk-xml') .with(body: request_body) .to_return( status: 200, body: response_body, headers: response_headers ) end it { is_expected.to eq(that) } end context 'when unsuccessful' do subject { described_class.talk!(input, botid, custid) } let(:response_body) do <<~XML <result status="1" botid="#{botid}" custid="fec7cfc40e5b751a"><input>#{input}</input><message>Something went wrong!</message></result>" XML end let(:response_headers) do { content_type: 'text/xml' } end before :each do stub_request(:post, 'https://www.pandorabots.com/pandora/talk-xml') .with(body: request_body) .to_return( status: 200, body: response_body, headers: response_headers ) end it { expect { subject }.to raise_error(described_class::PandorabotsError) } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pandorified-0.9.13 | spec/lib/pandorified_spec.rb |
pandorified-0.9.12 | spec/lib/pandorified_spec.rb |