Sha256: 617c908bbac206eb0472a9326d10ccecc957acce785fef7c299240f79cb39a8c

Contents?: true

Size: 846 Bytes

Versions: 3

Compression:

Stored size: 846 Bytes

Contents

require 'spec_helper'

describe Grape::Validations::RegexpValidator do
  module ValidationsSpec
    module RegexpValidatorSpec
      class API < Grape::API
        default_format :json

        params do
          requires :name, regexp: /^[a-z]+$/
        end
        get do
        end
      end
    end
  end

  def app
    ValidationsSpec::RegexpValidatorSpec::API
  end

  context 'invalid input' do
    it 'refuses inapppopriate' do
      get '/', name: 'invalid name'
      expect(last_response.status).to eq(400)
    end

    it 'refuses empty' do
      get '/', name: ''
      expect(last_response.status).to eq(400)
    end
  end

  it 'accepts nil' do
    get '/', name: nil
    expect(last_response.status).to eq(200)
  end

  it 'accepts valid input' do
    get '/', name: 'bob'
    expect(last_response.status).to eq(200)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-0.14.0 spec/grape/validations/validators/regexp_spec.rb
grape-0.13.0 spec/grape/validations/validators/regexp_spec.rb
grape-0.12.0 spec/grape/validations/validators/regexp_spec.rb