我一直堅持用這樣的一段時間,我一直在尋找,但我無法弄清楚,爲什麼我的代碼不工作...無法填充數據庫運行黃瓜場景
我學習Cucumber,我必須填充數據庫來運行場景。
這些都說明:
(......),你將創建一個步驟定義,將匹配在這兩個
sort_movie_list.feature
和filter_movie_list.feature
的Background
部分步驟Given the following movies exist
。 (後來在 過程中,我們將介紹如何幹出重複Background
部分在兩個特徵文件。)加入你的代碼中
movie_steps.rb
步驟定義文件。你可以用 只使用ActiveRecord調用來直接添加電影到數據庫; 可以繞過與創建新電影相關的GUI,因爲 這不是這些場景正在測試的。
的*.feature
文件的這一個
特點:由MPAA分級過濾的電影的顯示列表
As a concerned parent
So that I can quickly browse movies appropriate for my family
I want to see movies matching only certain MPAA ratings
Background: movies have been added to database
Given the following movies exist:
| title | rating | release_date |
| Aladdin | G | 25-Nov-1992 |
| The Terminator | R | 26-Oct-1984 |
| When Harry Met Sally | R | 21-Jul-1989 |
| The Help | PG-13 | 10-Aug-2011 |
| Chocolat | PG-13 | 5-Jan-2001 |
| Amelie | R | 25-Apr-2001 |
| 2001: A Space Odyssey | G | 6-Apr-1968 |
| The Incredibles | PG | 5-Nov-2004 |
| Raiders of the Lost Ark | PG | 12-Jun-1981 |
| Chicken Run | G | 21-Jun-2000 |
所以這是從*_steps.rb
我的代碼:
Given /the following movies exist/ do |movies_table|
movies_table.hashes.each do |movie|
Movie.create!(movie)
end
fail "Unimplemented"
end
這是我得到的錯誤:
Background: movies have been added to database # features/sort_movie_list.feature:7
Given the following movies exist: # features/step_definitions/movie_steps.rb:3
| title | rating | release_date |
| Aladdin | G | 25-Nov-1992 |
| The Terminator | R | 26-Oct-1984 |
| When Harry Met Sally | R | 21-Jul-1989 |
| The Help | PG-13 | 10-Aug-2011 |
| Chocolat | PG-13 | 5-Jan-2001 |
| Amelie | R | 25-Apr-2001 |
| 2001: A Space Odyssey | G | 6-Apr-1968 |
| The Incredibles | PG | 5-Nov-2004 |
| Raiders of the Lost Ark | PG | 12-Jun-1981 |
| Chicken Run | G | 21-Jun-2000 |
Unimplemented (RuntimeError)
./features/step_definitions/movie_steps.rb:7:in `/the following movies exist/'
features/sort_movie_list.feature:9:in `Given the following movies exist:'
我試過movie = Movie.create!, Movie.create!(movie), Movie.create! movie, movie = Movie.create!
(這最後一個只是純粹的絕望)......我做錯了什麼?
在先進的感謝:)
我的錢是在你的正則表達式中錯過的冒號(':')。 –
什麼正則表達式? '電影'是一個代表散列的變量 – cerealCode
你有步驟「鑑於以下電影存在:」,然後嘗試將它與「給定/以下電影存在/電影_table |」匹配。你用來匹配步驟定義的正則表達式中的':'在哪裏? –