Sha256: fd78202be712f906fa747e2664cbc191907b331a0dce32b005405225b0bf32f5

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe CMSScanner::XMLRPC do

  subject(:xml_rpc) { described_class.new(url) }
  let(:url)      { 'http://example.com/xmlrpc' }

  describe '#request_body' do
    after { expect(xml_rpc.request_body(method, params)).to eq @expected }

    let(:method) { 'rpc-test' }
    let(:params) { [] }

    context 'when no params' do
      it 'returns the body w/o the params elements' do
        @expected = '<?xml version="1.0"?><methodCall>'
        @expected << "<methodName>#{method}</methodName>"
        @expected << '</methodCall>'
      end
    end

    context 'when params' do
      let(:params) { %w(p1 p2) }

      it 'returns the correct body' do
        @expected = '<?xml version="1.0"?><methodCall>'
        @expected << "<methodName>#{method}</methodName><params>"
        @expected << '<param><value><string>p1</string></value></param>'
        @expected << '<param><value><string>p2</string></value></param>'
        @expected << '</params></methodCall>'
      end
    end
  end

  describe '#call' do
    let(:method) { 'rpc-test' }

    it 'returns a Typhoeus::Response' do
      stub_request(:post, url).with(body: xml_rpc.request_body(method)).to_return(body: 'OK')

      response = xml_rpc.call(method)

      expect(response).to be_a Typhoeus::Response
      expect(response.body).to eq 'OK'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cms_scanner-0.0.6 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.5 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.4 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.3 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.2 spec/app/models/xml_rpc_spec.rb