Add
capybara-webkitto yourGemfileand let Guard::Bundler install it automatically (or manually viabundle installif you don’t use Guard).gem 'capybara-webkit', '>= 1.0.0.beta4'
Set Javascript driver to
:webkitfor Capybara inspec_helper.rb.Capybara.javascript_driver = :webkit
Configure RSpec use non-transactional fixtures, configure Database Cleaner in
spec_helper.rb.Notice with this setup, we’ll only use truncation strategy when driver is not
:rack_test. this will make normal specs run faster.config.use_transactional_fixtures = false config.before :each do if Capybara.current_driver == :rack_test DatabaseCleaner.strategy = :transaction DatabaseCleaner.start else DatabaseCleaner.strategy = :truncation end end config.after :each do DatabaseCleaner.clean endTag your scenarios in
spec/acceptance/*_spec.rbto use Javascript driver if necessary.scenario 'Create a lolita via AJAX', :js => true do end
Wait for any AJAX call to be completed in your specs. This is very important, or you will get many strange issues like no database record found, AJAX call get empty response with 0 status code, etc.
For example if you have a simple AJAX form, the
successcallback will simply redirect browser to another page vialocation.href = '/yet_another_page';. You can use the following code to wait for it done.scenario 'Create a lolita via AJAX', :js => true do visit new_lolita_path click_on 'Submit' wait_until { page.current_path == lolita_path(Lolita.last) } # Your expections for the new page end
推荐一些 Ruby on Rails 学习资料
January 12th, 2011
Ruby
开始之前应该看看 Ruby 官方网站 上的 About Ruby、Ruby in Twenty Minutes 和 Ruby From Other Languages 得到初步的印象和感性认识。在页面底部可以选择语言查看中文版。
经验比较丰富的开发者可以通过 Ruby User’s Guide [注1] 快速入门 Ruby,之后应该准备一本 The Ruby Programming Language 作为日常参考。因为作为 Ruby 语言创始人松本行弘参与编写的书籍,它对 Ruby 语言的介绍最完整。而世界上第一本介绍 Ruby 语言的英文书籍 Programming Ruby 大概是最多人用于入门 Ruby 的书籍,虽然对于有经验的开发者来说它稍显啰嗦。Programming Ruby 第一版有提供免费的在线版本。如果你还没有任何程序设计经验,Ruby Programming: 向Ruby之父学程序设计 应该是不错的选择,作者高桥征义是日本 Ruby 协会会长。
Rails
同样,有经验的开发者可以直接通过 Ruby on Rails Guides 入门 Rails。而 Agile Web Development with Rails 则大概是最多人用于入门 Rails 的书籍,它的第四版已经使用目前最新的 Rails 3。
中文资料
@ihower 组织的 Ruby Taiwan 社区有提供 Ruby User’s Guide 的繁体中文翻译以及 Ruby on Rails Guides 前两章的繁体中文翻译。@ihower 自己编写的 Ruby on Rails 實戰手冊 也是一部很不错的面向有一定经验开发者的在线书籍。
其它
Ruby on Rails 社区非常注重代码的美观及可读性。使用相同的 coding style 是保证代码美观可读的有效措施之一,所以在自己尝试写代码时应该看看 Ruby Coding Style Guide。
真正开始使用 Ruby on Rails 之后,Rails Searchable API Doc 和 RubyDoc.info 一定会是最常用的两个在线文档服务。
注1: Ruby User’s Guide 写于 Ruby 1.8.3 时代,现在建议使用的 Ruby 版本是 1.8.7。文中提到的 eval.rb 应该使用 irb 取代,另外可以使用 irbtools 大幅度增强 irb。Ruby Taiwan 的繁体中文翻译版本对类似问题有提供译注,建议参考。
该日志未加标签。禁止浏览器发送 HTTP_REFERRER header 保护私密网站 URL
January 16th, 2010
今天看到 Twitter 上有人讨论浏览器发送 HTTP_REFERRER header 导致民间 Twitter Web 客户端地址被泄露的问题。研究了一下,这个问题的最终解决都需要依靠浏览器,网站自己没有办法强制禁止浏览器发送 HTTP_REFERRER header。
Chrome/Chromium
Chrome/Chromium 的 WebKit 内核最新版支持 HTML5 里的 noreferrer link relation。这个功能允许网页作者在 a 和 area 元素里简单地使用值为 noreferrer 的 rel 属性来禁止浏览器向链接目标发送 HTTP_REFERRER header。例如:
<a href="http://evil.com" rel="noreferrer">Evil</a>
当用户点击这个链接访问 evil.com 时,对方只会收到一个空白的 HTTP_REFERRER header。在 Windows 版的 Chrome 4.0.295.0 dev 上测试通过。
Firefox
Firefox 的扩展 Adaptive Referer Remover 可以禁止指定的 URL 出现在 HTTP_REFERRER header 里。它使用正则表达式来匹配要保护的 URL。普通的 URL 转换成它需要的正则表达式很简单,只需要在前面加 ^ 并把 . 改成 . 即可。例如:
^http://rainux.org
^http://search\.twitter\.com
另一个更简单但比较极端的做法是在 about:config 里将 network.http.sendRefererHeader 设置为 0,这样会完全禁止 Firefox 向任何网站发送 HTTP_REFERRER header。
Opera
Tools-> Preferences-> Advanced-> Network-> Send referrer information 去掉勾选。(感谢 vvoody 补充)
Internet Explorer
别开玩笑了,IE 的漏洞都导致 Google 重要服务被攻破 而被迫退出中国了,你还敢用它?
标签:Twitter使用 Function.apply.apply() 为 IE 里的原生函数添加 .apply() 方法
December 13th, 2009
IE 里有很多原生的 Javascript 函数实际上都不是一个标准的 Function 对象,例如 window.alert,window.setTimeout 以及 IE8 的 window.console.log 等。在需要对这样的函数进行包装的时候,会因为它们都没有 Function 对象应该有的 .apply() 及 .call() 方法而难以做到。
这段代码为了兼容旧版本没有 console 的浏览器,尝试将 console.log 包装为 $.log,但是基于上述原因它在 IE 里无法执行。
$ = {};
if (console && console.log) {
$.log = function() {
console.log.apply(console, arguments);
};
} else {
$.log = function() {};
}
由于 window 和 console 这样的原生对象都是只读的,所以无法使用类似这样的代码简单地为其添加 .apply() 方法。
console.log.apply = Function.apply;
解决办法是使用 Function.apply.apply() 将 Function.apply 函数对象 apply 到 console.log 上。
$ = {};
if (console && console.log) {
$.log = function() {
Function.apply.apply(console.log, [console, arguments]);
};
} else {
$.log = function() {};
}
这段代码和第一段代码完全等价。
如果觉得不容易理解,可以看看这个 .apply() 函数比较清晰的例子。这两行代码也完全等价。
[1, 2, 3, 4].slice(0, 2); Array.prototype.slice.apply([1, 2, 3, 4], [0, 2]);标签:Javascript
六月真是个好时节啊
June 5th, 2008
Ruby 1.8.7 和 Rails 2.1.0 前两天相继发布。Firefox 3.0 昨天进入 rc2 阶段,并且将在六月中旬发布 3.0 正式版。开发了十五年的 Wine 终于进入 1.0 的 rc 阶段,并且即将发布 1.0 正式版。
看来是时候更新 SCV Selector 了,可惜预想了很久的 rep 版本识别还是没有时间去研究……
标签:Software_软件, Web_Development_织网