Skip to content

Instantly share code, notes, and snippets.

@jasdeepsingh
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdeepsingh/d154794a6578f9b95704 to your computer and use it in GitHub Desktop.
Save jasdeepsingh/d154794a6578f9b95704 to your computer and use it in GitHub Desktop.
recent_files_spec.rb
#====== Implement your solution below:
# class RecentFiles
# end
#====== Solution implementation ends
require 'rspec'
describe RecentFiles do
describe '#initialize' do
it 'can be initialized with an empty list' do
recent = RecentFiles.new([])
recent.files.should == []
end
it 'cannot be initialized without a list of file names' do
expect { recent = RecentFiles.new }.to raise_error
end
it 'can be initialized with less than 5 files' do
file_list = [1,2,3,4]
recent = RecentFiles.new(file_list)
recent.files.should eq(file_list)
end
it 'can contain maximum 5 files only/1st five' do
file_list = [1,2,3,4,5,6]
recent = RecentFiles.new(file_list)
recent.files.should eq(file_list[0..4])
end
end
describe '#list' do
it 'should return the list of the files' do
file_list = ['file1', 'file2', 'file3']
recent = RecentFiles.new(file_list)
recent.files.should eq(file_list)
end
it 'should return the running list' do
recent = RecentFiles.new(['file1', 'file2', 'file3'])
recent.add('file4')
recent.add('file5')
recent.files.should eq(['file5', 'file4', 'file1', 'file2', 'file3'])
end
end
describe '#add' do
it 'should be able to add files to the list' do
recent = RecentFiles.new([])
recent.add('filename')
recent.files.should include('filename')
end
it 'cannot contain duplicates' do
recent = RecentFiles.new([])
recent.add('filename')
recent.add('filename')
recent.files.should eq(['filename'])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment