Ruby on rails Rspec中的动态期望

Ruby on rails Rspec中的动态期望,ruby-on-rails,ruby,testing,rspec,tdd,Ruby On Rails,Ruby,Testing,Rspec,Tdd,我试图通过Rspec预期测试动态url路径,如下所示: 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:

我试图通过Rspec预期测试动态url路径,如下所示:

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
这是一个特性测试,不是一个模型单元测试,所以我认为这种对象属性@user.id,expectation不应该出现在特性测试中。但是测试重定向到某个路径我想对于功能测试来说是一件有效的事情,我正在测试的功能的一个关键部分是动作重定向到特定于对象的显示页面

因此,a)我应该如何正确地测试这个重定向,它的新路径涉及到一个动态属性,b)这里要做的正确的事情是否是测试一个“动态属性”,如何在rspec测试中测试动态内容。也许是雇员再培训局


提前感谢您的启发。

您可以使用普通字符串插值:

expect(current_path).to eq "/users/#{ User.last.id }"
或路径帮助器:

expect(current_path).to eq user_path(User.last)