Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用Capybara测试js重定向?_Ruby On Rails_Capybara - Fatal编程技术网

Ruby on rails 如何使用Capybara测试js重定向?

Ruby on rails 如何使用Capybara测试js重定向?,ruby-on-rails,capybara,Ruby On Rails,Capybara,在我的控制器中,使用以下代码执行重定向: 会话控制器 def create render js: "window.location.pathname = #{home_path.to_json}" end 但是,当我运行capybara时,它在登录提交后不会进入主页: describe "Login Test", :js => true do before do @user = FactoryGirl.create(:user) end it 'should sh

在我的控制器中,使用以下代码执行重定向:

会话控制器

def create
  render js: "window.location.pathname = #{home_path.to_json}"
end
但是,当我运行capybara时,它在
登录
提交后不会进入主页:

describe "Login Test", :js => true do
  before do
    @user = FactoryGirl.create(:user)
  end
  it 'should show the users first name' do
    visit login_path
    fill_in 'email', with: @user.email
    fill_in 'password', with: @user.password
    click_button "Log In"
    save_and_open_page
    assert page.has_content? @user.first_name
  end
end
当我通过添加
launchy gem
并运行
save_和_open_页面
进行故障排除时,我会得到一个包含以下文本的页面:
window.location.pathname=“/”

水豚给了我以下错误:
Capybara::ElementNotFound:找不到xpath”/html“

水豚似乎永远都无法通过登录按钮。

你试过这个吗

respond_to do |format|
  format.js { render :js => 'window.location.href = "#{home_path.to_json}"' }
end