[rspec-users] rspec and shoulda have_indices

slavix mikerin.slava at gmail.com
Fri Sep 2 18:58:12 EDT 2011

I updated spec with correct statements

  it { should have_db_index([:user, :currency, :tradable]) }
and my db (dev and test) has the indexes

Action	Keyname	Type	Unique	Packed	Field	Cardinality	Collation	Null
Edit 	Drop 	PRIMARY	BTREE	Yes	No	id	0	A
Edit 	Drop 	index_balances_on_currency_id	BTREE	No	No	currency_id	0	A
Edit 	Drop 	index_balances_on_tradable_id	BTREE	No	No	tradable_id	0	A
Edit 	Drop 	index_balances_on_user_id	BTREE	No	No	user_id	0

but I get an error running rspec
  2) Balance shoulda validations
     Failure/Error: it { should
have_db_index([:user, :currency, :tradable]) }
       Expected Balance to have a  index on columns user and currency
and tradable ()

On Sep 2, 6:17 am, David Chelimsky <dchelim... at gmail.com> wrote:
> 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 athttp://rdoc.info/github/thoughtbot/shoulda-matchers/master/Shoulda/Ma..., 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.
> HTH,
> David
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list