Topic: What is this test testing?
I attended an Engine Yard Rails training course and this is one of the tests that I they had us write. And for the life of me, I don't understand what good this test is adding. Can someone explain the value of this unit test?
require 'spec_helper'
describe HotelsController do
def mock_hotel(stubs={})
(@mock_hotel ||= mock_model(Hotel).as_null_object).tap do |hotel|
hotel.stub(stubs) unless stubs.empty?
end
end
before :each do
system("rake db:seed")
end
describe "with valid params" do
it "assigns a newly created hotel as @hotel" do
Hotel.stub(:new).with({'these' => 'params'}) { mock_hotel(:save => true) }
post :create, :hotel => {'these' => 'params'}
assigns(:hotel).should be(mock_hotel)
end
end
end