所以我一直在努力与此相当长一段时间了,我似乎无法弄清楚我们出了什么问题,并且找不到什么可能会导致这个问题。使用rspec,水豚和poltergeist的测试返回空html和空屏幕截图
我对Ruby和Rails以及测试/行为驱动开发相对较新,并试图使用Rspec和Capybara使用PhantomJS通过Poltergeist编写一些接受(浏览器)测试。我相信有些人也称这种集成测试(他们可能从某种角度来看),但这是另外一个讨论。
我有一个非常简单的功能,我不能做什么,我想:
require 'feature_helper'
feature 'Logging in', :js => true do
scenario 'with incorrect credentials' do
visit '/login'
puts page.html
save_and_open_page
page.driver.render('_screenshot.png', :full => true)
page.html.should have_selector("title", :text => "hi")
end
end
所以。简单,正确。它应该只是去/login
并向我扔HTML内容,以及我想看到使用save_and_open_page
的页面,我希望它采取截图。我添加了一个简单的should have_selector
为了让测试失败,试图获得更多的反馈。
我feature_helper.rb
的相对含量:
require 'spec_helper'
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
include Capybara::DSL
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {
:debug => true,
:inspector => true
})
end
Capybara.default_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
FakeWeb.allow_net_connect = %r[^https?://(127.0.0.1|localhost)] # allow phantomjs/poltergeist requests
DatabaseCleaner.strategy = :truncation
RSpec.configure do |config|
config.before :each do
# Set the hostname to something with test
@host = "test.iome:3003"
host! @host
Capybara.default_host = Capybara.app_host = "http://#{@host}/"
Capybara.server_port = 3003
Capybara.reset_sessions!
# Start the database cleaner
config.use_transactional_fixtures = false
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
end
,也是我spec_helper.rb
:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'pry'
require 'fakeweb'
FakeWeb.allow_net_connect = false
这一切都非常简单。
现在,在我的控制台我看到以下内容:
{"name"=>"visit", "args"=>["http://test.iome:3003//login"]}
{"response"=>{"status"=>"fail"}}
{"name"=>"body", "args"=>[]}
{"response"=>"<html><head></head><body></body></html>"}
<html><head></head><body></body></html>
{"name"=>"body", "args"=>[]}
{"response"=>"<html><head></head><body></body></html>"}
{"name"=>"render", "args"=>["_screenshot.png", true]}
{"response"=>true}
{"name"=>"body", "args"=>[]}
{"response"=>"<html><head></head><body></body></html>"}
此外,截图仅仅是一个白色和空白页。当我尾随我的log/test.log
文件时,我看不到请求正在执行。我已经尝试将方法visit
更改为get
,并且会提出请求,但不会更改任何结果。
我已经完全用完的东西,这可能是想法,它是相当令人沮丧,:(
最终信息则有关版本:
- rspec的2.10.0
- 1.1.4水豚
- 骚灵1.0.3
- 红宝石1.8.7
- 轨3.2.13
不幸的是,我们仍然在红宝石1.8.7,但正在努力使该版本上涨。不过,我认为这不应该影响测试。
任何帮助将不胜感激!
如果你只是去你的浏览器并输入URL(即'http://test.iome:3003 /'),你会得到一个回应? –
当我运行测试时:是的。不过,我现在似乎还多了一点点。这是新的一天,所以新的事情正在发生:)我相信用于测试的端口仍在使用中,导致应用程序在引导时超时。看起来nginx还在运行。 “page.html”属性现在也有内容。但是,虽然屏幕截图文件已经制作完成,但之前空白,但它现在根本不会创建文件。另外,我向登录所需的数据库添加了一些信息,但这些信息对应用程序不可用。会让你知道更新。 – Mark
您可以添加控制器操作的代码吗?我遇到同样的问题,想要比较! :d –