Testing rails cancan abilities with rspec
Simple template for testing cancan abilities in rails project using rspec goodness
shared_examples "guest" do
it { expect(user).to have_ability([:show, :index], for: User) }
end
shared_examples "user" do
it { expect(user).to have_ability(:edit, for: user) }
end
describe "Abilities" do
describe "Guest" do
let(:user) { nil}
it_behaves_like "guest"
end
describe "User" do
let(:user) { Fabricate(:user) }
it_behaves_like "guest"
it_behaves_like "user"
end
end
Written by sergey kuchmistov
Related protips
1 Response
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/68761/0e8a012c6542299bec2bc94922a3ed27.jpeg)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#