Sha256: c06c2248215583fb2af02d67d0d5817cf2f605790f36869d2bea9875ea3c1225

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'
require 'pact/app'

module Pact
  describe SpecCriteria do

    describe "#spec_criteria" do

      let(:env_description) { "pact description set in ENV"}
      let(:env_provider_state) { "provider state set in ENV"}
      let(:env_criteria){ {:description=>/#{env_description}/, :provider_state=>/#{env_provider_state}/} }

      let(:defaults) { {:description => default_description, :provider_state => default_provider_state} }

      let(:subject) { Pact::App.new }

      context "when ENV variables are defined" do
        before do
          ENV.stub(:[])
          ENV.stub(:[]).with("PACT_DESCRIPTION").and_return(env_description)
          ENV.stub(:[]).with("PACT_PROVIDER_STATE").and_return(env_provider_state)
        end

        it "returns the env vars as regexes" do
          expect(SpecCriteria.call).to eq(env_criteria)
        end
      end

      context "when ENV variables are not defined" do
        it "returns an empty hash" do
          expect(SpecCriteria.call).to eq({})
        end
      end

      context "when provider state is an empty string" do
        before do
          ENV.stub(:[]).with(anything).and_return(nil)
          ENV.stub(:[]).with("PACT_PROVIDER_STATE").and_return('')
        end

        it "returns a nil provider state so that it matches a nil provider state on the interaction" do
          expect(SpecCriteria.call[:provider_state]).to be_nil
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact-1.1.1 spec/lib/pact/app_spec.rb