I've been stuck for a while with this, I've been searching but I cannot figure out why my code doesn't work...
I'm learning Cucumber, and I have to populate the db to run the scenarios.
These are the instructions:
(...) you will create a step definition that will match the step
Given the following movies exist
in theBackground
section of bothsort_movie_list.feature
andfilter_movie_list.feature
. (Later in the course, we will show how to DRY out the repeatedBackground
sections in the two feature files.)Add your code in the
movie_steps.rb
step definition file. You can just use ActiveRecord calls to directly add movies to the database; it`s OK to bypass the GUI associated with creating new movies, since that's not what these scenarios are testing.
This one of the *.feature
file
Feature: display list of movies filtered by MPAA rating
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 |
So this is my code from *_steps.rb
:
Given /the following movies exist/ do |movies_table|
movies_table.hashes.each do |movie|
Movie.create!(movie)
end
fail "Unimplemented"
end
And this is the error I get:
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:'
I have tried movie = Movie.create!, Movie.create!(movie), Movie.create! movie, movie = Movie.create!
(this last one just for pure desperation)... What am I doing wrong??
Thanks in advanced :)
答案 0 :(得分:0)
对我来说很好。
您迭代电影,然后在end
fail "Unimplemented"
之前。你会期待什么?