使用cucumber配合pickle

January 27, 2011

建立项目

1
$ rails -d mysql order test

添加脚手架

1
$ ruby script/generate scaffold books title:string

创建数据库,建表

修改BooksController#index

BooksController#index
1
@books = Book.find(:all,:order => "title DESC")

在项目下加载cucumber与capybara

1
$ ruby script/generate cucumber --capybara

添加pickle(path可选,加上之后会在paths.rb里面增加)

1
$ ruby script/generate pickle path

在相应books_steps.rb文件里加入

books_steps.rb
1
2
3
4
5
6
7
Then /^我应该(?:在"([^"]*)"中)?依次看到:$/ do |selector, table|
  pattern = table.raw.flatten.collect(&Regexp.method(:quote)).join('.*?')
  regexp = Regexp.compile(pattern, Regexp::MULTILINE)
  with_scope(selector) do
    page.should have_xpath('//*', :text => regexp)
  end
end

在feature中加入

1
2
3
4
5
6
7
8
9
10
11
12
Scenario: books in order
Given the following books exist
  | title   | id |
  | aaa  | 1  |
  | bbb  | 2  |
  | ccc   | 3  |
When I go to books
Then I should see in that order:
  | ccc    |
  | bbb    | 
  | aaa    | 
And I should see "aaa" 

在paths.rb中加入

path.rb
1
2
when /books/
  books_path

运行

1
$ rake cucumber:all

等着看黄瓜变绿~~

在ActiveAdmin下自定义filter

rails4之后,之前的`model`里加入`search_methods :filter_name`的做法已经失效,需修改为:``` ruby class PromoCode (ids) { with_tags(ids) } def self. …… Continue reading

Mac上搭建Phonegap环境

Published on October 02, 2014

Rails遗留程序里最常犯的错误(译)

Published on July 23, 2014