forked from codeforamerica/ohana-web-search
/
spec_helper.rb
105 lines (87 loc) · 3.43 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'coveralls'
Coveralls.wear!('rails')
ENV["RAILS_ENV"] ||= 'test'
ENV['TZ'] = 'America/Los_Angeles'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'email_spec'
require 'capybara/poltergeist'
require "rack_session_access/capybara"
require 'webmock/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, :js_errors => false)
end
# To debug failures of javascript-enabled tests, you can add ":debug => true"
# as an additional option on line 20. For example:
# Capybara::Poltergeist::Driver.new(app, :js_errors => true, :debug => true)
# This will result in verbose output in the Terminal when running tests.
# You can also use Poltergeist's experimental remote debugging feature by
# replacing line 19-21 with:
# Capybara.register_driver :poltergeist_debug do |app|
# Capybara::Poltergeist::Driver.new(app, :inspector => true)
# end
# You will also need to add Capybara.javascript_driver = :poltergeist_debug
# on line 45. Add "page.driver.debug" at a spot where you want to pause a test.
# When you run the test, it will pause at that spot, and will launch a browser
# window where you can inspect the page contents.
# Remember to remove "page.driver.debug" when you're done debugging!
# https://github.com/jonleighton/poltergeist#remote-debugging-experimental
# Sometimes, debugging is as simple as using Ruby's "puts" to output whatever
# you want to the Terminal. For example, if you want to see the URLs for
# all the visible links on the page at any point during a test, you can add
# this line: all('a').each { |a| puts a[:href] }
Capybara.javascript_driver = :poltergeist
RSpec.configure do |config|
config.include Features::SessionHelpers, type: :feature
config.include DetailFormatHelper
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
config.treat_symbols_as_metadata_keys_with_true_values = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
require 'vcr'
VCR.configure do |c|
c.configure_rspec_metadata!
c.ignore_hosts '127.0.0.1', 'localhost'
c.default_cassette_options = { :record => :once }
c.cassette_library_dir = "spec/cassettes"
c.hook_into :webmock
c.filter_sensitive_data("<API_TOKEN>") do
ENV['OHANA_API_TOKEN']
end
c.filter_sensitive_data("<GOOGLE_TRANSLATE>") do
ENV['GOOGLE_TRANSLATE_API_TOKEN']
end
end
def stub_get(url)
stub_request(:get, ohanapi_url(url))
end
def ohanapi_url(url)
url =~ /^http/ ? url : "http://smc-ohana-api-test.herokuapp.com/api#{url}"
end
def fixture_path
File.expand_path("../fixtures", __FILE__)
end
def fixture(file)
File.new(fixture_path + '/' + file)
end
def json_response(file)
{
:body => fixture(file),
:headers => {
:content_type => 'application/json; charset=utf-8'
}
}
end