Topic: We don't understand what controller tests do or should do
Hi Newbie rails programmer is trying to get a handle on testing with rspec. I have the code below which it turns out passes even if there is no edit method in the controller. Obviously something is wrong. (The code came from someone else's example) What should we be testing in an edit controller test and how? Any help gratefully appreciated. regards dukha
describe CoursesController do
sign_in_user
def mock_course(stubs={})
@mock_course ||= mock_model(Course, stubs).as_null_object
end
describe "GET index current_user.current_organisation.accessible_courses" do
it "assigns all courses as @courses" do
Course.stub(:all) { [mock_course] }
pending 'how to stub current_user.current_organisation.accessible_courses ?'
get :index
assigns(:courses).should eq([mock_course])
end
end
describe "GET show" do
pending 'show not used'
it "assigns the requested course as @course" do
Course.stub(:find).with("37") { mock_course }
get :show, :id => "37", :locale => "en"
assigns(:course).should be(mock_course)
end
end
describe "GET new" do
it "assigns a new course as @course" do
Course.stub(:new) { mock_course }
get :new, :locale => "en"
assigns(:course).should be(mock_course)
end
end
describe "GET edit" do
it "assigns the requested course as @course" do
Course.stub(:find).with("37") { mock_course }
get :edit, :id => "37", :locale => "en"
puts "+++++++++++++++"
assigns(:course).should equal(mock_course)
end
end