run_rspec_matchers_on_task_group

in elasticsearch-api/spec/rest_api/run_rspec_matchers.rb [18:111]


def run_rspec_matchers_on_task_group(task_group, test)
  if task_group.catch_exception?
    it 'sends the request and throws the expected error' do
      expect(task_group.exception).to match_error(task_group.expected_exception_message)
    end

    
    if task_group.has_match_clauses?
      task_group.match_clauses.each do |match|
        it 'contains the expected error in the request response' do
          regexp = if (val = match['match'].values.first.to_s).include?('\\s')
                     Regexp.new(val.gsub('\\\\', '\\').gsub('/', ''))
                   else
                     Regexp.new(Regexp.escape(val))
                   end
          expect(task_group.exception.message).to match(regexp)
        end
      end
    end
  else
    
    if task_group.has_match_clauses?
      task_group.match_clauses.each do |match|
        it "has the expected value (#{match['match'].values.join(',')}) in the response field (#{match['match'].keys.join(',')})" do
          expect(task_group.response).to match_response(match['match'], test)
        end
      end
    end

    
    if task_group.has_length_match_clauses?
      task_group.length_match_clauses.each do |match|
        it "the '#{match['length'].keys.join(',')}' field have the expected length" do
          expect(task_group.response).to match_response_field_length(match['length'], test)
        end
      end
    end

    
    if task_group.has_true_clauses?
      task_group.true_clauses.each do |match|
        it "sends the request and the '#{match['is_true']}' field is set to true" do
          expect(task_group.response).to match_true_field(match['is_true'], test)
        end
      end
    end

    
    if task_group.has_false_clauses?
      task_group.false_clauses.each do |match|
        it "sends the request and the '#{match['is_false']}' field is set to true" do
          expect(task_group.response).to match_false_field(match['is_false'], test)
        end
      end
    end

    
    if task_group.has_gte_clauses?
      task_group.gte_clauses.each do |match|
        it "sends the request and the '#{match['gte']}' field is greater than or equal to the expected value" do
          expect(task_group.response).to match_gte_field(match['gte'], test)
        end
      end
    end

    
    if task_group.has_gt_clauses?
      task_group.gt_clauses.each do |match|
        it "sends the request and the '#{match['gt']}' field is greater than the expected value" do
          expect(task_group.response).to match_gt_field(match['gt'], test)
        end
      end
    end

    
    if task_group.has_lte_clauses?
      task_group.lte_clauses.each do |match|
        it "sends the request and the '#{match['lte']}' field is less than or equal to the expected value" do
          expect(task_group.response).to match_lte_field(match['lte'], test)
        end
      end
    end

    
    if task_group.has_lt_clauses?
      task_group.lt_clauses.each do |match|
        it "sends the request and the '#{match['lt']}' field is less than the expected value" do
          expect(task_group.response).to match_lt_field(match['lt'], test)
        end
      end
    end
  end
end