Я запускаю эти тесты rspec для моего контроллера:
require 'spec_helper'
describe MoviesController do
describe 'searching for similar movies' do
before :each do
@fake_movies = [mock('Movie'), mock('Movie')]
@fake_movie = FactoryGirl.build(:movie, :id => "1", :title => "Star Wars", :director => "George Lucas")
end
it 'should follow the route to the similar movies by director page' do
assert_routing('movies/1/similar', {:controller => 'movies', :action => 'similar', :id => '1'})
end
it 'should find the similar movies by director' do
Movie.should_receive(:find_by_id).with("1").and_return(@fake_movie)
Movie.should_receive(:find_by_director).with(@fake_movie.director).and_return(@fake_movies)
get :similar, {:id => "1"}
end
it 'should select the Similiar Movies template for rendering' do
Movie.should_receive(:find_by_id).with("1").and_return(@fake_movie)
Movie.should_receive(:find_by_director).with(@fake_movie.director).and_return(@fake_movies)
get :similar, {:id => "1"}
response.should render_template('similar')
end
it 'it should make the results available to the template' do
Movie.should_receive(:find_by_id).with("1").and_return(@fake_movie)
Movie.should_receive(:find_by_director).with(@fake_movie.director).and_return(@fake_movies)
get :similar, {:id => "1"}
assigns(:movies).should == @fake_results
end
end
end
Купить они терпят неудачу с этим выводом:
Failures:
1) MoviesController searching for similar movies should find the similar movies by director
Failure/Error: get :similar, {:id => "1"}
<Movie(id: integer, title: string, rating: string, description: text, release_date: datetime, created_at: datetime, updated_at: datetime, director: string) (class)> received :find_by_director with unexpected arguments
expected: ("George Lucas")
got: ()
# ./app/controllers/movies_controller.rb:62:in `similar'
# ./spec/controllers/movies_controller_spec.rb:17:in `block (3 levels) in <top (required)>'
2) MoviesController searching for similar movies should select the Similiar Movies template for rendering
Failure/Error: get :similar, {:id => "1"}
<Movie(id: integer, title: string, rating: string, description: text, release_date: datetime, created_at: datetime, updated_at: datetime, director: string) (class)> received :find_by_director with unexpected arguments
expected: ("George Lucas")
got: ()
# ./app/controllers/movies_controller.rb:62:in `similar'
# ./spec/controllers/movies_controller_spec.rb:23:in `block (3 levels) in <top (required)>'
3) MoviesController searching for similar movies it should make the results available to the template
Failure/Error: get :similar, {:id => "1"}
<Movie(id: integer, title: string, rating: string, description: text, release_date: datetime, created_at: datetime, updated_at: datetime, director: string) (class)> received :find_by_director with unexpected arguments
expected: ("George Lucas")
got: ()
# ./app/controllers/movies_controller.rb:62:in `similar'
# ./spec/controllers/movies_controller_spec.rb:30:in `block (3 levels) in <top (required)>'
Finished in 0.15517 seconds
4 examples, 3 failures
Failed examples:
rspec ./spec/controllers/movies_controller_spec.rb:14 # MoviesController searching for similar movies should find the similar movies by director
rspec ./spec/controllers/movies_controller_spec.rb:20 # MoviesController searching for similar movies should select the Similiar Movies template for rendering
rspec ./spec/controllers/movies_controller_spec.rb:27 # MoviesController searching for similar movies it should make the results available to the template
Когда это мой метод управления:
def similar
@movies = Movie.find_by_director(Movie.find_by_id(params[:id]))
end
Я не понимаю, почему эти тесты не проходят.