require 'spec_helper' require 'fedux_org/stdlib/version_management/rubygem_version_file' describe FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile do context '#to_s' do it 'outputs the content for version file' do version = double( 'Version' ) expect(version).to receive( :to_s ).and_return( '0.0.0' ) library = double( 'RubyLibrary' ) expect(library).to receive( :module_names ).and_return( [ 'MyLibrary' ] ) version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library ) expect( version_file.to_s ).to eq(<<-EOS.strip_heredoc #main MyLibrary module MyLibrary VERSION = '0.0.0' end EOS ) end it 'outputs the content for version file for a more deeply nested module' do version = double( 'Version' ) expect(version).to receive( :to_s ).and_return( '0.0.0' ) library = double( 'RubyLibrary' ) expect(library).to receive( :module_names ).and_return( [ 'MyLibrary', 'MyClass' ] ) version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library ) expect( version_file.to_s ).to eq(<<-EOS.strip_heredoc #main MyLibrary module MyLibrary module MyClass VERSION = '0.0.0' end end EOS ) end end context '#write' do it 'writes the generated version file to disk' do version = double( 'Version' ) expect(version).to receive( :to_s ).and_return( '0.0.0' ) library = double( 'RubyLibrary' ) expect(library).to receive( :module_names ).and_return( [ 'MyLibrary', 'MyClass' ] ) version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library ) switch_to_working_directory do version_file.write( 'version.rb' ) expect( File ).to be_exists( 'version.rb' ) end end context '#read' do it 'reads a version file and handover parsing to parser' do version = double( 'Version' ) library = double( 'Library' ) version_builder = double( 'VersionBuilder' ) expect( version_builder ).to receive( :build_from ).with( '0.0.0' ).and_return( version ) library_builder = double( 'LibraryBuilder' ) expect( library_builder ).to receive( :build_from ).with( [ 'MyModule' ] ).and_return( library ) parser = double( 'Parser' ) expect( parser ).to receive( :parse ) expect( parser ).to receive( :version ).and_return( '0.0.0' ) expect( parser ).to receive( :modules ).and_return( [ 'MyModule' ] ) version_file = create_file( 'version.rb', <<-EOS.strip_heredoc #main MyLibrary module MyLibrary VERSION = '0.0.0' end EOS ) result = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.read( version_file, parser, version_builder, library_builder ) expect( result ).to be_kind_of( FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile ) end end context '#version' do it "returns the version for the file" do version = double( 'Version' ) expect(version).to receive( :to_s ).and_return( '0.0.0' ) library = double( 'RubyLibrary' ) version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library ) expect( version_file.version ).to eq('0.0.0' ) end end context '#bump' do it "bumps versions" do version = double( 'Version' ) expect(version).to receive( :bump ).with( :major ) expect(version).to receive( :to_s ).and_return( '1.0.0' ) library = double( 'RubyLibrary' ) version_file = FeduxOrg::Stdlib::VersionManagement::RubygemVersionFile.new( version, library ) version_file.bump( :major ) expect( version_file.version ).to eq('1.0.0' ) end end end end