Advertisement
t_a_w

How to mock network i/o for command line scripts

Apr 18th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.44 KB | None | 0 0
  1. ### Save this as mock_network:
  2. require "webmock"
  3. require "vcr"
  4.  
  5. VCR.configure do |config|
  6.   config.cassette_library_dir = Pathname(__dir__) + "vcr"
  7.   config.hook_into :webmock
  8. end
  9.  
  10. VCR.insert_cassette('network', :record => ENV["RECORD"] ? :new_episodes : :none)
  11.  
  12. END {
  13.   VCR.eject_cassette
  14. }
  15.  
  16. ### Then do this in tests
  17.  
  18. system "ruby -r#{__dir__}/mock_network your_script arguments"
  19.  
  20. and `RECORD=1 rspec` first time or `rspec` later.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement