mercredi 15 mars 2017

Rspec weird behavior

I just noticed weird Rspec behaviour. I wonder if it's Rspec's error or my approach to testing is incorrect.

I have this controller test (I cut out unnecessary pieces):

describe 'GET #new' do def get_new(group_id = nil) get :new, group_id: group_id end

context 'with logged in user' do
  context 'with group_id' do
    let(:group) { create(:group) }

    before { get_new(group.to_param)}

    it 'renders correct template' do
      expect(response).to render_template(:new)
    end

    it 'returns success' do
      expect(response).to be_success
    end
  end
end

end

this is the way I've been testing controllers for a long time, considering checking against template and response code is enough to make sure controller renders actual page.

However now, tweaking form on the page, I get an error in this action, which I can clearly see in the browser: browser error But I just discovered that both of those tests pass when in fact there is this error.

What am I doing wrong and how do I check for this error in my spec?

Aucun commentaire:

Enregistrer un commentaire