# encoding: utf-8 require 'spec_helper' require 'fedux_org_stdlib/version_management/rubygem_version_file' RSpec.describe FeduxOrgStdlib::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 = FeduxOrgStdlib::VersionManagement::RubygemVersionFile.new(version, library) expect(version_file.to_s).to eq(<<-EOS.strip_heredoc # encoding: utf-8 # 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 = FeduxOrgStdlib::VersionManagement::RubygemVersionFile.new(version, library) expect(version_file.to_s).to eq(<<-EOS.strip_heredoc # encoding: utf-8 # 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 = FeduxOrgStdlib::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 # encoding: utf-8 # MyLibrary module MyLibrary VERSION = '0.0.0' end EOS ) result = FeduxOrgStdlib::VersionManagement::RubygemVersionFile.read(version_file, parser, version_builder, library_builder) expect(result).to be_kind_of(FeduxOrgStdlib::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 = FeduxOrgStdlib::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 = FeduxOrgStdlib::VersionManagement::RubygemVersionFile.new(version, library) version_file.bump(:major) expect(version_file.version).to eq('1.0.0') end end end end