/
spec_helper.rb
82 lines (66 loc) · 1.86 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
require 'rubygems'
require 'spork'
require 'spork/ext/ruby-debug'
def with_airpot_vcr
VCR.use_cassette 'amazon/airpot' do
yield
end
end
def with_stub_products
product = mock_model(Product)
product.stub(:title).and_return("RC Helicopter")
product.stub(:img_src).and_return("http://www.amazon.com/img.jpg")
product.stub(:price).and_return(35.99)
Product.stub(:all).and_return([product])
Product.stub(:order).and_return([product])
yield
end
def with_ar_products
@product = Product.create(
title: "RC Helicopter",
img_src: "http://www.amazon.com/img.jpg",
url: "helicopter",
price: 35
)
yield
Product.delete_all
end
def time_travel_and_return(travel_to_date)
current_time = Time.zone.now
travel_to_date = Time.zone.parse(travel_to_date) if travel_to_date.is_a? String
Timecop.travel(travel_to_date)
yield
ensure
Timecop.travel(current_time)
end
Spork.prefork do
unless ENV['DRB']
require 'simplecov'
SimpleCov.start 'rails'
end
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/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}
RSpec.configure do |config|
config.use_transactional_fixtures = 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
if Settings.use_phantomjs
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
end
end
end
Spork.each_run do
if ENV['DRB']
require 'simplecov'
SimpleCov.start 'rails'
end
end