Reading a file fixture from disk

280 views
Skip to first unread message

Gavin Miller

unread,
Jul 14, 2012, 4:06:16 PM7/14/12
to rubym...@googlegroups.com
I'd like to be able to read a file from disk within a spec. No matter where I've tried placing the file I get: 

No such file or directory - open() failed

Where does the file need to be?

Gavin Miller

unread,
Jul 14, 2012, 4:34:18 PM7/14/12
to rubym...@googlegroups.com
Found the answer. The file has to be located under the resources directory, and it can be accessed using the following code:

@local_feed = File.join(App.resources_path, 'feed_parser_data.xml')
puts
File.read(@local_feed)

Gavin Miller

unread,
Jul 14, 2012, 5:14:58 PM7/14/12
to rubym...@googlegroups.com
Forgot to mention, this solution only works if you've got BubbleWrap as a part of your project.
If not then call
NSBundle.mainBundle.resourcePath to get the resources path

Francis Chong

unread,
Jul 14, 2012, 9:17:11 PM7/14/12
to rubym...@googlegroups.com
You may want to know that App.resource_path is a shorthand to NSBundle.mainBundle.resourcePath
Reply all
Reply to author
Forward
0 new messages