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 4062362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:35:19+00:00 2026-05-20T15:35:19+00:00

I’m creating a GUI application which interacts with database so I need fixture management

  • 0

I’m creating a GUI application which interacts with database so I need fixture management for my RSpec tests. I use sqlite database and am going to write a class which will manipulate data with straight SQL. I need to test it’s database interaction functionality.

I couldn’t find any libraries which could do 2 basic things when I run RSpec tests:

  1. Clear database or particular tables in it
  2. Load specific data into it so I can use that data in my tests

There are already ten thousands of blog posts and manuals which clearly explain how to use FactoryGirl with any version of Rails but no one without it. I started digging around and this is what I have (note that I don’t use rails and it’s components):

spec/note_spec.rb:

require 'spec_helper'
require 'note'

describe Note do
  it "should return body" do
    @note = Factory(:note)
    note.body.should == 'body of a note'
  end
end

spec/factories.rb:

Factory.define :note do |f|
  f.body 'body of a note'
  f.title 'title of a note'
end

lib/note.rb:

class Note
  attr_accessor :title, :body
end

When I run rspec -c spec/note_spec.rb I get following:

F

Failures:

  1) Note should return body
     Failure/Error: @note = Factory(:note)
     NoMethodError:
       undefined method `save!' for #<Note:0x8c33f18>
     # ./spec/note_spec.rb:6:in `block (2 levels) in <top (required)>'

Questions:

  1. Is it possible at all to use FactoryGirl without Rails and Rails libraries like ActiveModel/ActiveRecord?
  2. Do I have to subclass my Note class from particular class, since FactoryGirl is looking for save! method?
  3. Are there any other more viable solutions besides FactoryGirl?

I’m totally new to Ruby/RSpec/BDD, so any help will be greatly appreciated 😉

  • 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-05-20T15:35:20+00:00Added an answer on May 20, 2026 at 3:35 pm

    By default factory_girl creates saved instances. If you don’t want to save the object to the database, you can create unsaved instances using the build method.

    require 'spec_helper'
    require 'note'
    
    describe Note do
      it "should return body" do
        @note = Factory.build(:note)
        note.body.should == 'body of a note'
      end
    end
    

    See “Using Factories” in the Getting Started file.

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

Sidebar

Related Questions

No related questions found

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.