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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:53:33+00:00 2026-05-29T05:53:33+00:00

I have a module and it includes activemodel and I want to test it

  • 0

I have a module and it includes activemodel and I want to test it using rspec.

This is my setup so far:

lib/
 |__ my_module/
 |    |__ base.rb 
 |__ my_module.rb
spec/
 |__ my_module_spec.rb
 |__ spec_helper.rb
 |__ support/
      |__ shared_examples/
           |__ active_model.rb

inside ‘my_class.rb’:

require "active_model"
require "my_module/base"

inside ‘base.rb’:

module MyModule
  class Base
    extend ActiveModel::Naming

    include ActiveModel::Conversion
    include ActiveModel::Validations
  end
end

inside ‘my_module_spec.rb’:

require 'spec_helper'

describe MyModule do
  describe MyModule::Base do
    it_behaves_like "ActiveModel"
  end
end

inside ‘spec_helper.rb’:

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'my_module'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|
end

inside ‘active_model.rb’:

# taken from http://pivotallabs.com/users/jdean/blog/articles/1706-form-backing-objects-for-fun-and-profit

shared_examples_for "ActiveModel" do
  require 'test/unit/assertions'
  require 'active_model/lint'
  include Test::Unit::Assertions
  include ActiveModel::Lint::Tests

  before do
    @model = subject
  end

  ActiveModel::Lint::Tests.public_instance_methods.map { |method| method.to_s }.grep(/^test/).each do |method|
    example(method.gsub('_', ' ')) { send method }
  end
end

I thought my setup is alright but when I tried to run bundle exec rspec spec I am getting these errors:

Failures:

  1) MyModule MyModule::Base behaves like ActiveModel test to key
     Failure/Error: example(method.gsub('_', ' ')) { send method }

  2) MyModule MyModule::Base behaves like ActiveModel test to param
     Failure/Error: example(method.gsub('_', ' ')) { send method }

  3) MyModule MyModule::Base behaves like ActiveModel test to partial path
     Failure/Error: example(method.gsub('_', ' ')) { send method }

  4) MyModule MyModule::Base behaves like ActiveModel test valid?
     Failure/Error: example(method.gsub('_', ' ')) { send method }

  5) MyModule MyModule::Base behaves like ActiveModel test persisted?
     Failure/Error: example(method.gsub('_', ' ')) { send method }

  6) MyModule MyModule::Base behaves like ActiveModel test model naming
     Failure/Error: example(method.gsub('_', ' ')) { send method }

  7) MyModule MyModule::Base behaves like ActiveModel test errors aref
     Failure/Error: example(method.gsub('_', ' ')) { send method }

  8) MyModule MyModule::Base behaves like ActiveModel test errors full messages
     Failure/Error: example(method.gsub('_', ' ')) { send method }

What am I doing wrong here? How do I test ActiveModel properly?

Thanks in advance

  • 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-29T05:53:34+00:00Added an answer on May 29, 2026 at 5:53 am

    You try to do too much. Because you want test the ActiveModel library. You just need test if your Object include this module

    
    require 'spec_helper'
    
    describe MyModule do
      describe MyModule::Base do
        it { MyModule::Base.should include(ActiveModel::Conversion) }
        it { MyModule::Base.should include(ActiveModel::Validations) }
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a GWT module that includes an external javascript file using tag.
I have class Fruit < ActiveRecord::Base includes Skin end and the mixin module module
I have a project and this project includes a module about web page html
I have a rails module included for reference below that I have included using
I have a class that I want to include in a GWT module. Unfortunately,
I have a model, Show and a module Utilities class Show < ActiveRecord::Base include
Let's say I have a perl module file and I want to include and
I have a module in my Drupal 7 application called Feedback. It includes a
I have already defined an interface and a module: module type BASE = sig
I have a Drupal (v6.17) Content Type which includes a Taxonomy field. I want

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.