Sha256: 1a914848dffbcc71ad5783930e8710555dff04fdd3d54808e4742fbe27458f7e

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

#--
# gravaty
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019  Marco Bresciani
#
# This file is part of gravaty.
#
# gravaty is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# gravaty is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
#++

require_relative '../test_helper'

describe Gravaty::Gravaty do
  describe 'when using a parser ' do

    subject {Gravaty::parser}

    it 'shall provide a list of parsers' do
      subject.parsers.wont_be_empty
    end

    it 'shall provide all needed parsers' do
      subject.parsers.length.must_equal Gravaty::ALLOWED_PARAMS.length
      subject.parsers.keys.must_equal Gravaty::ALLOWED_PARAMS
    end

    it 'shall use the parsable duck type' do
      parsable_mocks = {}

      Gravaty::ALLOWED_PARAMS.each do |param|
        parsable_mocks[param] = MiniTest::Mock.new
        parsable_mocks[param].expect(:parse, false, [nil])
        parsable_mocks[param].expect(:nil?, false)
      end

      my_parser = Gravaty::Parser.new(parsable_mocks)

      Gravaty::ALLOWED_PARAMS.each do |param|
        my_parser.parse(param, nil)
        parsable_mocks[param].verify
      end
    end

    it 'shall die gracefully whether parameters are not valid' do
      a_parser = Gravaty::Parser.new(nil)
      a_parser.parse
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gravaty-9.0.1 test/gravaty/test_parser.rb
gravaty-9.0.0 test/gravaty/test_parser.rb