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 的繁体中文翻译版本对类似问题有提供译注,建议参考。
该日志未加标签。很爽的 Rails CHM Documentation 2.0.2
May 30th, 2008
delynn 老兄终于发布了他的 Rails CHM Documentation 的 2.0.2 版,再也不用忍受 RailsBrain.com 那个 Rails API with the AJAX flavor 糟糕的目录结构了。
网上流传的所有 Rails 文档都是用 rdoc 从 Rails 源代码里的 RDoc 注释自动生成的,内容都完全一样。但只有这位 delynn 老兄的 Rails CHM Documentation 目录是手工整理的,按照 Module 分类,结构非常清晰。
标签:Ruby on Rails