forked from insoshi/insoshi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_helper.rb
93 lines (83 loc) · 2.83 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
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec'
require 'spec/rails'
include AuthenticatedTestHelper
Spec::Runner.configure do |config|
# Active Record configuration
config.use_transactional_fixtures = true
config.use_instantiated_fixtures = false
config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
# Load the custom matchers in spec/matchers
matchers_path = File.dirname(__FILE__) + "/matchers"
matchers_files = Dir.entries(matchers_path).select {|x| /\.rb\z/ =~ x}
matchers_files.each do |path|
require File.join(matchers_path, path)
end
# Custom matchers includes
config.include(CustomModelMatchers)
# == Fixtures
#
# You can declare fixtures for each example_group like this:
# describe "...." do
# fixtures :table_a, :table_b
#
# Alternatively, if you prefer to declare them only once, you can
# do so right here. Just uncomment the next line and replace the fixture
# names with your fixtures.
#
config.global_fixtures = :all
#
# If you declare global fixtures, be aware that they will be declared
# for all of your examples, even those that don't use them.
#
# == Mock Framework
#
# RSpec uses its own mocking framework by default. If you prefer to
# use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Simulate an uploaded file.
def uploaded_file(filename, content_type = "image/png")
t = Tempfile.new(filename)
t.binmode
path = File.join(RAILS_ROOT, "spec", "images", filename)
FileUtils.copy_file(path, t.path)
(class << t; self; end).class_eval do
alias local_path path
define_method(:original_filename) {filename}
define_method(:content_type) {content_type}
end
return t
end
def mock_photo(options = {})
photo = mock_model(Photo)
photo.stub!(:public_filename).and_return("photo.png")
photo.stub!(:primary).and_return(options[:primary])
photo.stub!(:primary?).and_return(photo.primary)
photo
end
# Write response body to output file.
# This can be very helpful when debugging specs that test HTML.
def output_body(response)
File.open("tmp/index.html", "w") { |f| f.write(response.body) }
end
# Make a user an admin.
# All fixture people are not admins by default, to protect against mistakes.
def admin!(person)
person.admin = true
person.save!
person
end
# This is needed to get RSpec to understand link_to(..., person).
def polymorphic_path(args)
"http://a.fake.url"
end
def enable_email_notifications
Preference.find(:first).update_attributes(:email_verifications => true)
end
end