Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9204053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:36:54+00:00 2026-06-17T23:36:54+00:00

Been chugging along learning Rspec, Capybara, and FactoryGirl as per Ryan Bates’ How I

  • 0

Been chugging along learning Rspec, Capybara, and FactoryGirl as per Ryan Bates’ “How I Test” railscast and hit a snag. My app uses Devise for authentication and CanCan for authorization. I’d like to test to make sure that an user can delete their own posts, but not the posts of other users, but I can’t seem to make the deletion happen. I’ve read about how I should use “controller tests” for this, but googling hasn’t shed much light on what the difference is between that and my integration tests and how I might go that route.

Here’s my code and, below it, the result:

Factories:

  2 FactoryGirl.define do
  3   factory :role do
  4     factory :admin_role do
  5      name 'admin'
  6     end
  7 
  8     factory :author_role do
  9       name 'author'
 10     end
...
 17   sequence(:name) { |n| "Joe User #{n}"}
 18   sequence(:email) { |n| "joeuser+user#{n}@example.com"}
 19 
 20   factory :user do
 21     name
 22     email
 23     password 'secret'
 24 
 25     factory :admin, :class => User do
 26       name
 27       email
 28       after_create { |user| user.roles << FactoryGirl.create(:admin_role) }
 29     end
 30 
 31     factory :author , :class => User do
 32       name
 33       email
 34       after_create { |user| user.roles << FactoryGirl.create(:author_role) }
 35     end
 36   end
 37 
 38   sequence(:title) { |n| "Post Title #{n}"}
 39   sequence(:body) { |n| "The inner post body #{n}"}
 40 
 41   factory :post do
 42     title
 43     body
 44   end
 45 
 46 end

posts_spec.rb:

  1 require 'spec_helper'                                                                                                                                                                                   
  2 
  3 def login(user)
  4   visit new_user_session_path
  5   fill_in "Email", :with => user.email
  6   fill_in "Password", :with => user.password
  7   click_button "Sign in"
  8   page.should have_content("Signed in successfully")
  9 end
 10 
 11 describe "Posts" do
 12   let(:author) {FactoryGirl.create(:author)}
 13   let(:author2) {FactoryGirl.create(:author)}
 14   let(:user) {FactoryGirl.create(:user)}
 15   let(:admin) {FactoryGirl.create(:admin)}
 16   let(:post) { FactoryGirl.create(:post, user: author) }
...
 99   describe "destroy /post/:id" do
100     it "should allow the author to destroy post" do
101       login(author)
102 
103       visit post_path(post, :method => :delete)
104       lambda {
105         visit post_path(post)                                                                                                                                                                           
106       }.should raise_exception(ActiveRecord::RecordNotFound)
107     end
108   end
109 end

Results from guard:

Running: spec/requests/posts_spec.rb
........F

Failures:

  1) Posts destroy /post/:id should allow the author to destroy post
     Failure/Error: lambda {
       expected ActiveRecord::RecordNotFound but nothing was raised
     # ./spec/requests/posts_spec.rb:104:in `block (3 levels) in <top (required)>'

When I actually save_and_open_page (using launchy) I see that the post hasn’t been deleted. Any thoughts on how I should best do this? Thanks much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:36:55+00:00Added an answer on June 17, 2026 at 11:36 pm

    Thank you, railscard, for the solution:

    Are you really want to test abilities via Capybara? There is a solution about testing CanCan: github.com/ryanb/cancan/wiki/Testing-Abilities

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My web app has been chugging along just great in Production for years with
So far I've been chugging along with Parcelable objects without issue, mainly because all
I've been chugging along OK with the use of data annotations made on buddy
I've been programming a new iPhone application and everything has been chugging along fine,
My app had been chugging along fine on the Android market until last night
Ok, so I'm familiar with creating local Wordpress builds, and have been chugging along
I'm converting an old VB6 app that's been chugging along for years, but has
Been stuck on this for ages. Currently learning Django and done some bits on
Been slowly picking up the basics in IOS Programming, but seemed to have hit
Been trying to implement Rabin-Miller Strong Pseudoprime Test today. Have used Wolfram Mathworld as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.