Question

I have trouble with testing model count through feature/scenario rspec instrument

require 'spec_helper'

feature 'Registration' do
  scenario 'Guest can sign up as individual' do
    with_role(:guest)
    sign_up(:client)
    Individual.count.should == 1
    # should be replaced by expect{ sign_up(:client) }.to change{ Individual.count }.by(1)
  end
end

How can I replace model.count should to the expect in the block to expecting in scenario? I don't want to use should because of record count changes every time I use it

Regards, Alex

Was it helpful?

Solution

The correct way of using the change matcher of rspec is as follows:

expect{ sign_up(:client) }.to change(Individual, :count).by(1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top