Sha256: 18f8a790dad1e381402406ddb3cb1c785b34fbb89012910a580707ee3c0bed28

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'

RSpec.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
      pending { is_expected.to raise_error(described_class::PandorabotsError) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pandorified-0.9.3 spec/lib/pandorified_spec.rb
pandorified-0.9.2 spec/lib/pandorified_spec.rb
pandorified-0.9.1 spec/lib/pandorified_spec.rb