SlideShare a Scribd company logo
Submit Search
Upload
Fake your files - MemFs
Report
Share
Simon Courtois
CTO Founder at PDFMonkey
Follow
•
1 like
•
1,016 views
1
of
24
Fake your files - MemFs
•
1 like
•
1,016 views
Report
Share
Download Now
Download to read offline
Technology
My talk for Paris.rb on 2014-02-04.
Read more
Simon Courtois
CTO Founder at PDFMonkey
Follow
Recommended
Python 101 by
Python 101
The Active Network
2.5K views
•
37 slides
Introduction to JavaScript: Week Two by
Introduction to JavaScript: Week Two
Event Handler
1.4K views
•
43 slides
Getting to know Arel by
Getting to know Arel
Ray Zane
653 views
•
36 slides
SolrMeter Lightning talk - Lucene Revolution 2010 by
SolrMeter Lightning talk - Lucene Revolution 2010
Tomás Fernández Löbbe
968 views
•
16 slides
gitfs by
gitfs
Temian Vlad
541 views
•
56 slides
F strings by
F strings
Mariatta Wijaya
446 views
•
20 slides
More Related Content
Similar to Fake your files - MemFs
DIWE - File handling with PHP by
DIWE - File handling with PHP
Rasan Samarasinghe
936 views
•
67 slides
Php files by
Php files
kalyani66
3K views
•
36 slides
File Handling in C Programming by
File Handling in C Programming
RavindraSalunke3
173 views
•
18 slides
Filesystems Lisbon 2018 by
Filesystems Lisbon 2018
Frank de Jonge
122 views
•
152 slides
File handling in C++ by
File handling in C++
Hitesh Kumar
1.8K views
•
20 slides
Ch3(working with file) by
Ch3(working with file)
Chhom Karath
174 views
•
14 slides
Similar to Fake your files - MemFs
(20)
DIWE - File handling with PHP by Rasan Samarasinghe
DIWE - File handling with PHP
Rasan Samarasinghe
•
936 views
Php files by kalyani66
Php files
kalyani66
•
3K views
File Handling in C Programming by RavindraSalunke3
File Handling in C Programming
RavindraSalunke3
•
173 views
Filesystems Lisbon 2018 by Frank de Jonge
Filesystems Lisbon 2018
Frank de Jonge
•
122 views
File handling in C++ by Hitesh Kumar
File handling in C++
Hitesh Kumar
•
1.8K views
Ch3(working with file) by Chhom Karath
Ch3(working with file)
Chhom Karath
•
174 views
Web Development Course: PHP lecture 3 by Gheyath M. Othman
Web Development Course: PHP lecture 3
Gheyath M. Othman
•
292 views
Having Fun Programming! by Aaron Patterson
Having Fun Programming!
Aaron Patterson
•
863 views
Automate the boring stuff with python by DEEPAKSINGHBIST1
Automate the boring stuff with python
DEEPAKSINGHBIST1
•
209 views
Java File I/O by Canterbury HS
Java File I/O
Canterbury HS
•
1.1K views
Filing system in PHP by Mudasir Syed
Filing system in PHP
Mudasir Syed
•
560 views
Linux Command Line - By Ranjan Raja by Ranjan Raja
Linux Command Line - By Ranjan Raja
Ranjan Raja
•
80 views
Java 7 Features and Enhancements by Gagan Agrawal
Java 7 Features and Enhancements
Gagan Agrawal
•
1.5K views
file_handling_in_c.ppt by yuvrajkeshri
file_handling_in_c.ppt
yuvrajkeshri
•
3 views
General Functions by BabuDevanandam
General Functions
BabuDevanandam
•
391 views
Linux commands by shekhar70
Linux commands
shekhar70
•
75 views
Raspberry pi Part 25 by Techvilla
Raspberry pi Part 25
Techvilla
•
380 views
Assignment Of A Computer System by Cynthia Harder
Assignment Of A Computer System
Cynthia Harder
•
5 views
Basic input-output-v.1.1 by BG Java EE Course
Basic input-output-v.1.1
BG Java EE Course
•
843 views
Python programming : Files by Emertxe Information Technologies Pvt Ltd
Python programming : Files
Emertxe Information Technologies Pvt Ltd
•
6.4K views
More from Simon Courtois
Conseils pour un lancement Product Hunt réussi by
Conseils pour un lancement Product Hunt réussi
Simon Courtois
72 views
•
28 slides
Organize your assets with Rails by
Organize your assets with Rails
Simon Courtois
761 views
•
51 slides
Speed your Rails app creation with templates by
Speed your Rails app creation with templates
Simon Courtois
783 views
•
25 slides
Dependency sorting in Ruby with TSort by
Dependency sorting in Ruby with TSort
Simon Courtois
942 views
•
16 slides
How Unidecoder Transliterates UTF-8 to ASCII by
How Unidecoder Transliterates UTF-8 to ASCII
Simon Courtois
782 views
•
34 slides
Get Slim! by
Get Slim!
Simon Courtois
2.2K views
•
23 slides
More from Simon Courtois
(16)
Conseils pour un lancement Product Hunt réussi by Simon Courtois
Conseils pour un lancement Product Hunt réussi
Simon Courtois
•
72 views
Organize your assets with Rails by Simon Courtois
Organize your assets with Rails
Simon Courtois
•
761 views
Speed your Rails app creation with templates by Simon Courtois
Speed your Rails app creation with templates
Simon Courtois
•
783 views
Dependency sorting in Ruby with TSort by Simon Courtois
Dependency sorting in Ruby with TSort
Simon Courtois
•
942 views
How Unidecoder Transliterates UTF-8 to ASCII by Simon Courtois
How Unidecoder Transliterates UTF-8 to ASCII
Simon Courtois
•
782 views
Get Slim! by Simon Courtois
Get Slim!
Simon Courtois
•
2.2K views
Multi tenant/lang application with Ruby on Rails by Simon Courtois
Multi tenant/lang application with Ruby on Rails
Simon Courtois
•
1.7K views
Rails is like Burger King by Simon Courtois
Rails is like Burger King
Simon Courtois
•
819 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)
Simon Courtois
•
3.2K views
Ruby and DCI by Simon Courtois
Ruby and DCI
Simon Courtois
•
877 views
Cells by Simon Courtois
Cells
Simon Courtois
•
631 views
Mustdown by Simon Courtois
Mustdown
Simon Courtois
•
954 views
Vos Regexps sont fausses ! by Simon Courtois
Vos Regexps sont fausses !
Simon Courtois
•
395 views
Ariane by Simon Courtois
Ariane
Simon Courtois
•
663 views
Pourquoi Ruby on Rails ça déchire ? by Simon Courtois
Pourquoi Ruby on Rails ça déchire ?
Simon Courtois
•
4.9K views
Commander by Simon Courtois
Commander
Simon Courtois
•
292 views
Recently uploaded
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya
73 views
•
25 slides
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software
225 views
•
86 slides
SAP Automation Using Bar Code and FIORI.pdf by
SAP Automation Using Bar Code and FIORI.pdf
Virendra Rai, PMP
19 views
•
38 slides
How the World's Leading Independent Automotive Distributor is Reinventing Its... by
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS
15 views
•
25 slides
Roadmap to Become Experts.pptx by
Roadmap to Become Experts.pptx
dscwidyatamanew
11 views
•
45 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf
Phactum Softwareentwicklung GmbH
28 views
•
73 slides
Recently uploaded
(20)
The Research Portal of Catalonia: Growing more (information) & more (services) by CSUC - Consorci de Serveis Universitaris de Catalunya
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya
•
73 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software
•
225 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdf
Virendra Rai, PMP
•
19 views
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...
NUS-ISS
•
15 views
Roadmap to Become Experts.pptx by dscwidyatamanew
Roadmap to Become Experts.pptx
dscwidyatamanew
•
11 views
20231123_Camunda Meetup Vienna.pdf by Phactum Softwareentwicklung GmbH
20231123_Camunda Meetup Vienna.pdf
Phactum Softwareentwicklung GmbH
•
28 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri
•
15 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst
•
470 views
ChatGPT and AI for Web Developers by Maximiliano Firtman
ChatGPT and AI for Web Developers
Maximiliano Firtman
•
181 views
AI: mind, matter, meaning, metaphors, being, becoming, life values by Twain Liu 刘秋艳
AI: mind, matter, meaning, metaphors, being, becoming, life values
Twain Liu 刘秋艳
•
35 views
Top 10 Strategic Technologies in 2024: AI and Automation by AutomationEdge Technologies
Top 10 Strategic Technologies in 2024: AI and Automation
AutomationEdge Technologies
•
14 views
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction System
RADIUS
•
15 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10
•
209 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdf
gdsczhcet
•
55 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdf
WillDavies22
•
16 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...
NUS-ISS
•
28 views
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk
•
88 views
Tunable Laser (1).pptx by Hajira Mahmood
Tunable Laser (1).pptx
Hajira Mahmood
•
23 views
Java Platform Approach 1.0 - Picnic Meetup by Rick Ossendrijver
Java Platform Approach 1.0 - Picnic Meetup
Rick Ossendrijver
•
25 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023
Michael Price
•
15 views
Fake your files - MemFs
1.
Fake your files Simon
Courtois - @happynoff
2.
How to test
files manipulation ?
3.
class FileMaker def create(path) FileUtils.touch(path) end end it
"creates the given file" do file_maker.create('thing.txt') end
4.
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
5.
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
6.
Read-only file system
?
7.
class FileMaker def create(path) FileUtils.touch(path) end end it
"creates the given file" do file_maker.create('thing.txt') end
8.
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
9.
Boooh! Test behavior not implementation
10.
Enters a solution FakeFS
11.
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
12.
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
13.
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
14.
BOOM! That’s a red
dot
15.
FakeFS overwrites FileUtils and ignores
options
16.
Try MemFS
17.
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
18.
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
19.
MemFs doesn’t overwrite FileUtils only
low-level classes
20.
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')
21.
Some resources
22.
http://github.com/defunkt/fakefs http://github.com/simonc/memfs
23.
Questions ?
24.
Thank you Simon Courtois
- @happynoff