Module: HasMockObjects::LocalInstanceMethods

Included in:
ClassMethods
Defined in:
lib/has_mock_objects.rb

Constant Summary collapse

FAKERSHORTCUTS =
{
  word: lambda { Faker::Lorem.word },
  words: lambda { Faker::Lorem.words.join(' ') },
  sentence: lambda { Faker::Lorem.sentence },
  sentences: lambda { Faker::Lorem.sentences.join(' ') },
  paragraph: lambda { Faker::Lorem.paragraph },
  paragraphs: lambda { Faker::Lorem.paragraphs.join(' ') },
  name: lambda { Faker::Name.name },
  first_name: lambda { Faker::Name.first_name },
  last_name: lambda { Faker::Name.last_name },
  phone_number: lambda { Faker::PhoneNumber.phone_number },
  email: lambda { Faker::Internet.email },
  credit_card_number: lambda { Faker::Business.credit_card_number },
  credit_card_type: lambda { Faker::Business.credit_card_type },
  today: lambda { Time.now },
  recent_date: lambda { Time.now - rand(HasMockObjects::SECONDS_IN_YEAR) },
  historical_date: lambda { Time.now - rand(HasMockObjects::SECONDS_IN_YEAR*10) }
}

Instance Method Summary collapse

Instance Method Details

#mock_attributes(attributes) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/has_mock_objects.rb', line 35

def mock_attributes(attributes)
  mock = OpenStruct.new
  attributes.each do |attribute, type|
    mock.send( attribute.to_s + '=', FAKERSHORTCUTS[type].call )
  end
  return mock
end

#mock_objectsObject



43
44
45
# File 'lib/has_mock_objects.rb', line 43

def mock_objects
  @mock_objects ||= {}
end