dimanche 24 mai 2015

Dynamic expectations in Rspec

I am trying to test a dynamic url path through an Rspec expectation, as below:

describe 'registering a user' do
  context 'with valid data' do
    it 'confirms user registration' do
      visit '/users/new'
      fill_in 'Name here...', with: 'johnny bloggs'
      fill_in 'Your email here...', with: 'test1@test.com'
      click_button 'Notify me'
      expect(current_path).to eq '/users/@user.id'
      expect(page).to have_content "johhny"
      expect(page).not_to have_content "Sign up"
    end
  end
end

This is a feature test not a model unit test so I suppose this sort of object attribute , @user.id, expectation shouldn't be in a feature test. But testing the redirection to a certain path i guess is a valid thing for a feature test to be checking, and a key part of the functionality that i'm testing is that the action redirects to an object specific show page?!

So a) how should i correctly be testing this redirect thats new path involves a dynamic attribute and b) whether or not the correct thing to be doing here is testing a 'dynamic attribute' how would it be possible to test dynamic content within an rspec test? .erb perhaps?

Thank you in advance for the enlightenment.

Aucun commentaire:

Enregistrer un commentaire