Search code examples
ruby-on-railsrspecrspec-rails

How to convert errors_on to RSpec 3 syntax?


I recently upgraded from RSpec 2.99 to RSpec 3. This would be one of my specs:

require 'spec_helper'

  describe User, :type => :model do

    it "is invalid without a password" do
      expect(FactoryGirl.build(:user, :password => nil).errors_on(:password).size).to eq(1)      
    end

  end

end

I already ran the Transpec gem that is supposed to convert most of my specs to RSpec 3 syntax. However, I am still getting this error (and a few others):

 Failure/Error: expect(FactoryGirl.build(:user, :password => nil).errors_on(:password).size).to eq(1)
 NoMethodError:
   undefined method `errors_on' for #<User:0x00000108beaba0>

I tried to re-write the test in a number of different ways but the error won't go away.

Can anybody help?


Solution

  • Looks like it exists in rspec-collection_matchers. Also from this issue you can monkey patch it.