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

  • Home
  • SEARCH
  • 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 982805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:45:26+00:00 2026-05-16T04:45:26+00:00

I’ve setup Rspec2 beta5 and shoulda as following to use shoulda macros inside rspec

  • 0

I’ve setup Rspec2 beta5 and shoulda as following to use shoulda macros inside rspec model tests.

=================

Update 2011-Feb-18

Now we can use shoulda-matchers out of the box.

Just add gem shoulda-matchers in you Gemfile and nothing else in spec_helper or any hack. It just runs.

=================

Gemfile

group :test do
  gem "rspec", ">= 2.0.0.beta.4"
  gem "rspec-rails", ">= 2.0.0.beta.4"
  gem 'shoulda',          :git => 'git://github.com/bmaddy/
shoulda.git'
  gem "faker"
  gem "machinist"
  gem "pickle",           :git => 'git://github.com/codegram/
pickle.git'
  gem 'capybara',         :git => 'git://github.com/jnicklas/
capybara.git'
  gem 'database_cleaner', :git => 'git://github.com/bmabey/
database_cleaner.git'
  gem 'cucumber-rails',   :git => 'git://github.com/aslakhellesoy/
cucumber-rails.git'
end

spec_helper.rb

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

require 'shoulda'

Rspec.configure do |config|

spec/models/outlet_spec.rb

require 'spec_helper'

describe Outlet do
  it { should validate_presence_of(:name) }
end

And when I run the spec, I get the following error.

[~/rails_apps/rails3_apps/automation (master)⚡] ➔ spec spec/models/
outlet_spec.rb
DEPRECATION WARNING: RAILS_ROOT is deprecated! Use Rails.root instead.
(called from join at /home/millisami/.rvm/gems/ruby-1.9.1-p378%rails3/
bundler/gems/shoulda-87e75311f83548760114cd4188afa4f83fecdc22-master/
lib/shoulda/autoload_macros.rb:40)
F

1) Outlet
    Failure/Error: it { should validate_presence_of(:name) }
    undefined method `validate_presence_of' for
#<Rspec::Core::ExampleGroup::Nested_1:0xc4dc138 @__memoized={}>
    # ./spec/models/outlet_spec.rb:4:in `block (2 levels) in <top
(required)>'

Finished in 0.0399 seconds
1 example, 1 failures
[~/rails_apps/rails3_apps/automation (master)⚡] ➔

Why the "undefined method" ?? Is the shoulda getting loaded?

  • 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-16T04:45:26+00:00Added an answer on May 16, 2026 at 4:45 am

    Using RSpec 2.0.0.beta.19

    # Gemfile
    group :test do
      gem "rspec", ">= 2.0.0.beta.19"
      gem "rspec-rails", ">= 2.0.0.beta.17"
      gem "shoulda"
    end
    
    # spec/spec_helper.rb
    require 'rspec/rails'
    require 'shoulda/integrations/rspec2' # Add this line
    
    # In your specs....
    it { should validate_presence_of(:name) }
    

    Running rake spec should now load and run specs including the RSpec 2 matchers.

    • 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.