Sha256: ab61ce7e4cc53c3bc66918064a894f56169af6b393922dfa32c1947a4525e5e0

Contents?: true

Size: 1.32 KB

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
cms_scanner-0.0.18 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.17 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.16 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.15 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.14 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.13 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.12 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.11 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.10 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.9 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.8 spec/app/models/xml_rpc_spec.rb
cms_scanner-0.0.7 spec/app/models/xml_rpc_spec.rb