env.rb 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
  2. # It is recommended to regenerate this file in the future when you upgrade to a
  3. # newer version of cucumber-rails. Consider adding your own code to a new file
  4. # instead of editing this one. Cucumber will automatically load all features/**/*.rb
  5. # files.
  6. require "cucumber/rails"
  7. require "cucumber/rspec/doubles"
  8. require "capybara/poltergeist"
  9. require "billy/capybara/cucumber"
  10. require "webmock/cucumber"
  11. Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
  12. Capybara.register_driver :poltergeist do |app|
  13. Capybara::Poltergeist::Driver.new(app,
  14. url_blacklist: ["anon-stats.eff.org"],
  15. phantomjs_logger: StringIO.new,
  16. js_errors: true)
  17. end
  18. Capybara.javascript_driver = :poltergeist
  19. WebMock.allow_net_connect!
  20. Billy.configure do |c|
  21. c.cache = true
  22. c.cache_request_headers = false
  23. c.ignore_params = ["https//anon-stats.eff.org"]
  24. c.persist_cache = true
  25. c.cache_path = "features/req_cache/"
  26. c.non_whitelisted_requests_disabled = ENV["DISABLE_PUFFING_BILLY_REQUESTS"]
  27. c.after_cache_handles_request = proc do |_request, response|
  28. response[:headers]["Access-Control-Allow-Origin"] = "*"
  29. end
  30. end
  31. # Don't prevent form fills by bots during the test run
  32. InvisibleCaptcha.setup do |config|
  33. config.timestamp_enabled = false
  34. end
  35. # Capybara defaults to CSS3 selectors rather than XPath.
  36. # If you'd prefer to use XPath, just uncomment this line and adjust any
  37. # selectors in your step definitions to use the XPath syntax.
  38. # Capybara.default_selector = :xpath
  39. # By default, any exception happening in your Rails application will bubble up
  40. # to Cucumber so that your scenario will fail. This is a different from how
  41. # your application behaves in the production environment, where an error page will
  42. # be rendered instead.
  43. #
  44. # Sometimes we want to override this default behaviour and allow Rails to rescue
  45. # exceptions and display an error page (just like when the app is running in production).
  46. # Typical scenarios where you want to do this is when you test your error pages.
  47. # There are two ways to allow Rails to rescue exceptions:
  48. #
  49. # 1) Tag your scenario (or feature) with @allow-rescue
  50. #
  51. # 2) Set the value below to true. Beware that doing this globally is not
  52. # recommended as it will mask a lot of errors for you!
  53. #
  54. ActionController::Base.allow_rescue = false
  55. # Remove/comment out the lines below if your app doesn't have a database.
  56. # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
  57. begin
  58. DatabaseCleaner.strategy = :transaction
  59. rescue NameError
  60. raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
  61. end
  62. # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
  63. # See the DatabaseCleaner documentation for details. Example:
  64. #
  65. # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
  66. # # { :except => [:widgets] } may not do what you expect here
  67. # # as Cucumber::Rails::Database.javascript_strategy overrides
  68. # # this setting.
  69. # DatabaseCleaner.strategy = :truncation
  70. # end
  71. #
  72. # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
  73. # DatabaseCleaner.strategy = :transaction
  74. # end
  75. #
  76. # Possible values are :truncation and :transaction
  77. # The :transaction strategy is faster, but might give you threading problems.
  78. # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
  79. Cucumber::Rails::Database.javascript_strategy = :truncation
  80. Before("@billy") do
  81. Capybara.current_driver = :poltergeist_billy
  82. end
  83. After do
  84. Capybara.use_default_driver
  85. end
  86. Before do
  87. stub_civicrm
  88. end
  89. def stub_smarty_streets
  90. stub_resp = { "city" => "San Francisco", "state_abbreviation" => "CA", "state" => "California", "mailable_city" => true }
  91. allow(SmartyStreets).to receive(:get_city_state).with("94109").and_return(stub_resp)
  92. end
  93. def stub_smarty_streets_street_address
  94. stubbed_address = '[{"input_index":0,"candidate_index":0,"delivery_line_1":"815 Eddy St","last_line":"San Francisco CA 94109-7701","delivery_point_barcode":"941097701156","components":{"primary_number":"815","street_name":"Eddy","street_suffix":"St","city_name":"San Francisco","state_abbreviation":"CA","zipcode":"94109","plus4_code":"7701","delivery_point":"15","delivery_point_check_digit":"6"},"metadata":{"record_type":"S","zip_type":"Standard","county_fips":"06075","county_name":"San Francisco","carrier_route":"C043","congressional_district":"12","rdi":"Commercial","elot_sequence":"0167","elot_sort":"A","latitude":37.78277,"longitude":-122.42104,"precision":"Zip9","time_zone":"Pacific","utc_offset":-8,"dst":true},"analysis":{"dpv_match_code":"Y","dpv_footnotes":"AABB","dpv_cmra":"N","dpv_vacant":"N","active":"Y"}}]'
  95. allow_any_instance_of(SmartyStreetsController).to receive(:get_data_on_address_zip).and_return(stubbed_address)
  96. end
  97. def stub_legislators
  98. nancy = CongressMember.create!(
  99. full_name: "Nancy Pelosi",
  100. first_name: "Nancy",
  101. last_name: "Pelosi",
  102. bioguide_id: "P000197",
  103. phone: "202-225-4965",
  104. term_end: (Time.now + 1.year).strftime("%Y-%m-%d"),
  105. chamber: "senate",
  106. state: "ca",
  107. twitter_id: "NancyPelosi"
  108. )
  109. allow(CongressMember).to receive(:lookup).and_return([nancy])
  110. end
  111. def wait_until
  112. require "timeout"
  113. Timeout.timeout(Capybara.default_max_wait_time) do
  114. sleep(0.1) until value = yield
  115. value
  116. end
  117. end