[rspec-users] Specing based on user roles

Fernando Perez lists at ruby-forum.com
Tue Nov 11 17:24:10 EST 2008


> I've really moved away from shared example groups and started writing
> more targeted macros. So I might do something like this:
> 
> def for_roles *roles
>   roles.each do |role|
>     before(:each) { login_as role }
>     yield
>   end
> end
> 
> describe OrdersController do
>   describe "GET index" do
>     for_roles :admin, :sysadmin do |role|
>       it "..." do ... end
>     end
>     for_roles :sysadmin do |role|
>       it "..." do ... end
>     end
>   end
> 
>   describe "GET edit" do
>     for_roles :admin, :sysadmin do |role|
>       it "..." do ... end
>     end
>     for_roles :sysadmin do |role|
>       it "..." do ... end
>     end
>   end
> end
> 

I can't write my specs so that they work as expected. What does login_as 
look like? And where do you put this code? I am not sure mine (if 
working) gets initialized correctly.

I think I have to write my specs from scratch.
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list