On 8/11/07, Franck D'agostini <[EMAIL PROTECTED]> wrote: > > I'm trying to spec a Rails application using the couple > restful_authentication/acl_system2 plugins. > > In my admin layout, I put the following code : > > <% restrict_to "admin" do -%> > <ul id="admin-tabs"> > <li> /users Users management </li> > </ul> > <% end -%> >
Remember, rSpec is Behavioural. The code behind "restrict_to" doesn't matter; it's the behaviour that matters. As such, your view-spec should only know about the code in that view. So for example, there's no mention of a "user" or "role" model there, only a "restrict_to" method. Spec out the "restrict_to" code, rather than setting up a complex chain of fragile model interactions. This means that you can change the whole ACL system, but as long as it conforms to the same interface, restrict_to("rolename"), your specs will suceed. You can also change the associations or the name of your models, or add some fancy caching, anything, and this particular spec won't die. > User.should_receive(:find_by_id).any_number_of_times.and_return(@current_user) > request.session[:user] = @current_user The fact that you're stubbing "find" calls in the *view* spec indicates that you're probably testing things that are out of the scope of that spec. The actual ACL system should be tested on its own, not in the context of a view. Courtenay _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users