我有rspec测试,我觉得pilly有一个漏洞,或者我误解了设置中白名单的使用。
基本上,测试是关于检查,如果第三方托管图像(在名为Cloudinary的服务上)需要时间来下载页面,那么用户会看到加载微调器,并且在图像最终加载后,微调器消失并且不再可见。
我确定比利是
的根本原因如果我不使用puffing billy(通过删除billy:true)来截断/伪造第三方图像的10秒响应延迟,正如您可能猜到的那样,我看到了图像(使用save_and_open_page来制作确定)太快了,我的测试无法实施。
如果我使用billy使用billy:true,那么图像NEVER出现(由save_and_open_page检查)并且旋转器继续转动,因为实际的存根图像永远不会出现,就像它被吸气“阻塞”一样比利...也使测试不可行:(
Puffing billy设置
Capybara.configure do |config|
# we must force the value of the capybara server port. We have to do that because puffing-billy
# saves everything locally for a specific host and port. But, capybara starts your rack application
# on a new port each time you run your tests. The consequence is puffing-billy
# is not able to reuse the created cache files and tries to do all the API call again.
# source - kevin.disneur.me/archives/2015-03-05-end-to-end-tests-in-javascript.html
config.server_port = 60001
# source: comments in coderwall.com/p/jsutlq, enable to load save_and_open page with css and js
config.asset_host = 'http://localhost:3000'
end
require 'billy/capybara/rspec'
Billy.configure do |c|
c.cache = true
c.cache_request_headers = false
c.persist_cache = true
c.non_successful_cache_disabled = true
c.non_successful_error_level = :warn
c.whitelist = ['localhost', '127.0.0.1', 'https://res.cloudinary.com']
c.ignore_cache_port = true
c.cache_path = "spec/support/http_cache/billy/"
# Only set non_whitelisted_requests_disabled **temporarily**
# to false when first recording a 3rd party interaction. After
# the recording has been stored to cache_path, then set
# non_whitelisted_requests_disabled back to true.
c.non_whitelisted_requests_disabled = true
end
rspec测试:
context "non signed in visitor", js: true, billy: true do
describe "Spinner shows while waiting then disappears" do
it "should work" doproxy.stub("https://res.cloudinary.com/demo/image/upload/sample.jpg").and_return(
Proc.new { |params, headers, body|
sleep 10
{code: 200}
}
)
visit actual_deal_page_path(deal)
# detect spinner
expect(page).to have_css('div#fullPageLoadingSpinner', visible: :visible)
# check subsequent image elements not yet visible
expect(page).to have_no_css("img[src*='https://res.cloudinary.com/demo/image/upload/sample.jpg']")
# then after 15 seconds, the cloudinary image finally is loaded and
# the spinner disappears
sleep 15
expect(page).to have_css('div#fullPageLoadingSpinner', visible: :hidden)
expect(page).to have_css("img[src*='https://res.cloudinary.com/demo/image/upload/sample.jpg']")
end
end
end
视图中的图片
<section
id="introImg"
<img src="https://res.cloudinary.com/demo/image/upload/sample.jpg" class="cld-responsive deal-page-bckdImgCover"
</section>
我尝试了不同的设置变体,尝试将https // res.cloudinary更改为res.cloudinary.com ...没有效果
最后,我认为这很重要,我一直在我的测试日志中看到:
puffing-billy: CACHE KEY for 'https://res.cloudinary.com:443/demo/image/upload/sample.jpg' is 'get_res.cloudinary.com_2c4fefdac8978387ee341535c534e21e2588ed76'
puffing-billy: Connection to https://res.cloudinary.com:443/demo/image/upload/sample.jpg not cached and new http connections are disabled
puffing-billy: CACHE KEY for 'https://res.cloudinary.com:443/demo/image/upload/sample.jpg' is 'get_res.cloudinary.com_2c4fefdac8978387ee341535c534e21e2588ed76'
puffing-billy: Connection to https://res.cloudinary.com:443/demo/image/upload/sample.jpg not cached and new http connections are disabled
puffing-billy: CACHE KEY for 'https://res.cloudinary.com:443/demo/image/upload/sample.jpg' is 'get_res.cloudinary.com_2c4fefdac8978387ee341535c534e21e2588ed76'
puffing-billy: Connection to https://res.cloudinary.com:443/demo/image/upload/sample.jpg not cached and new http connections are disabled
puffing-billy: CACHE KEY for 'https://res.cloudinary.com:443/demo/image/upload/sample.jpg' is 'get_res.cloudinary.com_2c4fefdac8978387ee341535c534e21e2588ed76'
puffing-billy: Connection to https://res.cloudinary.com:443/demo/image/upload/sample.jpg not cached and new http connections are disabled
在这些测试日志中,首先我不太明白为什么同一资源有这么多行,其次,这条消息的意思是“没有缓存,新的http连接被禁用”。我尝试了其他类似声音问题的门票,如#104或#179或者,但我的错误可能不同......