forked from cheald/mongomapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_helper.rb
More file actions
62 lines (51 loc) · 2.28 KB
/
Copy pathtest_helper.rb
File metadata and controls
62 lines (51 loc) · 2.28 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
require 'pathname'
require 'rubygems'
require 'test/unit'
require 'shoulda'
gem 'mocha', '0.9.4'
gem 'jnunemaker-matchy', '0.4.0'
require 'matchy'
require 'mocha'
$LOAD_PATH.unshift(File.dirname(__FILE__))
dir = (Pathname(__FILE__).dirname + '..' + 'lib').expand_path
require dir + 'mongomapper'
class Test::Unit::TestCase
custom_matcher :be_nil do |receiver, matcher, args|
matcher.positive_failure_message = "Expected #{receiver} to be nil but it wasn't"
matcher.negative_failure_message = "Expected #{receiver} not to be nil but it was"
receiver.nil?
end
custom_matcher :be_true do |receiver, matcher, args|
matcher.positive_failure_message = "Expected #{receiver} to be true but it wasn't"
matcher.negative_failure_message = "Expected #{receiver} not to be true but it was"
receiver.eql?(true)
end
custom_matcher :be_false do |receiver, matcher, args|
matcher.positive_failure_message = "Expected #{receiver} to be false but it wasn't"
matcher.negative_failure_message = "Expected #{receiver} not to be false but it was"
receiver.eql?(false)
end
custom_matcher :be_valid do |receiver, matcher, args|
matcher.positive_failure_message = "Expected to be valid but it was invalid #{receiver.errors.inspect}"
matcher.negative_failure_message = "Expected to be invalid but it was valid #{receiver.errors.inspect}"
receiver.valid?
end
custom_matcher :have_error_on do |receiver, matcher, args|
receiver.valid?
attribute = args[0]
expected_message = args[1]
if expected_message.nil?
matcher.positive_failure_message = "#{receiver} had no errors on #{attribute}"
matcher.negative_failure_message = "#{receiver} had errors on #{attribute} #{receiver.errors.inspect}"
!receiver.errors.on(attribute).blank?
else
actual = receiver.errors.on(attribute)
matcher.positive_failure_message = %Q(Expected error on #{attribute} to be "#{expected_message}" but was "#{actual}")
matcher.negative_failure_message = %Q(Expected error on #{attribute} not to be "#{expected_message}" but was "#{actual}")
actual == expected_message
end
end
end
DefaultDatabase = 'test' unless defined?(DefaultDatabase)
AlternateDatabase = 'test2' unless defined?(AlternateDatabase)
MongoMapper.database = DefaultDatabase