Guest User

Untitled

a guest
Feb 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. # prevent the use of `` in tests
  2. Spec::Runner.configure do |configuration|
  3. backtick = nil # establish the variable in this scope
  4. saved_system = nil
  5. configuration.prepend_before(:all) do
  6. # raise an exception if Kernel#` or Kernel#system is used
  7. # in our tests, we want to ensure we're fully self-contained
  8. Kernel.instance_eval do
  9. backtick = instance_method(:'`')
  10. saved_system = instance_method(:system)
  11. define_method :'`' do |str|
  12. raise "Cannot use backticks in tests"
  13. end
  14. define_method :system do |*args|
  15. raise "Cannot use Kernel#system in tests"
  16. end
  17. end
  18. end
  19.  
  20. configuration.prepend_after(:all) do
  21. # and now restore Kernel#` and Kernel#system
  22. Kernel.instance_eval do
  23. define_method :'`', backtick
  24. define_method :system, saved_system
  25. end
  26. end
  27. end
Add Comment
Please, Sign In to add comment