Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8107237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:42:05+00:00 2026-06-06T00:42:05+00:00

I am working on Ruby on Rails rspec testing and I have a question.

  • 0

I am working on Ruby on Rails rspec testing and I have a question. Apparently, I have to create a dictionary, sort like

@example = {:attr1 => "somevalue", :attr2 => "some", 
            :attr3 => "someother", :stt => "abc"}

It is a very long dictionary so I would like to make it inside a factory. That would make the test look nicer.

I have been looking around but I only see FactoryGirl is designed for ActiveRecord object. Does anyone know how to use FactoryGirl to make a dictionary like this ?

Thanks for your helps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:42:06+00:00Added an answer on June 6, 2026 at 12:42 am

    You can, in fact, use FactoryGirl for this:

    See Custom Construction. Basically, you provide initialize_with to the factory definition and use your initializer function to set the dictionary values to what you need. You still get the full power of sequences, traits, etc, but can get back any Ruby object… not just an ActiveRecord.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with Ruby on rails 2.3.4 and I'd like to have a link
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
I have the simple following code, which is working in a ruby (not rails)
I'm working on Ruby on rails 2.3.4 and I'm trying to develop a Sort
I'm working with Ruby on rails 2.3.4 and I'd like to pass some parameters
I'm having a frustrating time with Rspec while working through the Ruby on Rails
I'm working on Ruby on Rails 3 application. Already, I have implemented authentication and
I'm working on ruby on rails and i'm an absolute beginner. My question is:
I'm brand new to Ruby/Rails/RSpec, and hopefully this is a dumb/simple question. I'm currently
I'm working through the Ruby on Rails 3 Tutorial: Learn Rails by Example by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.