Skip to content

Commit

Permalink
Using described_class in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
simonc committed Mar 15, 2015
1 parent f6edfd7 commit b5dd374
Show file tree
Hide file tree
Showing 9 changed files with 613 additions and 616 deletions.
382 changes: 191 additions & 191 deletions spec/fileutils_spec.rb

Large diffs are not rendered by default.

192 changes: 97 additions & 95 deletions spec/memfs/dir_spec.rb

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions spec/memfs/fake/directory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module MemFs
module Fake
describe Directory do
let(:directory) { Directory.new('test') }
subject(:directory) { described_class.new('test') }

describe '.new' do
it 'sets . in the entries list' do
Expand All @@ -16,7 +16,7 @@ module Fake
end

describe '#add_entry' do
let(:entry) { Directory.new('new_entry') }
let(:entry) { described_class.new('new_entry') }

it 'adds the entry to the entries list' do
directory.add_entry entry
Expand All @@ -35,23 +35,23 @@ module Fake
end

it 'returns false if the directory is not empty' do
directory.add_entry Directory.new('test')
directory.add_entry described_class.new('test')
expect(directory).not_to be_empty
end
end

describe '#entry_names' do
it 'returns the list of the names of the entries in the directory' do
3.times do |n|
directory.add_entry Directory.new("dir#{n}")
directory.add_entry described_class.new("dir#{n}")
end

expect(directory.entry_names).to eq(%w[. .. dir0 dir1 dir2])
end
end

describe '#find' do
let(:sub_directory) { Directory.new('sub_dir') }
let(:sub_directory) { described_class.new('sub_dir') }
let(:file) { File.new('file') }

before :each do
Expand All @@ -73,7 +73,7 @@ module Fake
end

describe '#parent=' do
let(:parent) { Directory.new('parent') }
let(:parent) { described_class.new('parent') }

it 'sets the .. entry in entries list' do
directory.parent = parent
Expand All @@ -87,7 +87,7 @@ module Fake
end

describe '#path' do
let(:root) { Directory.new('/') }
let(:root) { described_class.new('/') }

it 'returns the directory path' do
directory.parent = root
Expand All @@ -103,7 +103,7 @@ module Fake

describe '#paths' do
before do
subdir = Directory.new('subdir')
subdir = described_class.new('subdir')
directory.add_entry(subdir)
subdir.add_entry File.new('file1')
subdir.add_entry File.new('file2')
Expand Down
6 changes: 3 additions & 3 deletions spec/memfs/fake/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module MemFs
module Fake
describe Entry do
let(:entry) { Entry.new('test') }
let(:entry) { described_class.new('test') }
let(:parent) { Directory.new('parent') }
let(:time) { Time.now - 5000 }

Expand Down Expand Up @@ -76,11 +76,11 @@ module Fake
end

it 'sets an empty string as name if none is given' do
expect(Entry.new.name).to be_empty
expect(described_class.new.name).to be_empty
end

it 'sets the access time' do
expect(Entry.new.atime).to be_a(Time)
expect(described_class.new.atime).to be_a(Time)
end

it 'sets the modification time' do
Expand Down
8 changes: 3 additions & 5 deletions spec/memfs/fake/file/content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
module MemFs
module Fake
describe File::Content do
subject { File::Content.new }

describe '#<<' do
it 'writes the given string to the contained string' do
subject << 'test'
Expand All @@ -21,7 +19,7 @@ module Fake
end

context 'when an argument is given' do
subject { File::Content.new(base_value) }
subject { described_class.new(base_value) }

context 'when the argument is a string' do
let(:base_value) { 'test' }
Expand Down Expand Up @@ -80,7 +78,7 @@ module Fake
end

describe '#truncate' do
subject { File::Content.new('x' * 50) }
subject { described_class.new('x' * 50) }

it 'truncates the content to length characters' do
subject.truncate(5)
Expand Down Expand Up @@ -113,7 +111,7 @@ module Fake
end

context 'when initialized with a string argument' do
subject { File::Content.new('test') }
subject { described_class.new('test') }

describe '#read' do
it 'reads +length+ bytes from the contained string' do
Expand Down
22 changes: 11 additions & 11 deletions spec/memfs/fake/symlink_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Fake
describe '#content' do
it "returns the target's content" do
MemFs::File.open('/test-file', 'w') { |f| f.puts 'test' }
s = Symlink.new('/test-link', '/test-file')
s = described_class.new('/test-link', '/test-file')
expect(s.content).to be(s.dereferenced.content)
end
end
Expand All @@ -16,7 +16,7 @@ module Fake
_fs.touch '/test-file'
target = _fs.find!('/test-file')

s = Symlink.new('/test-link', '/test-file')
s = described_class.new('/test-link', '/test-file')

expect(s.dereferenced).to eq(target)
end
Expand All @@ -26,7 +26,7 @@ module Fake
target = _fs.find!('/test-file')

_fs.symlink '/test-file', '/test-link'
s = Symlink.new('/test-link2', '/test-link')
s = described_class.new('/test-link2', '/test-link')

expect(s.dereferenced).to eq(target)
end
Expand All @@ -36,14 +36,14 @@ module Fake
context "when the symlink's target exists" do
it 'returns its target name' do
_fs.touch('/test-file')
symlink = Symlink.new('/test-link', '/test-file')
symlink = described_class.new('/test-link', '/test-file')
expect(symlink.dereferenced_name).to eq('test-file')
end
end

context "when the symlink's target does not exist" do
it 'returns its target name' do
symlink = Symlink.new('/test-link', '/no-file')
symlink = described_class.new('/test-link', '/no-file')
expect(symlink.dereferenced_name).to eq('no-file')
end
end
Expand All @@ -53,14 +53,14 @@ module Fake
context "when the symlink's target exists" do
it 'returns its target path' do
_fs.touch('/test-file')
symlink = Symlink.new('/test-link', '/test-file')
symlink = described_class.new('/test-link', '/test-file')
expect(symlink.dereferenced_path).to eq('/test-file')
end
end

context "when the symlink's target does not exist" do
it 'raises an exception' do
symlink = Symlink.new('/test-link', '/no-file')
symlink = described_class.new('/test-link', '/no-file')
expect {
symlink.dereferenced_path
}.to raise_exception
Expand All @@ -77,7 +77,7 @@ module Fake
end

context "when the symlink's target exists" do
subject { Symlink.new('/test-dir-link', '/test-dir') }
subject { described_class.new('/test-dir-link', '/test-dir') }

it 'forwards the search to it' do
entry = subject.find('test-file')
Expand All @@ -86,7 +86,7 @@ module Fake
end

context "when the symlink's target does not exist" do
subject { Symlink.new('/test-no-link', '/no-dir') }
subject { described_class.new('/test-no-link', '/no-dir') }

it 'returns nil' do
entry = subject.find('test-file')
Expand All @@ -97,14 +97,14 @@ module Fake

describe '#target' do
it 'returns the target of the symlink' do
s = Symlink.new('/test-link', '/test-file')
s = described_class.new('/test-link', '/test-file')
expect(s.target).to eq('/test-file')
end
end

describe '#type' do
it "returns 'link'" do
s = Symlink.new('/test-link', '/test-file')
s = described_class.new('/test-link', '/test-file')
expect(s.type).to eq('link')
end
end
Expand Down
28 changes: 14 additions & 14 deletions spec/memfs/file/stat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

module MemFs
describe File::Stat do
let(:file_stat) { File::Stat.new('/test-file') }
let(:dereferenced_file_stat) { File::Stat.new('/test-file', true) }
let(:file_stat) { described_class.new('/test-file') }
let(:dereferenced_file_stat) { described_class.new('/test-file', true) }

let(:dir_link_stat) { File::Stat.new('/test-dir-link') }
let(:dereferenced_dir_link_stat) { File::Stat.new('/test-dir-link', true) }
let(:dir_link_stat) { described_class.new('/test-dir-link') }
let(:dereferenced_dir_link_stat) { described_class.new('/test-dir-link', true) }

let(:link_stat) { File::Stat.new('/test-link') }
let(:dereferenced_link_stat) { File::Stat.new('/test-link', true) }
let(:link_stat) { described_class.new('/test-link') }
let(:dereferenced_link_stat) { described_class.new('/test-link', true) }

let(:dir_stat) { File::Stat.new('/test-dir') }
let(:dereferenced_dir_stat) { File::Stat.new('/test-dir', true) }
let(:dir_stat) { described_class.new('/test-dir') }
let(:dereferenced_dir_stat) { described_class.new('/test-dir', true) }

let(:entry) { _fs.find!('/test-file') }

Expand All @@ -29,7 +29,7 @@ module MemFs
context 'when the last target of the link chain does not exist' do
it 'raises an exception' do
expect {
File::Stat.new('/test-no-file-link', true)
described_class.new('/test-no-file-link', true)
}.to raise_error(Errno::ENOENT)
end
end
Expand Down Expand Up @@ -74,7 +74,7 @@ module MemFs
_fs.touch('/block-file')
file = _fs.find('/block-file')
file.block_device = true
block_stat = File::Stat.new('/block-file')
block_stat = described_class.new('/block-file')
expect(block_stat.blockdev?).to be true
end
end
Expand All @@ -92,7 +92,7 @@ module MemFs
_fs.touch('/character-file')
file = _fs.find('/character-file')
file.character_device = true
character_stat = File::Stat.new('/character-file')
character_stat = described_class.new('/character-file')
expect(character_stat.chardev?).to be true
end
end
Expand Down Expand Up @@ -391,7 +391,7 @@ module MemFs
_fs.touch('/block-file')
file = _fs.find('/block-file')
file.block_device = true
block_stat = File::Stat.new('/block-file')
block_stat = described_class.new('/block-file')
expect(block_stat.ftype).to eq('blockSpecial')
end
end
Expand All @@ -401,7 +401,7 @@ module MemFs
_fs.touch('/character-file')
file = _fs.find('/character-file')
file.character_device = true
character_stat = File::Stat.new('/character-file')
character_stat = described_class.new('/character-file')
expect(character_stat.ftype).to eq('characterSpecial')
end
end
Expand All @@ -418,7 +418,7 @@ module MemFs
it "returns 'unknown'" do
root = _fs.find('/')
root.add_entry Fake::Entry.new('test-entry')
entry_stat = File::Stat.new('/test-entry')
entry_stat = described_class.new('/test-entry')
expect(entry_stat.ftype).to eq('unknown')
end
end
Expand Down
Loading

0 comments on commit b5dd374

Please sign in to comment.