DEfusion
DEfusion

Reputation: 5613

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>

Upvotes: 1

Views: 1745

Answers (2)

the55
the55

Reputation: 46

just syntax:

not:

it { should_have_instance_methods( :save ) }

but

it { should have_instance_methods( :save ) } 

(note the underscores)

Upvotes: 3

Shane Liebling
Shane Liebling

Reputation: 248

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.

Upvotes: 0

Related Questions