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 7715753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:27:59+00:00 2026-06-01T02:27:59+00:00

I can’t seem to get these Rspec tests to pass. I just don’t know

  • 0

I can’t seem to get these Rspec tests to pass. I just don’t know what exactly I’m doing wrong. Any advice? These tests make sure that every hunt has an edit and delete link when admins are logged in. I’m using FactoryGirl to generate a test admin user and a test hunt.

Here are the tests.

    describe "for users who are admins" do
      before(:each) do
        admin = FactoryGirl.create(:user, :email => "admin@example.com", :admin => true)
        test_sign_in(admin)
      end

    it "should show edit link" do
      get 'index'
      Hunt.each do |hunt|
        response.should have_selector('a', :href => "edit",
                                       :content => "edit")    
      end
    end

    it "should show delete link" do
      get 'index'
      Hunt.each do |hunt|
        response.should have_selector('a', :href => "delete"  ,
                                       :content => "delete")  
      end
    end

Here’s the code I’m testing. It’s from views/hunts.html.erb

    <h1>All Hunts</h1>

    <%= will_paginate %>

    <ul>
      <% @hunts.each do |hunt| %>
            <li>
          <%= link_to hunt.name, hunt %>
          <% if current_user && current_user.admin? %>
            | <%= link_to "edit", edit_hunt_path(hunt) %>
            | <%= link_to "delete", hunt, :method => :delete, :confirm => "You   
                          sure?",  :title => "Delete #{hunt.name}" %>


          <% end %>
        </li>
      <% end %>
    </ul>
    <%= will_paginate %>

    <%= link_to( "Create New Hunt", '/hunts/new') %>  

And here’s the relevant part of the hunt controller.

class HuntsController < ApplicationController

  def index
     @title = "All Hunts"
     @hunts = Hunt.paginate(:page => params[:page])
  end

    ....
end

When I run rspec, this is what appears.

    </li>
            <li>
      <a href="/hunts/30">---
   - optio
   - et
   - sunt
   </a>
        | <a href="/hunts/30/edit">edit</a>
        | <a href="/hunts/30" data-confirm="You sure?" data-method="delete" rel="nofollow" title="Delete ---
   - optio
   - et
   - sunt
   ">delete</a>

Finally, here’s my factories.rb file.

FactoryGirl.define do
  factory :user do
    sequence(:name)  { |n| "Person #{n}" }
    sequence(:email) { |n| "person_#{n}@example.com"}   
    password "foobar"
    password_confirmation "foobar"

    factory :admin do
      admin true
    end
  end

  factory :hunt do
    name "Test Hunt" 
  end
end         

UPDATE: So I dropped the “a” from the original tests. I also rewrote the test so that it looks at each hunt on page 1.

      describe "for users who are admins" do
        before(:each) do
            admin = FactoryGirl.create(:user, :email => "admin@example.com", :admin => true)
            test_sign_in(admin)
        end

        it "should show edit link" do
          get 'index'
          Hunt.paginate(:page => 1).each do |hunt|
            response.should have_selector(:href => "edit",
                                           :content => "edit")
          end 
        end

        it "should show delete link" do
          get 'index'
          Hunt.paginate(:page => 1).each do |hunt|
            response.should have_selector(:href => "delete",
                                           :content => "delete")  
          end
        end
      end 

So now I’ve got a different error:

HuntsController GET 'index' for users who are admins should show edit link
 Failure/Error: response.should have_selector(:href => "edit",
 Nokogiri::CSS::SyntaxError:
   unexpected '{' after ''

I tried googling this error, but haven’t had much luck. Seen it before? I’m not sure what syntax I’m messing up.

  • 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-01T02:28:00+00:00Added an answer on June 1, 2026 at 2:28 am

    What if you change the selector to the following:

    it "should show an 'edit' link" do
      get :index
      ...
      response.should have_selector('a', :href => edit_hunt_path(hunt), :content => 'edit')
      ...
    end
    

    If you are using Capybara then you can simply use have_link() instead of have_selector().

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

Sidebar

Related Questions

Can't get Youtube's homepage, or any other youtube.com prefixed URL to load in an
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can i get the source code for a WAMP stack installer somewhere? Any help
can any one tell me how can change this java code into objective c.is
Can someone guide me on a possible solution? I don't want to use /bin/cp
Can somebody tell me how to get mod_rewrite to rename this: our-work-section.php?id=3&title=something to our-work-section/something/3
Can someone help me understand why Win32 error codes don't match method signatures and
Can I set a maximum fps? Is there any way to limit fps in
Can some one Guide me to work with these things... What is Model popup
Does anyone know how can I replace this 2 symbol below from the string

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.