Sha256: ce696094828073d6892152343aedf378f8d59e0b72d7aaa4a37e9bbfeddfc57b

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

RSpec.describe "Passing additional arguments to step operations" do
  let(:call_transaction) { transaction.call(input, step_options) }

  let(:transaction) {
    Dry.Transaction(container: container) do
      map :process
      try :validate, catch: Test::NotValidError
      tee :persist
    end
  }

  let(:container) {
    {
      process:  -> input { {name: input["name"], email: input["email"]} },
      validate: -> allowed, input { !input[:email].include?(allowed) ? raise(Test::NotValidError, "email not allowed") : input },
      persist:  -> input { Test::DB << input and true }
    }
  }

  let(:input) { {"name" => "Jane", "email" => "jane@doe.com"} }

  before do
    Test::NotValidError = Class.new(StandardError)
    Test::DB = []
  end

  context "required arguments provided" do
    let(:step_options) { {validate: ["doe.com"]} }

    it "passes the arguments and calls the operations successfully" do
      expect(call_transaction).to be_a Kleisli::Either::Right
    end
  end

  context "required arguments not provided" do
    let(:step_options) { {} }

    it "raises an ArgumentError" do
      expect { call_transaction }.to raise_error(ArgumentError)
    end
  end

  context "spurious arguments provided" do
    let(:step_options) { {validate: ["doe.com"], bogus: ["not matching any step"]} }

    it "raises an ArgumentError" do
      expect { call_transaction }.to raise_error(ArgumentError)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-transaction-0.6.0 spec/integration/passing_step_arguments_spec.rb
dry-transaction-0.5.0 spec/integration/passing_step_arguments_spec.rb
dry-transaction-0.4.0 spec/integration/passing_step_arguments_spec.rb