Sha256: 024c6965c506c3024a6b2c4cb765d910c5e7e8aad1e6776488745cd116acdd13

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'

describe APIMatchers::ResponseBody::Base do
  let(:setup) { OpenStruct.new(:response_body_method => :body) }
  subject { APIMatchers::ResponseBody::Base.new(setup: setup, expected_node: :status) }

  describe "#matches?" do
    it "should raise Not Implemented Error" do
      expect {
        subject.matches?("foo")
      }.to raise_error(NotImplementedError, "not implemented on #{subject}")
    end
  end

  describe "#setup" do
    it "should read from the initialize" do
      expect(subject.setup).to equal setup
    end
  end

  describe "#expected_node" do
    it "should read from the initialize" do
      expect(subject.expected_node).to equal :status
    end
  end

  describe "#response_body" do
    let(:body) { { :foo => :bar}.to_json }

    context 'when have configuration' do
      it "should call the method when is config" do
        subject.actual = OpenStruct.new(:body => body)
        expect(subject.response_body).to eql body
      end
    end

    context 'when dont have configuration' do
      let(:setup) { OpenStruct.new(:response_body_method => nil) }
      subject { APIMatchers::ResponseBody::Base.new(setup: setup, expected_node: :status) }

      it "should return the actual when do not have config" do
        subject.actual = body
        expect(subject.response_body).to eql body
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
api_matchers-0.5.1 spec/api_matchers/response_body/base_spec.rb
api_matchers-0.5.0 spec/api_matchers/response_body/base_spec.rb