spec/lib/pact/tasks/task_helper_spec.rb in pact-1.1.0 vs spec/lib/pact/tasks/task_helper_spec.rb in pact-1.1.1
- old
+ new
@@ -1,80 +1,65 @@
require 'spec_helper'
require 'pact/tasks/task_helper'
+require 'rake/file_utils'
module Pact
describe TaskHelper do
- include TaskHelper
- 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(:default_description) { "default description"}
- let(:default_provider_state) { "default provider state"}
- shared_context "PACT_DESCRIPTION is defined" do
- before do
- ENV.stub(:[])
- ENV.stub(:[]).with("PACT_DESCRIPTION").and_return(env_description)
- end
- end
+ describe ".execute_pact_verify" do
+ let(:ruby_path) { "/path/to/ruby" }
+ let(:pact_uri) { "/pact/uri" }
+ let(:default_pact_helper_path) { "/pact/helper/path.rb" }
- shared_context 'PACT_PROVIDER_STATE is defined' do
before do
- ENV.stub(:[])
- ENV.stub(:[]).with("PACT_PROVIDER_STATE").and_return(env_provider_state)
+ stub_const("FileUtils::RUBY", ruby_path)
+ allow(Pact::Provider::PactHelperLocater).to receive(:pact_helper_path).and_return(default_pact_helper_path)
end
- end
- shared_context 'default description is defined' do
- let(:default_description) { "default description"}
- end
-
- let(:defaults) { {:description => default_description, :provider_state => default_provider_state} }
-
- describe "spec_criteria" do
-
- context "when ENV variables are defined" do
- before do
- ENV.stub(:fetch).with("PACT_DESCRIPTION", anything).and_return(env_description)
- ENV.stub(:fetch).with("PACT_PROVIDER_STATE", anything).and_return(env_provider_state)
+ context "with no pact_helper or pact URI" do
+ let(:command) { "#{ruby_path} -S pact verify -h #{default_pact_helper_path}" }
+ it "executes the command" do
+ expect(TaskHelper).to receive(:execute_cmd).with(command)
+ TaskHelper.execute_pact_verify
end
+ end
- context "when defaults are not passed in" do
- it "returns the env vars as regexes" do
- expect(spec_criteria).to eq(env_criteria)
- end
+ context "with a pact URI" do
+ let(:command) { "#{ruby_path} -S pact verify -h #{default_pact_helper_path} -p #{pact_uri}" }
+ it "executes the command" do
+ expect(TaskHelper).to receive(:execute_cmd).with(command)
+ TaskHelper.execute_pact_verify(pact_uri)
end
+ end
- context "when defaults are passed in" do
- it "returns the env vars as regexes" do
- expect(spec_criteria(defaults)).to eq(env_criteria)
- end
+ context "with a pact URI and a pact_helper" do
+ let(:custom_pact_helper_path) { '/custom/pact_helper.rb' }
+ let(:command) { "#{ruby_path} -S pact verify -h #{custom_pact_helper_path} -p #{pact_uri}" }
+ it "executes the command" do
+ expect(TaskHelper).to receive(:execute_cmd).with(command)
+ TaskHelper.execute_pact_verify(pact_uri, custom_pact_helper_path)
end
end
- context "when ENV variables are not defined" do
- context "when defaults are passed in" do
- it "returns the defaults as regexes" do
- expect(spec_criteria(defaults)).to eq({:description=>/#{default_description}/, :provider_state=>/#{default_provider_state}/})
- end
+ context "with a pact_helper with no .rb on the end" do
+ let(:custom_pact_helper_path) { '/custom/pact_helper' }
+ let(:command) { "#{ruby_path} -S pact verify -h #{custom_pact_helper_path}.rb -p #{pact_uri}" }
+ it "executes the command" do
+ expect(TaskHelper).to receive(:execute_cmd).with(command)
+ TaskHelper.execute_pact_verify(pact_uri, custom_pact_helper_path)
end
- context "when defaults are not passed in" do
- it "returns an empty hash" do
- expect(spec_criteria).to eq({})
- end
- end
end
- context "when provider state is an empty string" do
- before do
- ENV.stub(:fetch).with(anything, anything).and_return(nil)
- ENV.stub(:fetch).with("PACT_PROVIDER_STATE", anything).and_return('')
+ context "with a pact URI and a nil pact_helper" do
+ let(:command) { "#{ruby_path} -S pact verify -h #{default_pact_helper_path} -p #{pact_uri}" }
+ it "executes the command" do
+ expect(TaskHelper).to receive(:execute_cmd).with(command)
+ TaskHelper.execute_pact_verify(pact_uri, nil)
end
-
- it "returns a nil provider state so that it matches a nil provider state on the interaction" do
- expect(spec_criteria[:provider_state]).to be_nil
- end
end
+
end
+
+
end
end