Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch] $SAFE=3 capability and additional test methods #80

Closed
davidmiani opened this issue May 5, 2011 · 1 comment
Closed

[patch] $SAFE=3 capability and additional test methods #80

davidmiani opened this issue May 5, 2011 · 1 comment

Comments

@davidmiani
Copy link

At https://github.com/nanothief/fakefs/tree/safe3_and_autotests ( git@github.com:nanothief/fakefs.git ) I've added the ability to use fakefs while $SAFE=3 has been set. I did this as I used this library to implement the file operations on tryruby.org , and for security reasons all that code had to run in $SAFE=3 mode. There were a few changes needed to achieve this, mainly File.expand_path had to be rewritten to not use RealFile.expand_path, and the way chdirs where tracked was changed.

I also added the class FakeFsTestHelper as an aide to checking that the fake file system was performing in the same was as the real file system. You write one block of code that works with the filesystem, and the code will perform the code firstly with fakefs, then with the real file system. It will then compare any differences. Eg:

def test_file_read
    compare_with_real do
      Dir.mkdir mp("somedir")
      Dir.mkdir mp("somedir/lol")
      file = File.open(mp("somedir/afile"), "w")
      file.write "hello world"
      file.close
      check_value File.read mp("somedir/afile")
    end
 end 

These tests are really easy to write, and also catch a lot more bugs since they are so complete (they test about the filesystem for each single test). They also run with $SAFE=3.

@davidmiani
Copy link
Author

I've made an updated pull request containing these changes, in an easier to merge format. So I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant