Skip to content
Browse files

Added rspec/expectations to be able to use the 'should' assertion

Completed the 'Select all ratings' scenario for rottenpotatoes
  • Loading branch information...
1 parent 33dfcd4 commit f543c7221e14216c5dbac78463eca20575c8592e @chinpira committed Aug 27, 2012
View
1 Gemfile
@@ -14,6 +14,7 @@ group :development, :test do
gem 'database_cleaner'
gem 'capybara'
gem 'launchy'
+ gem 'rspec-expectations', "~> 2.6.0"
end
group :production do
# gem 'pg'
View
3 Gemfile.lock
@@ -120,6 +120,8 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
@@ -175,6 +177,7 @@ DEPENDENCIES
jquery-rails
launchy
rails (= 3.1.0)
+ rspec-expectations (~> 2.6.0)
ruby-debug19
sass-rails (~> 3.1.0)
sqlite3
View
BIN db/development.sqlite3
Binary file not shown.
View
23 features/filter_movie_list.feature
@@ -23,13 +23,34 @@ Background: movies have been added to database
Scenario: restrict to movies with 'PG' or 'R' ratings
# enter step(s) to check the 'PG' and 'R' checkboxes
+ When I check the following ratings: PG R
+
# enter step(s) to uncheck all other checkboxes
+ And I uncheck the following ratings: G PG-13 NC-17
+
# enter step to "submit" the search form on the homepage
+ And I press "ratings_submit"
+
# enter step(s) to ensure that PG and R movies are visible
+ Then I should see "The Terminator"
+ And I should see "When Harry Met Sally"
+ And I should see "Amelie"
+ And I should see "The Incredibles"
+ And I should see "Raiders of the Lost Ark"
+
# enter step(s) to ensure that other movies are not visible
+ And I should not see "Aladdin"
+ And I should not see "The Help"
+ And I should not see "Chocolat"
+ And I should not see "2001: A Space Odyssey"
+ And I should not see "Chicken Run"
Scenario: no ratings selected
# see assignment
-
+
+
Scenario: all ratings selected
# see assignment
+ When I check all of the ratings
+ And I press "ratings_submit"
+ Then I should see all of the movies
View
31 features/step_definitions/movie_steps.rb
@@ -4,8 +4,11 @@
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.
+ #Movie.where(:title => movie[:title], :rating => movie[:rating], :release_date => movie[:release_date]).first_or_create
+ #puts movie
+ Movie.create(movie)
end
- flunk "Unimplemented"
+ #flunk "Unimplemented"
end
# Make sure that one string (regexp) occurs before or after another one
@@ -25,4 +28,30 @@
# 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
+ ratings_to_modify = rating_list.split(%r{[,\s]+})
+ if uncheck.nil?
+ puts "uncheck is not nil"
+ ratings_to_modify.each do |rating|
+ check("ratings_" + rating)
+ end
+ else
+ puts "uncheck is nil"
+ ratings_to_modify.each do |rating|
+ uncheck("ratings_" + rating)
+ end
+ end
+end
+
+When /I check all of the ratings/ do
+ ratings_list = Movie.all_ratings
+ ratings_list.each do |rating|
+ puts "Checking rating: ratings_" + rating
+ check("ratings_" + rating)
+ end
+end
+
+Then /I should see all of the movies/ do
+ movie_count = Movie.count(:title)
+ puts "Total number of movies in database: #{movie_count}"
+ (page.all("table#movies tr").count - 1).should == movie_count
end
View
3 features/support/env.rb
@@ -6,6 +6,9 @@
require 'cucumber/rails'
+# Added this line 8/27/12 to deal with "undefined method 'should'" when running cucumber tests
+require 'rspec/expectations'
+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your

0 comments on commit f543c72

Please sign in to comment.
Something went wrong with that request. Please try again.