spec_helper.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Require this file using `require "spec_helper"`
  2. # to ensure that it is only loaded once.
  3. #
  4. # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
  5. require 'digest/md5'
  6. require 'coveralls'
  7. require 'vcr'
  8. require 'webmock/rspec'
  9. Coveralls.wear!
  10. require 'polipus'
  11. VCR.configure do |c|
  12. c.cassette_library_dir = "#{File.dirname(__FILE__)}/cassettes"
  13. c.hook_into :webmock
  14. c.allow_http_connections_when_no_cassette = true
  15. c.ignore_localhost = true
  16. end
  17. RSpec.configure do |config|
  18. config.run_all_when_everything_filtered = true
  19. config.filter_run :focus
  20. # Run specs in random order to surface order dependencies. If you find an
  21. # order dependency and want to debug it, you can fix the order by providing
  22. # the seed, which is printed after each run.
  23. # --seed 1234
  24. config.order = 'random'
  25. config.mock_with :flexmock
  26. config.around(:each) do |example|
  27. t = Time.now
  28. print example.metadata[:full_description]
  29. VCR.use_cassette(
  30. Digest::MD5.hexdigest(example.metadata[:full_description]),
  31. record: :all
  32. ) do
  33. example.run
  34. end
  35. puts " [#{Time.now - t}s]"
  36. end
  37. config.before(:each) { Polipus::SignalHandler.disable }
  38. end
  39. def page_factory(url, params = {})
  40. params[:code] ||= 200 unless params.has_key?(:code)
  41. params[:body] = '<html></html>' unless params.has_key?(:body)
  42. params[:fetched_at] = Time.now.to_i
  43. sleep(1)
  44. Polipus::Page.new(url, params)
  45. end