Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the basics for Pathname support (ref #13)
- Loading branch information
Showing
5 changed files
with
126 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'memfs/filesystem_access' | ||
|
||
module MemFs | ||
class Pathname | ||
extend FilesystemAccess | ||
|
||
def initialize(path) | ||
@path = '' + path | ||
end | ||
|
||
def to_s | ||
path | ||
end | ||
alias_method :to_str, :to_s | ||
|
||
private | ||
|
||
attr_reader :path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'spec_helper' | ||
|
||
module MemFs | ||
describe Pathname do | ||
describe 'Class Methods' do | ||
subject { MemFs::Pathname } | ||
|
||
describe '.new' do | ||
it 'creates a Pathname object from the given path' do | ||
pathname = subject.new('some/path') | ||
expect(pathname.to_s).to eq 'some/path' | ||
end | ||
|
||
context 'when the given path is not a string' do | ||
it 'creates a Pathname object from the string representation of the path' do | ||
path = MemFs::Pathname.new('some/path') | ||
pathname = MemFs::Pathname.new(path) | ||
expect(pathname.to_s).to eq 'some/path' | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe "Instance Methods" do | ||
subject(:pathname) { MemFs::Pathname.new('some/path') } | ||
|
||
describe '#to_str' do | ||
it 'can be converted to a string object' do | ||
expect('test ' + pathname).to eq 'test some/path' | ||
end | ||
end | ||
|
||
describe '#to_s' do | ||
it "returns the path as a String" do | ||
expect(pathname.to_s).to eq 'some/path' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters