1

I'm trying to use Model < ActiveRecord::Base in one of my gem tests with shoulda and I'm getting the following error

./test/model.rb:1:in `require': no such file to load -- active_record (LoadError)

Without this call, I'm getting this error

./test/model.rb:1: uninitialized constant ActiveRecord (NameError)

Help! I need a barebones AR model for my tests :)


my_gem/test/model.rb

require 'active_record' # <= this fails class Model < ActiveRecord::Base # <= I need a barebones AR model here acts_as_flaggable end 

my_gem/test/test_acts_as_flaggable.rb

require 'helper' require 'model' class TestActsAsFlaggable < Test::Unit::TestCase context "a model" do setup do @model = Model.new end should "be able to set flag" do @model.flag[:foo] = "bar" assert_equal "bar", @model.flag[:foo] end should "get default value for unset flags" do @model = User.new assert_equal false, @model.flag[:some_unset_flag] end end end 

Disclaimer: I'm very new to testing. This is my first gem and I wanted to make sure I was doing things the "right" way :)

1
  • I trust you have the activerecord gem installed and you can require it from irb? Commented May 19, 2011 at 5:12

1 Answer 1

2

If you want to use it outside of a Rails application, you need to also require 'rubygems'

I the goal of your gem is to be used inside a Rails app, and if it is your first gem, I would recommend using enginex to gain some time. Granted, it's originally supposed to help making engines, but the included testing saves a lot of hassle...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.