2014-09-04 53 views
1

我试图在page.current_url上运行预期,但是,由于某些原因,page.current_url没有得到更新。水豚不遵循重定向

发生这种情况当我点击链接而不是访问网址。看:

scenario 'When a user who is not an admin visits the dashboard' do 
    before do 
     sign_up user 
     visit admin_statistics_path 
    end 

    its(:current_url){ should have_a_uri_of root_path } 
end 

所有这些规格通过。然而,当我点击,而不是访问admin_statistics_path链接到admin_statistics_path的current_url预期失败:

describe 'When a user who is not an admin clicks control panel' do 
     before do 
      sign_up user 
      click_link 'dashboard' 

#   puts current_url 
     end 

    it { should have_css 'div.danger', "You do not have sufficient priviledges to access the admin area. Try logging out and logging in with an account that has admin priviledges." } 
    it { should have_css 'h1', text: 'Goals'} 
    its(:current_url){ should have_a_uri_of root_path } 
end 

所有上述预期从current_url一个通过开!即使怪异,如果我把current_url,规范通:

describe 'When a user who is not an admin clicks control panel' do 
     before do 
      sign_up user 
      click_link 'dashboard' 

      puts current_url #=> returns the initial url despite the specs passing 
     end 

    it { should have_css 'div.danger', "You do not have sufficient priviledges to access the admin area. Try logging out and logging in with an account that has admin priviledges." } 
    it { should have_css 'h1', text: 'Goals'} 
    its(:current_url){ should have_a_uri_of root_path } 
end 
  • 我如何获得水豚等待重定向?
  • 为什么把current_url导致预期通过?
  • 为什么访问 url会导致current_url的期望值通过?
  • 为什么点击一个链接不会导致current_url的期望值通过?
+0

1)使用'sleep'时将使用水豚等待行为has_current_path匹配如果重定向需要时间2)'it {should_a_uri_of URI.parse(current_url)}'3)您已经通过这个'its(:current_url){should have_a_uri_of root_path}'将'current_url'赋值给'root_path''这就是为什么每次它采取'root_path'而不是真正的目前的网址 – 2014-09-04 10:51:23

+2

并请修复缩进 – 2015-08-19 16:27:08

回答

2

对于任何来到这个问题现在,水豚2.5添加检查的current_path

it { should have_current_path(root_path) } 

expect(page).to have_current_path(root_path)