Class: Spec::FactoryGirl::Matchers::BeCreatedByFactory

Inherits:
Base
  • Object
show all
Defined in:
lib/spec/factory_girl/matchers/be_created_by_factory.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Spec::FactoryGirl::Matchers::Base

Instance Method Details

#descriptionObject



5
6
7
# File 'lib/spec/factory_girl/matchers/be_created_by_factory.rb', line 5

def description
  "create instance of '#{@target}' by factory '#{@factory}'"
end

#failure_message_for_shouldObject



22
23
24
# File 'lib/spec/factory_girl/matchers/be_created_by_factory.rb', line 22

def failure_message_for_should
  "expected #{@target.inspect} to be created by factory '#{@factory}'\n" + @errors.join("\n")
end

#failure_message_for_should_notObject



26
27
28
# File 'lib/spec/factory_girl/matchers/be_created_by_factory.rb', line 26

def failure_message_for_should_not
  "expected #{@target.inspect} not to be created by factory '#{@factory}'"
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/spec/factory_girl/matchers/be_created_by_factory.rb', line 9

def matches?(target)
  prepare_matches(target)
  
  begin
    @result = Factory.create(@factory)
  rescue ActiveRecord::RecordInvalid => e
    @errors << e.to_s
    return false
  end
  
  super
end