Fake your files - MemFs

Simon Courtois
Simon CourtoisCTO Founder at PDFMonkey
Fake your files
Simon Courtois - @happynoff
How to test files
manipulation ?
class FileMaker
def create(path)
FileUtils.touch(path)
end
end

it "creates the given file" do
file_maker.create('thing.txt')
end
class FileMaker
def create(path)
FileUtils.touch(path)
end
end

it "creates the given file" do
file_maker.create('thing.txt')
expect(File.exists?(‘thing.txt’)).to be_true
end
class FileMaker
def create(path)
FileUtils.touch(path)
end
end

it "creates the given file" do
FileUtils.rm('thing.txt')
file_maker.create('thing.txt')
expect(File.exists?(‘thing.txt’)).to be_true
end
Read-only file system ?
class FileMaker
def create(path)
FileUtils.touch(path)
end
end

it "creates the given file" do
file_maker.create('thing.txt')
end
class FileMaker
def create(path)
FileUtils.touch(path)
end
end

it "creates the given file" do
expect(FileUtils).to receive(:touch)
.with(‘thing.txt')
.and_return(true)
file_maker.create('thing.txt')
end
Boooh!
Test behavior not
implementation
Enters a solution
FakeFS
class FileMaker
def create(path)
FileUtils.touch(path)
end
end

it "creates the given file" do
file_maker.create('thing.txt')
expect(File.exists?('thing.txt')).to be_true
end
class FileMaker
def create(path)
FileUtils.touch(path)
end
end

it "creates the given file" do
FakeFS do
file_maker.create('thing.txt')
expect(File.exists?('thing.txt')).to be_true
end
end
class FileMaker
def create(path)
FileUtils.touch(path, noop: true)
end
end

it "creates the given file" do
FakeFS do
file_maker.create('thing.txt')
expect(File.exists?('thing.txt')).to be_true
be_false
end
end
BOOM!
That’s a red dot
FakeFS
overwrites FileUtils and
ignores options
Try MemFS
class FileMaker
def create(path)
FileUtils.touch(path, noop: true)
end
end

it "creates the given file" do
file_maker.create('thing.txt')
expect(File.exists?('thing.txt')).to be_false
end
class FileMaker
def create(path)
FileUtils.touch(path, noop: true)
end
end

it "creates the given file" do
MemFs.activate do
file_maker.create('thing.txt')
expect(File.exists?('thing.txt')).to be_false
end
end
MemFs
doesn’t overwrite FileUtils
only low-level classes
File.open('thing.txt') do |f|
f.puts 'hello'
end

!

File.read('thing.txt')
# => "hellon"

File.symlink('thing.txt', 'thing-link.txt')
File.symlink?('thing-link.txt')
# => true

File.stat('thing.txt').ctime
# => 2014-02-04 19:00:00 +0100
File.chmod(0777, 'thing.txt')
Some resources
http://github.com/defunkt/fakefs
http://github.com/simonc/memfs
Questions

?
Thank you
Simon Courtois - @happynoff
1 of 24

Recommended

Python 101 by
Python 101Python 101
Python 101The Active Network
2.5K views37 slides
Introduction to JavaScript: Week Two by
Introduction to JavaScript: Week TwoIntroduction to JavaScript: Week Two
Introduction to JavaScript: Week TwoEvent Handler
1.4K views43 slides
Getting to know Arel by
Getting to know ArelGetting to know Arel
Getting to know ArelRay Zane
653 views36 slides
SolrMeter Lightning talk - Lucene Revolution 2010 by
SolrMeter   Lightning talk - Lucene Revolution 2010SolrMeter   Lightning talk - Lucene Revolution 2010
SolrMeter Lightning talk - Lucene Revolution 2010Tomás Fernández Löbbe
968 views16 slides
gitfs by
gitfsgitfs
gitfsTemian Vlad
541 views56 slides
F strings by
F stringsF strings
F stringsMariatta Wijaya
446 views20 slides

More Related Content

Similar to Fake your files - MemFs

DIWE - File handling with PHP by
DIWE - File handling with PHPDIWE - File handling with PHP
DIWE - File handling with PHPRasan Samarasinghe
936 views67 slides
Php files by
Php filesPhp files
Php fileskalyani66
3K views36 slides
File Handling in C Programming by
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C ProgrammingRavindraSalunke3
173 views18 slides
Filesystems Lisbon 2018 by
Filesystems Lisbon 2018Filesystems Lisbon 2018
Filesystems Lisbon 2018Frank de Jonge
122 views152 slides
File handling in C++ by
File handling in C++File handling in C++
File handling in C++Hitesh Kumar
1.8K views20 slides
Ch3(working with file) by
Ch3(working with file)Ch3(working with file)
Ch3(working with file)Chhom Karath
174 views14 slides

Similar to Fake your files - MemFs(20)

File handling in C++ by Hitesh Kumar
File handling in C++File handling in C++
File handling in C++
Hitesh Kumar1.8K views
Ch3(working with file) by Chhom Karath
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
Chhom Karath174 views
Automate the boring stuff with python by DEEPAKSINGHBIST1
Automate the boring stuff with pythonAutomate the boring stuff with python
Automate the boring stuff with python
DEEPAKSINGHBIST1209 views
Filing system in PHP by Mudasir Syed
Filing system in PHPFiling system in PHP
Filing system in PHP
Mudasir Syed560 views
Linux Command Line - By Ranjan Raja by Ranjan Raja
Linux Command Line - By Ranjan Raja Linux Command Line - By Ranjan Raja
Linux Command Line - By Ranjan Raja
Ranjan Raja80 views
Java 7 Features and Enhancements by Gagan Agrawal
Java 7 Features and EnhancementsJava 7 Features and Enhancements
Java 7 Features and Enhancements
Gagan Agrawal1.5K views
Linux commands by shekhar70
Linux commandsLinux commands
Linux commands
shekhar7075 views
Raspberry pi Part 25 by Techvilla
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
Techvilla380 views

More from Simon Courtois

Conseils pour un lancement Product Hunt réussi by
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussiSimon Courtois
72 views28 slides
Organize your assets with Rails by
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with RailsSimon Courtois
761 views51 slides
Speed your Rails app creation with templates by
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templatesSimon Courtois
783 views25 slides
Dependency sorting in Ruby with TSort by
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSortSimon Courtois
942 views16 slides
How Unidecoder Transliterates UTF-8 to ASCII by
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCIISimon Courtois
782 views34 slides
Get Slim! by
Get Slim!Get Slim!
Get Slim!Simon Courtois
2.2K views23 slides

More from Simon Courtois(16)

Conseils pour un lancement Product Hunt réussi by Simon Courtois
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussi
Simon Courtois72 views
Organize your assets with Rails by Simon Courtois
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with Rails
Simon Courtois761 views
Speed your Rails app creation with templates by Simon Courtois
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templates
Simon Courtois783 views
Dependency sorting in Ruby with TSort by Simon Courtois
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSort
Simon Courtois942 views
How Unidecoder Transliterates UTF-8 to ASCII by Simon Courtois
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCII
Simon Courtois782 views
Multi tenant/lang application with Ruby on Rails by Simon Courtois
Multi tenant/lang application with Ruby on RailsMulti tenant/lang application with Ruby on Rails
Multi tenant/lang application with Ruby on Rails
Simon Courtois1.7K views
REST with Her (and let Her take care of the REST) by Simon Courtois
REST with Her (and let Her take care of the REST)REST with Her (and let Her take care of the REST)
REST with Her (and let Her take care of the REST)
Simon Courtois3.2K views
Pourquoi Ruby on Rails ça déchire ? by Simon Courtois
Pourquoi Ruby on Rails ça déchire ?Pourquoi Ruby on Rails ça déchire ?
Pourquoi Ruby on Rails ça déchire ?
Simon Courtois4.9K views

Recently uploaded

The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
73 views25 slides
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Safe Software
225 views86 slides
SAP Automation Using Bar Code and FIORI.pdf by
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdfVirendra Rai, PMP
19 views38 slides
How the World's Leading Independent Automotive Distributor is Reinventing Its... by
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...NUS-ISS
15 views25 slides
Roadmap to Become Experts.pptx by
Roadmap to Become Experts.pptxRoadmap to Become Experts.pptx
Roadmap to Become Experts.pptxdscwidyatamanew
11 views45 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
28 views73 slides

Recently uploaded(20)

Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software225 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
How the World's Leading Independent Automotive Distributor is Reinventing Its... by NUS-ISS
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS15 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
AI: mind, matter, meaning, metaphors, being, becoming, life values by Twain Liu 刘秋艳
AI: mind, matter, meaning, metaphors, being, becoming, life valuesAI: mind, matter, meaning, metaphors, being, becoming, life values
AI: mind, matter, meaning, metaphors, being, becoming, life values
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS28 views
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk88 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views

Fake your files - MemFs