Search code examples
ruby-on-railsmacrosrspecshoulda

Using shoulda macros with RSpec


I'm trying to use the shoulda macros within RSpec and am having some problems.

I've done the following:

spec_helper.rb:

require 'shoulda/active_record/macros'

Spec::Runner.configure do |config|
    ...
    config.include(Shoulda::ActiveRecord::Macros, :type => :model)

spec/models/foo_spec.rb:

describe Foo do
    it { should_have_instance_methods( :save ) } # just for example
end

Which gives me a failure with:

undefined method 'get_options!' for #<Spec::Rails::Example::ModelExampleGroup::Subclass_1:0xb714046c>


Solution

  • just syntax:

    not:

    it { should_have_instance_methods( :save ) }
    

    but

    it { should have_instance_methods( :save ) } 
    

    (note the underscores)