Skip to content

Instantly share code, notes, and snippets.

@JonKernPA
Created August 5, 2014 01:21
Show Gist options
  • Save JonKernPA/7c53d5653600178cbdd7 to your computer and use it in GitHub Desktop.
Save JonKernPA/7c53d5653600178cbdd7 to your computer and use it in GitHub Desktop.
spec helper and test for flix project
require 'spec_helper'
describe "Viewing the list of movies" do
it "shows the movies" do
movie1 = Movie.create(title: "Iron Man",
rating: "PG-13",
total_gross: 318412101.00,
description: "Tony Stark builds an armored suit to fight the throes of evil",
released_on: "2008-05-02",
cast: "Robert Downey Jr., Gwyneth Paltrow and Terrence Howard",
director: "Jon Favreau",
duration: "126 min",
image_file_name: "ironman.jpg")
movie2 = Movie.create(title: "Superman",
rating: "PG",
total_gross: 134218018.00,
description: "Clark Kent grows up to be the greatest super-hero",
released_on: "1978-12-15",
cast: "Christopher Reeve, Margot Kidder and Gene Hackman",
director: "Richard Donner",
duration: "143 min",
image_file_name: "superman.jpg")
movie3 = Movie.create(title: "Spider-Man",
rating: "PG-13",
total_gross: 403706375.00,
description: "Peter Parker gets bit by a genetically modified spider",
released_on: "2002-05-03",
cast: "Tobey Maguire, Kirsten Dunst and Willem Dafoe",
director: "Sam Raimi",
duration: "121 min",
image_file_name: "spiderman.jpg")
visit movies_url
expect(page).to have_text(movie1.title)
expect(page).to have_text(movie2.title)
expect(page).to have_text(movie3.title)
expect(page).to have_text(movie1.rating)
expect(page).to have_text(movie1.description[0..10])
expect(page).to have_text(movie1.released_on.year)
expect(page).to have_text("$318,412,101.00")
expect(page).to have_text(movie1.cast)
expect(page).to have_text(movie1.duration)
expect(page).to have_selector("img[src$='#{movie1.image_file_name}']")
end
it "does not show a movie that hasn't yet been released" do
movie = Movie.create(movie_attributes(released_on: 1.month.from_now))
visit movies_path
expect(page).not_to have_text(movie.title)
end
end
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment