Sha256: 4e57c5d94549046978cc8c0d410020e6c2f49036395439fe2603ed6fe50c8dc6

Contents?: true

Size: 749 Bytes

Versions: 3

Compression:

Stored size: 749 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 nil' do
      get '/', name: nil
      expect(last_response.status).to eq(400)
    end
  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.11.0 spec/grape/validations/validators/regexp_spec.rb
grape-0.10.1 spec/grape/validations/validators/regexp_spec.rb
grape-0.10.0 spec/grape/validations/validators/regexp_spec.rb