Sha256: b83dd07ab8a3c655d744a30b9cb70ca3d9407899c6f69ac04220a4ce19696be9
Contents?: true
Size: 1.55 KB
Versions: 2
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true RSpec.describe Ferver::FileList do subject { described_class.new(files) } let(:files) { [] } describe "#size" do it "is the size of the files available" do expect(subject.size).to eq 0 end context "with files" do let(:files) { three_files } it "is the size of the files available" do expect(subject.size).to eq 3 end end end describe "#each" do let(:files) { three_files } it "responds to each_with_index" do expect(subject).to respond_to(:each_with_index) end it "returns yields files in sorted order" do ordered_file_names = %w(file1 file2 file3) i = 0 subject.each do |actual_file| expect(actual_file.name).to eq ordered_file_names[i] i += 1 end end end describe "#file_by_id" do context "with a request for a file index within range" do let(:files) { three_files } it "returns the file requested in sorted order" do expect(subject.file_by_id(0).name).to eq "file1" expect(subject.file_by_id(1).name).to eq "file2" expect(subject.file_by_id(2).name).to eq "file3" end end context "with a request for a file index out of range" do it "raises file not found error" do expect { subject.file_by_id(0) }.to raise_error(Ferver::FileNotFoundError, "File id=0 not found") end end end private def three_files [ double("file", name: "file2"), double("file", name: "file3"), double("file", name: "file1") ] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ferver-1.4.0 | spec/file_list_spec.rb |
ferver-1.3.1 | spec/file_list_spec.rb |