From ecddb76ec0c5b9ba6046dc91e83856f464d1fc14 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Fri, 27 Mar 2015 10:48:49 +0100 Subject: [PATCH] Remove README section about view specs This really isn't the place for this kind of thing. If someone wants to write a blog post about this, I'd be happy to link it in external resources. --- README.md | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/README.md b/README.md index f3247cc..7d9abfb 100644 --- a/README.md +++ b/README.md @@ -546,31 +546,6 @@ end An alternative approach to Pundit policy specs is scoping them to a user context as outlined in this [excellent post](http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/). -### View Specs - -When writing view specs, you'll notice that the policy helper is not available -and views under test that use it will fail. Thankfully, it's very easy to stub -out the policy to have it return whatever is appropriate for the spec. - -``` ruby -describe "users/show" do - before(:each) do - user = assign(:user, build_stubbed(:user)) - controller.stub(:current_user).and_return user - end - - it "renders the destroy action" do - allow(view).to receive(:policy).and_return double(edit?: false, destroy?: true) - - render - expect(rendered).to match 'Destroy' - end -end -``` - -This technique enables easy unit testing of tricky conditionaly view logic -based on what is or is not authorized. - # External Resources - [RailsApps Example Application: Pundit and Devise](https://github.com/RailsApps/rails-devise-pundit)