0

我正在使用 rspec 和 capybara ,js: truedescribe我有一个问题:

     Failure/Error: visit '/users/sign_in'
     WebMock::NetConnectNotAllowedError:
       Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:62453/__identify__ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}

       You can stub this request with the following snippet:

       stub_request(:get, "http://127.0.0.1:62453/__identify__").
         with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
         to_return(:status => 200, :body => "", :headers => {})

如果我像他们说的那样存根,下一个端口是不同的:

  1) the signin process signs me in
     Failure/Error: visit '/users/sign_in'
     WebMock::NetConnectNotAllowedError:
       Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:62453/__identify__ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}

       You can stub this request with the following snippet:

       stub_request(:get, "http://127.0.0.1:62453/__identify__").
         with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
         to_return(:status => 200, :body => "", :headers => {})

       registered request stubs:

       stub_request(:get, "http://127.0.0.1:61772/__identify__").
         with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'})

我尝试将正则表达式添加到端口,但一直失败。

4

1 回答 1

1

你不能同时使用 webmock 和 js: true 。当设置 js: true 时,Capybara 使用单独的浏览器发出请求,因此任何拦截测试线程中的连接的尝试都将无效。
您在输出中看到的连接尝试实际上是 Capybara 尝试启动它的服务器以在其中运行应用程序,并验证服务器是否已启动。阻止这将阻止一切正常工作。如果你真的需要在将 capybara 与 js: true 一起使用时模拟一些请求,你可能应该查看 puffing-billy gem,它实现了与 capybara 驱动程序集成并允许这种事情的代理。

于 2015-09-29T16:28:35.350 回答