Skip to content

Commit

Permalink
Add cucumber steps to test for movie sorting based on title and relea…
Browse files Browse the repository at this point in the history
…se date
  • Loading branch information
Oliver Martell committed Apr 3, 2012
1 parent 45839b7 commit 3abb45c
Show file tree
Hide file tree
Showing 16 changed files with 570 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ gem 'rails', '3.1.0'
group :development, :test do
gem 'sqlite3'
gem 'ruby-debug19', :require => 'ruby-debug'
gem 'cucumber-rails'
# database_cleaner is not required, but highly recommended
gem 'database_cleaner'
gem 'cucumber-rails-training-wheels'
gem 'database_cleaner'
gem 'capybara'
gem 'launchy'
end
group :production do
gem 'pg'
Expand All @@ -17,7 +24,7 @@ end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'therubyracer'
gem 'therubyracer'
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
Expand Down
45 changes: 45 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ GEM
activesupport (= 3.1.0)
activesupport (3.1.0)
multi_json (~> 1.0)
addressable (2.2.7)
archive-tar-minitar (0.5.2)
arel (2.2.1)
bcrypt-ruby (3.0.1)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.3.1)
ffi (~> 1.0.6)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
railties (~> 3.1.0)
Expand All @@ -42,16 +52,36 @@ GEM
execjs
coffee-script-source (1.2.0)
columnize (0.3.5)
cucumber (1.1.8)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.8.0)
json (>= 1.4.6)
term-ansicolor (>= 1.0.6)
cucumber-rails (1.3.0)
capybara (>= 1.1.2)
cucumber (>= 1.1.8)
nokogiri (>= 1.5.0)
cucumber-rails-training-wheels (1.0.0)
cucumber-rails (>= 1.1.1)
database_cleaner (0.7.1)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.2.13)
multi_json (~> 1.0)
ffi (1.0.11)
gherkin (2.8.0)
json (>= 1.4.6)
haml (3.1.4)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.3)
json_pure (1.6.5)
launchy (2.0.5)
addressable (~> 2.2.6)
libv8 (3.3.10.4)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
Expand All @@ -61,6 +91,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.0.4)
nokogiri (1.5.0)
pg (0.13.1)
polyglot (0.3.3)
rack (1.3.5)
Expand Down Expand Up @@ -100,17 +131,24 @@ GEM
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
rubyzip (0.9.6.1)
sass (3.1.12)
sass-rails (3.1.5)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (~> 3.1.10)
tilt (~> 1.3.2)
selenium-webdriver (2.13.0)
childprocess (>= 0.2.1)
ffi (~> 1.0.9)
json_pure
rubyzip
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
term-ansicolor (1.0.7)
therubyracer (0.9.9)
libv8 (~> 3.3.10)
thor (0.14.6)
Expand All @@ -122,14 +160,21 @@ GEM
uglifier (1.2.2)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
capybara
coffee-rails (~> 3.1.0)
cucumber-rails
cucumber-rails-training-wheels
database_cleaner
haml
jquery-rails
launchy
pg
rails (= 3.1.0)
ruby-debug19
Expand Down
2 changes: 1 addition & 1 deletion config/cucumber.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
Expand Down
5 changes: 4 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ development:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
test: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
Expand All @@ -23,3 +23,6 @@ production:
database: db/production.sqlite3
pool: 5
timeout: 5000

cucumber:
<<: *test
Binary file added features/.DS_Store
Binary file not shown.
35 changes: 35 additions & 0 deletions features/filter_movie_list.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 |

And I am on the RottenPotatoes home page

Scenario: restrict to movies with 'PG' or 'R' ratings
# enter step(s) to check the 'PG' and 'R' checkboxes
# enter step(s) to uncheck all other checkboxes
# enter step to "submit" the search form on the homepage
# enter step(s) to ensure that PG and R movies are visible
# enter step(s) to ensure that other movies are not visible

Scenario: no ratings selected
# see assignment

Scenario: all ratings selected
# see assignment
30 changes: 30 additions & 0 deletions features/sort_movie_list.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Feature: display list of movies sorted by different criteria

As an avid moviegoer
So that I can quickly browse movies based on my preferences
I want to see movies sorted by title or release date

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 |

And I am on the RottenPotatoes home page

Scenario: sort movies alphabetically
When I sort the movies alphabetically
Then I should see "Aladdin" before "When Harry Met Sally"

Scenario: sort movies in increasing order of release date
When I sort the movies in increasing order of release date
Then I should see "2001: A Space Odyssey" before "The Help"
Binary file added features/step_definitions/.DS_Store
Binary file not shown.
43 changes: 43 additions & 0 deletions features/step_definitions/movie_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Add a declarative step here for populating the DB with movies.

Given /the following movies exist/ do |movies_table|
movies_table.hashes.each do |movie|
# each returned element will be a hash whose key is the table header.
# you should arrange to add that movie to the database here.
title = movie[:title]
rating = movie[:rating]
release_date = movie[:release_date]
Movie.create!(title: title, rating: rating, release_date: release_date)
end
end

# Make sure that one string (regexp) occurs before or after another one
# on the same page

Then /I should see "(.*)" before "(.*)"/ do |e1, e2|
# ensure that that e1 occurs before e2.
# page.content is the entire content of the page as a string.
regexp = /#{e1}.*#{e2}.*/m
assert_match page.source, regexp
end

# Make it easier to express checking or unchecking several boxes at once
# "When I uncheck the following ratings: PG, G, R"
# "When I check the following ratings: G"

When /I (un)?check the following ratings: (.*)/ do |uncheck, rating_list|
# HINT: use String#split to split up the rating_list, then
# iterate over the ratings and reuse the "When I check..." or
# "When I uncheck..." steps in lines 89-95 of web_steps.rb
rating_list.split(" ").each do |rating|
When %{I uncheck "#{rating}"}
end
end

When /^I sort the movies alphabetically$/ do
click_link "title_header"
end

When /^I sort the movies in increasing order of release date$/ do
click_link "release_date_header"
end
Loading

0 comments on commit 3abb45c

Please sign in to comment.