문제

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

도움이 되었습니까?

해결책

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

expect{ sign_up(:client) }.to change(Individual, :count).by(1)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top