# encoding: utf-8 require 'spec_helper' require 'fedux_org_stdlib/version_management/rubygem_version_file_parser' RSpec.describe FeduxOrgStdlib::VersionManagement::RubygemVersionFileParser do let(:parser) { FeduxOrgStdlib::VersionManagement::RubygemVersionFileParser.new } context '#parse' do it 'extracts version number' do version_file = create_file('version.rb', <<-EOS.strip_heredoc #main MyLibrary module MyLibrary VERSION = '0.0.0' end EOS ) parser.parse(version_file) expect(parser.version).to eq('0.0.0') end it 'extracts modules' do version_file = create_file('version.rb', <<-EOS.strip_heredoc #main MyLibrary module MyLibrary VERSION = '0.0.0' end EOS ) parser.parse(version_file) expect(parser.modules).to eq([ 'MyLibrary' ]) end it 'extracts nested modules as well' do version_file = create_file('version.rb', <<-EOS.strip_heredoc #main MyLibrary module MyLibrary module MyClass VERSION = '0.0.0' end end EOS ) parser.parse(version_file) expect(parser.modules).to eq([ 'MyLibrary', 'MyClass' ]) end it 'fails if version cannot be extracted' do version_file = create_file('version.rb', <<-EOS.strip_heredoc #main MyLibrary EOS ) expect { parser.parse(version_file) }.to raise_error VersionManagement::Exceptions::VersionFileInvalid end end end