require 'spec_helper' describe Commit do let(:project) { create :project } let(:commit) { project.commit } describe '#title' do it "returns no_commit_message when safe_message is blank" do allow(commit).to receive(:safe_message).and_return('') expect(commit.title).to eq("--no commit message") end it "truncates a message without a newline at 80 characters" do message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.' allow(commit).to receive(:safe_message).and_return(message) expect(commit.title).to eq("#{message[0..79]}…") end it "truncates a message with a newline before 80 characters at the newline" do message = commit.safe_message.split(" ").first allow(commit).to receive(:safe_message).and_return(message + "\n" + message) expect(commit.title).to eq(message) end it "does not truncates a message with a newline after 80 but less 100 characters" do message =<(txt){ subject.stub(safe_message: txt) } } # Include the subject in the repository stub. let(:extra_commits) { [subject] } end end