Every time i run rspec_scaffold and look at the generated specs im shocked anew, there is just so much bla bla and so little information. I know that as a rule of thumb there should be one assertion per test, but in my opinion this is going too far. Note to self: New rule of thumb: “Test one aspect per test”. Meaning that i test ‘database interaction’ and ‘output’ (renders x + assigns y + flash z) in different tests. And when there is only simple logic (1-liner) in either of them, they may be merged.
before(:each) do @address = mock_model(Address) Address.stub!(:find).and_return([@address]) end def do_get get :index end it "should be successful" do do_get response.should be_success end it "should render index template" do do_get response.should render_template('index') end it "should find all addresses" do Address.should_receive(:find).with(:all).and_return([@address]) do_get end it "should assign the found addresses for the view" do do_get assigns[:addresses].should == [@address] end
it "should render index and assign all addresses" do Address.expects(:find).with(:all).once.returns([@address]) get :index response.should render_template('index') assigns[:addresses].should equal([@address]) end