[英]rails rspec capybara cannot get my internal api to connect
Constructing a basic rails app I'm re-factoring to do heavy lifting on an external docker/compute as a service ie iron.io. 我正在重构一个基本的Rails应用,以便对外部docker / compute即服务Iron.io进行繁重的工作。 the 'worker'
工人'
In refactoring created Grape API to allow status of processing from remote 'worker' to notify the server when processing is done. 在重构创建的Grape API时,允许远程“工作者”的处理状态在处理完成时通知服务器。 The user interface then uses ajax to poll the local server to update.
然后,用户界面使用ajax轮询本地服务器以进行更新。 API and basic tests all ok.
API和基本测试都可以。 It also works in development using Delayed::job running the worker.
它也可以使用运行工作程序的Delayed :: job在开发中工作。
I however cannot seem to get my capybara tests to work end to end as the delayed::job running process making the HTTP request back to the server always gets connection refused. 但是我似乎无法让我的水豚测试端到端地工作,因为延迟的:: job运行过程使HTTP请求返回到服务器始终会拒绝连接。
It works fine if i run a rails server in parallel as the tests: ( RAILS_ENV="test" rails s -p 3001
), then make sure the ENV variable is set to port 3001. 如果我在测试中并行运行Rails服务器,则工作正常:(
RAILS_ENV="test" rails s -p 3001
),然后确保将ENV变量设置为端口3001。
I had tried 我试过了
url="http://#{Capybara.server_host}:#{Capybara.server_port}"
) to see if that 'kicks off' the server perhaps url="http://#{Capybara.server_host}:#{Capybara.server_port}"
)以查看是否“启动”了服务器 Any thoughts, experience or guidance much appreciated 非常感谢任何想法,经验或指导
Ben 本
note: in the code 注意:在代码中
ENV variables populated in the test 测试中填充的ENV变量
Capybara.configure do |config| config.run_server = true config.server_port = "9876" config.app_host = "http://127.0.0.1:9876" end
rails 4.1.0 rspec 3.4.0 capybara 2.7.0 poltergeist 1.5.1 selenium 2.53.0 滑轨4.1.0 rspec 3.4.0水豚2.7.0 Poltergeist 1.5.1硒2.53.0
I think you're trying to have your test too too much . 我认为您正在尝试太多测试。 I would recommend that you "mock out" the interactions with the other service to make the tests self sufficient.
我建议您“模拟”与其他服务的交互,以使测试自足。 In the past I have added a
test.js
that: 在过去,我添加了一个
test.js
:
page.evaluate_script
) page.evaluate_script
) execute_script
) execute_script
) Like this: 像这样:
# test.js
$.ajax = function(settings) {
window.__ajaxRequests || (window.__ajaxRequests = []);
window.__ajaxRequests.push(settings);
return {
done: function(cb) { settings.__done = cb; }
}
}
# spec/features/jobs_spec.rb
visit '/jobs'
click_button 'Start job'
requests = page.evaulate_script('window.__ajaxRequests')
expect(requests.size).to eq(1)
expect(requests[0].url).to eq('http://jobs.yourproduct.com/start')
...
expect(page).not_to have_content('Job completed')
page.execute_script('window.__ajaxRequests[0].__done({data:{status:"complete"}})')
expect(page).to have_content('Job completed')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.