Sha256: 90f11bbdd040bf7dc7344b04eece1dd3f2b4cdf6a08644e892262e78243de73b

Contents?: true

Size: 1.78 KB

Versions: 85

Compression:

Stored size: 1.78 KB

Contents

RSpec.shared_examples 'a Hyrax workflow method' do
  before do
    raise 'workflow_method must be set with `let(:workflow_method)`' unless
      defined? workflow_method
  end

  subject { workflow_method }
  let(:expected_call_method_keywords){ [:target, :comment, :user] }


  describe '#call' do
    it "handles the :target, :comment, and :user keywords (but not other parameters that don't have defaults)" do
      parameters = subject.method(:call).parameters
      parameter_types = parameters.map(&:first)
      errors = []

      # If we have splat *args or **kwargs, the path is different
      if parameter_types.include?(:keyrest) || parameter_types.include?(:rest)
        parameters.each do |parameter|
          next if parameter.first == :keyrest
          next if parameter.first == :opt
          next if parameter.first == :key
          next if parameter.first == :rest
          next if expected_call_method_keywords.include?(parameter.last)
          errors << "Unexpected keyword argument: #{parameter.last.inspect} for #{workflow_method}"
        end
      else
        # We don't have splat args and need to make sure that each keyword parameter are handled
        must_have = expected_call_method_keywords.clone
        parameters.each do |parameter|
          next if parameter.first == :opt
          next if parameter.first == :key
          next if parameter.first == :rest
          if expected_call_method_keywords.include?(parameter.last)
            must_have -= [parameter.last]
          end
          errors << "Unexpected keyword argument: #{parameter.last.inspect} for #{workflow_method}"
        end
        if must_have.any?
          errors << "Missing keyword arguments for: #{must_have}"
        end
      end
      expect(errors).to(be_empty, errors.join("\n"))
    end
  end
end

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-5.0.4 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-5.0.3 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-5.0.2 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-5.0.1 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-5.0.0 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-5.0.0.rc3 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-5.0.0.rc2 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-5.0.0.rc1 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-3.6.0 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-4.0.0 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-4.0.0.rc3 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-4.0.0.rc2 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-4.0.0.rc1 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-3.5.0 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-4.0.0.beta2 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-3.4.2 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-4.0.0.beta1 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-3.4.1 lib/hyrax/specs/shared_specs/workflow_method.rb
hyrax-3.4.0 lib/hyrax/specs/shared_specs/workflow_method.rb