我可以使用 RSpec 来测试部署的站点吗? [英] Can I use RSpec to test deployed site?

查看:35
本文介绍了我可以使用 RSpec 来测试部署的站点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我应该说,我不太擅长测试我的代码,而且直到最近我才开始这样做.

I should say first, that I'm not very well-versed in testing my code, and I didn't do it at all until recently.

所以我有这个 rails 应用程序.它基本上是一个 API 端点.它接受请求并吐出 JSON.有很好的(我希望)测试覆盖率应该测试大部分功能.

So I have this rails app. It's basically an API endpoint. It takes requests and spits JSON. There's good (I hope) test coverage that should test most of the functionality.

现在我们正在部署一个临时环境,并希望让负载测试人员(独立部门)玩"它.我想非常确定我们是否正确部署了它.

Now we're deploying a staging env and want to let load testing guys (independent department) to "play" with it. I want to be super sure that we deployed it correctly.

我可以针对这个临时部署运行 RSpec 的请求规范吗?人们会做这种测试吗?什么是最佳实践?我应该读什么?

Can I run RSpec's request specs against this staging deployment? Do people do this kind of testing at all? What are best practices? What should I read?

推荐答案

是的,您可以使用 Rspec 和 Capybara 测试已部署的站点.您需要像这样更改配置:

Yes you can test deployed site using Rspec and Capybara. You need change configuration like this:

  1. 将驱动更改为 :webkit:selenium:poltergeist,因为默认驱动 (:rack_test) 不支持在远程服务器上运行.

  1. Change driver to :webkit, :selenium or :poltergeist, because the default driver (:rack_test) does not support running against a remote server.

Capybara.javascript_driver = :selenium

  • 设置 app_host.

  • Set app_host.

    Capybara.app_host = 'http://example.com'
    

  • 关闭本地服务器.

  • Turn off local server.

    Capybara.run_server = false
    

  • 之后,您可以使用 Capybara DSL 为已部署的服务器创建测试.

    After that you can create test for deployed server using Capybara DSL.

    这篇关于我可以使用 RSpec 来测试部署的站点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆