This repository was archived by the owner on Dec 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathtest_helper.rb
More file actions
64 lines (57 loc) · 1.81 KB
/
test_helper.rb
File metadata and controls
64 lines (57 loc) · 1.81 KB
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
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'mocha/mini_test'
require 'factory_girl'
require 'sidekiq/testing'
require 'vcr'
class ActiveSupport::TestCase
include FactoryGirl::Syntax::Methods
include Rails.application.routes.url_helpers
def authorization_headers(user)
{ 'Authorization': "bearer #{user.token}" }
end
# @see https://gist.github.com/mattbrictson/72910465f36be8319cde
#
# Monkey patch the `test` DSL to enable VCR and configure a cassette named
# based on the test method. This means that a test written like this:
#
# class OrderTest < ActiveSupport::TestCase
# test "user can place order" do
# ...
# end
# end
#
# will automatically use VCR to intercept and record/play back any external
# HTTP requests using `cassettes/order_test/_user_can_place_order.yml`.
#
def self.test(test_name, &block)
return super if block.nil?
cassette = [name, test_name].map do |str|
str.underscore.gsub(/[^A-Z]+/i, '_')
end.join('/')
super(test_name) do
VCR.use_cassette(cassette) do
instance_eval(&block)
end
end
end
end
VCR.configure do |config|
config.allow_http_connections_when_no_cassette = false
config.cassette_library_dir = 'test/cassettes'
config.hook_into :webmock
end
Geocoder.configure(lookup: :test)
Geocoder::Lookup::Test.set_default_stub(
[{ 'latitude' => -4,
'longitude' => -4,
'address' => 'a weird default, when real world accuracy does not matter',
'state_code' => 'DEFAULT' }]
)
Geocoder::Lookup::Test.add_stub(
'97201', [{ 'latitude' => 45.505603,
'longitude' => -122.6882145,
'address' => 'real world result for the zip used in the user factory',
'state_code' => 'OR' }]
)