[rspec-users] rspec and shoulda have_indices

David Chelimsky dchelimsky at gmail.com
Fri Sep 2 09:17:37 EDT 2011

On Sep 2, 2011, at 4:12 AM, slavix wrote:

> Hello,
> I am developing a rails 3.1 app. My Gemfile has shoulda gems
> Gemfile
> ..
> gem "shoulda"
> gem "shoulda-matchers"

You only need shoulda-matchers if you're using rspec.

> In a model spec I have
> spec file
>  it { should have_indices([:user, :currency]) }
> And I get this error...
> NoMethodError:
>       undefined method `has_indices?' for #<Balance:0xf3b860c>

When there is no have_xxx method defined, rspec-expectations implements method_missing such that it assumes you want to send the object the has_xxx? predicate. What your experiencing suggests that there is no have_indices method. Looking at http://rdoc.info/github/thoughtbot/shoulda-matchers/master/Shoulda/Matchers/ActiveRecord, I see a singular have_db_index matcher, but I don't see a pluralized one, so perhaps this method doesn't exist. If it does, then something is wrong with your configuration, as it is not being made available.


More information about the rspec-users mailing list