ruby-on-rails - 在 rspec 测试之前启动 rails?

标签 ruby-on-rails ruby selenium rspec selenium-webdriver

在 RSpec 测试中,是否有任何方法,按照惯例或代码,让 rails 在测试运行之前启动?我正在尝试为使用 chrome 的 selenium 测试设置一个测试框架,现在我只是因为缺少正在运行的服务器而受阻。

require 'spec_helper'

describe 'The first tab' do
  before(:each) do
    @driver = Selenium::WebDriver.for :chrome
  end

  it 'Shows the list' do
    @driver.navigate.to 'index.html'
  end
end

我是 RSpec 的新手,所以我不确定如何创建一套在 Rails 服务器运行时全部运行的测试。

最佳答案

你应该使用 Capybara来测试这些东西。它在内部使用 selenium-webdriver 来提供 JavaScript 测试支持。

对于 Capybara,您可以将此测试放在 spec/integrationspec/requests 文件夹中,并像这样编写:

require 'spec_helper'
describe 'The first tab' do
  it "shows the list", :js => true do
    visit list_path
  end
end

通过在示例名称后放置 :js => true,Capybara 将知道将其作为 JavaScript 测试运行。

关于ruby-on-rails - 在 rspec 测试之前启动 rails?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8290106/

相关文章:

ruby-on-rails - 数组 will_paginate rspec 的未定义方法 total_pages'

java - 获取 HTMLUnitDriver 绕过不受信任的证书验证(Selenium 2.0)

python - 需要使用 Selenium Chromedriver 和 Python 的帮助

javascript - 在 Rails 中保存和更新基于 AJAX 的图形的状态

ruby-on-rails - rails : How to populate Db with data without migrations getting in the way?

ruby-on-rails - ActiveRecord枚举错误: “is not a valid value”

ruby - 比较 Ruby 中的字节

ruby - 使用 SHA256 摘要签名的 OpenSSL RSA

python - 有没有办法在 Ruby 中将对象转换为 boolean 值

c# - 如何配置 TeamCity 以同时运行测试而不是一个接一个地运行?