This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_helper.rb
66 lines (56 loc) · 1.55 KB
/
test_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
ENV['RACK_ENV'] = 'test'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
require "rack/test"
require "contest"
require "quietbacktrace"
require 'active_support/testing/assertions'
require 'mocha'
Debugger.start
Debugger.settings[:autoeval] = true
Debugger.settings[:autolist] = 1
class Test::Unit::TestCase
include Rack::Test::Methods
include ActiveSupport::Testing::Assertions
def app
Main.new
end
def assert_contains(collection, x, extra_msg = "")
collection = [collection] unless collection.is_a?(Array)
msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}"
case x
when Regexp
assert(collection.detect { |e| e =~ x }, msg)
else
assert(collection.include?(x), msg)
end
end
def assert_does_not_contain(collection, x, extra_msg = "")
collection = [collection] unless collection.is_a?(Array)
msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg
case x
when Regexp
assert(!collection.detect { |e| e =~ x }, msg)
else
assert(!collection.include?(x), msg)
end
end
end
module Factory
class Options
def method_missing(method, *args)
@records ||= {}
@records[method] = args.first
@records
end
end
def factory(options = {}, &block)
if block_given?
@default_options = Options.new.instance_eval(&block)
else
options = (@default_options || {}).merge(options)
options.each {|k,v| options[k] = v.call if v.is_a?(Proc) }
self.new(options)
end
end
end
require "factories"