Skip to content

Instantly share code, notes, and snippets.

@themoxman
Created November 17, 2013 20:56
Show Gist options
  • Save themoxman/7518165 to your computer and use it in GitHub Desktop.
Save themoxman/7518165 to your computer and use it in GitHub Desktop.
class MoviesController < ApplicationController
def directors
Movie.find_directors(params[:id])
end
end
class Movie < ActiveRecord::Base
# should be self.find_directors
# should take a param
# example:
# def self.find_directors(movie_id)
# end
def find_directors
end
end
describe MoviesController do
describe "finding movies with the same director" do
it 'should call the model method that returns the similar movies list' do
Movie.should_receive(:find_directors).with("5")
get :directors, :id => "5"
end
end
end
# the above passes
# VS
describe MoviesController do
describe "finding movies with the same director" do
it 'should call the model method that returns the similar movies list' do
get :directors, :id => "5"
Movie.should_receive(:find_directors).with("5")
end
end
end
# the above, fails
Failures:
1) MoviesController finding movies with the same director should call the model method that returns the similar movies list
Failure/Error: get :directors, :id => "5"
NoMethodError:
undefined method `find_directors' for #<Class:0x007f8b6e42b020>
# ./app/controllers/movies_controller.rb:12:in `directors'
# ./spec/controllers/movies_controller_spec.rb:8:in `block (3 levels) in <top (required)>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment