有人可以帮我为以下代码创建模拟。我想通过以下名称在现有控制器中添加一个控制器方法,并希望将其行为测试到包含标题、导演、评级等作为表实例的电影类。不幸的是,我不熟悉在这里使用的 BDD 命令。
describe MoviesController do
describe "#find_same_director" do
before :each do
fake_movies = [mock('movie1'), mock('movie2')]
end
context "with invalid attributes" do
it "flashes no such director message" do
flash[:notice].should_not be_nil
end
it "redirects to the index method" do
response.should redirect_to movies_path
end
end
context "with valid attributes" do
it "calls model method to find all movies" do
movie = Movie.find_with_director, {:director => 'George Lucas'}
get :show, id: @fake_movies
assigns(:movie).should eq(@fake_results)
end
it "renders the #find_same_director view" do
get :find_same_director, id: @fake_movies
response.should render_template :find_same_director
end
end
end
end