在主文件夹.bashrc中加入一行

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

如果终端设置成以登录shell方式运行命令(Run command as login shell),则修改.bash_profile

重启终端

建立项目

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

等着看黄瓜变绿~~

简而言之,就是代码中在有使用link_to的时候 ,出现了@url


点此查看原文

If you get this error, and the error message is pointing you to a “link_to” call or something similar, then you may be using an instance variable that’s called ‘@url’ too.

This blog post did talk about the problem but it seemed limited to models only. I finally discovered that, in my case, I was using ‘@url’ in the controller for the view where I was making the ‘link_to’ call.

Long story short, if you see this error, comb through your code (models, controllers and views) for any variables that are called ‘@url’ and change them.