views:

808

answers:

2

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>

A: 

I am not 100% sure about the integration with RSpec, but did you wrap the chunk where you call should_have_instance_methods in a context? IIRC all should statements from shoulda require a context wrapped around them.

Shane Liebling
+3  A: 

just syntax:

not:

it { should_have_instance_methods( :save ) }

but

it { should have_instance_methods( :save ) }

(note the underscores)

the55