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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:10:31+00:00 2026-06-05T18:10:31+00:00

I might have a flawed understanding of what shared_examples_for should do, but hear me

  • 0

I might have a flawed understanding of what shared_examples_for should do, but hear me out.

Basically, I have a common navigation bar that appears in index page and new page of Forum. So I want tests for navigation bar to perform for both index page and new page. I was hoping that code below using shared_examples_for would accomplish that. But what happened was that, test cases in shared_examples_for simply is not running. To check I created failing test case within the shared_examples_for scope, but the tests didn’t fail.

What am I doing wrong?

require 'spec_helper'

describe "Forums" do

  subject { page }

  shared_examples_for "all forum pages" do

    describe "should have navigation header" do
      it { should have_selector('nav ul li a', text:'Home') }
      it { should have_selector('nav ul li a', text:'About') }
    end
  end

  describe "Index forum page" do
    before { visit root_path }
    ...
  end

  describe "New forum page" do
    before { visit new_forum_path }
    ...
  end

end
  • 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-05T18:10:33+00:00Added an answer on June 5, 2026 at 6:10 pm

    Not sure what your issue is really, but how necessary is the describe block in the shared example? That’s my first stab.

    This code works for me.

    shared_examples_for 'all pages' do
      # the following two would be navs for all pages
      it { should have_selector 'h1', text: 'About' }
      it { should have_selector 'a', text: 'Songs' }
      # these would be dynamic depending on the page
      it { should have_selector('h1',    text: header) }
      it { should have_selector('title', text: full_title(title)) }
    end
    
    describe "About" do
      before { visit about_path }
    
      let(:title) {'About'}
      let(:header) {'About Site'}
    
      it_should_behave_like 'all pages'
    end
    
    describe "Songs" do 
      before { visit songs_path }
    
      let(:title) { 'Songs Title' }
      let(:header) { 'Songs' }
    
      it_should_behave_like 'all pages'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single that might have a decimal place but might not. I
I might have misunderstood the meaning of base.OnLoad(e); My understanding was that this statement
This might have very obvious solution but I'm afraid I cannot find out how
I know that this question might have been asked like 100 times, but, believe
I have an issue that (I think) might have to do with scope, but
I might have misunderstood something.. but I expected the running of a code in
this might have been answered or might be too easy, but I haven't found
I know this question might have been asked a few times already, but I
I think it might have been asked before but i was unable to find
I have a mySQL database that might have a table named jason . A

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.