Class: Spec::FactoryGirl::Matchers::Base
- Inherits:
-
Object
- Object
- Spec::FactoryGirl::Matchers::Base
show all
- Defined in:
- lib/spec/factory_girl/matchers/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(factory) ⇒ Base
8
9
10
11
|
# File 'lib/spec/factory_girl/matchers/base.rb', line 8
def initialize(factory)
@factory = factory
@errors = []
end
|
Instance Method Details
#matches?(target) ⇒ Boolean
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
|
# File 'lib/spec/factory_girl/matchers/base.rb', line 13
def matches?(target)
prepare_matches(target)
return false unless @result
unless @result.kind_of?(@target)
@errors << "'#{@target}' class expected, but factory return object kind of #{@result.class}"
return false
end
unless @result.valid?
@errors += @result.errors.full_messages
return false
end
begin
@result.save!
rescue ActiveRecord::RecordInvalid => e
@errors << e.to_s
return false
end
begin
Factory.create(@factory)
rescue ActiveRecord::RecordInvalid => e
@errors << "model has uniqueness validation, use sequence in factory (#{e.to_s})"
return false
end
@errors.empty?
end
|