Sha256: 995de01e2b388633d0ca24a871fbca1dff1601262017ed910c5d70b2d293bdb9

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe 'Parameter Sets' do
  describe 'one_of' do
    it 'returns 400 on requests that contain more than one mutually exclusive parameter' do
      params = [
        {a: 1, b: 2},
        {b: 2, c: 3},
        {a: 1, b: 2, c: 3}
      ]

      params.each do |param|
        get('/one_of/3', param) do |response|
          expect(response.status).to eql 400
          expect(JSON.parse(response.body)['message']).to match(/^Invalid parameters/)
        end
      end
    end

    it 'returns 400 on requests that contain more than one mutually exclusive parameter' do
      params = {a: 1, b: 2}

      get('/one_of/2', params) do |response|
        expect(response.status).to eql 400
        expect(JSON.parse(response.body)['message']).to match(/^Invalid parameters/)
      end
    end

    it 'returns successfully for requests that have one parameter' do
      params = [
        {a: 1},
        {b: 2},
        {c: 3}
      ]

      (1..3).each do |n|
        params.each do |param|
          get("/one_of/#{n}", param) do |response|
            expect(response.status).to eql 200
            expect(JSON.parse(response.body)['message']).to match(/OK/)
          end
        end
      end
    end

    it 'returns successfully for requests that have no parameter' do
      (1..3).each do |n|
        get("/one_of/#{n}") do |response|
          expect(response.status).to eql 200
          expect(JSON.parse(response.body)['message']).to match(/OK/)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
jdx-sinatra-param-0.0.1 spec/parameter_exclusivity_spec.rb
sinatra-param-1.6.0 spec/parameter_exclusivity_spec.rb
sinatra-param-1.5.0 spec/parameter_exclusivity_spec.rb
sinatra-param2-1.0.0 spec/parameter_exclusivity_spec.rb
sinatra-param-1.4.0 spec/parameter_exclusivity_spec.rb