shared_examples not working with Capybara feature specs

My app has seven different roles that users can have, with seven corresponding levels of authorization to interact with company data.  This means there are A LOT of possible scenarios – for each controller and each feature, I need seven nearly identical sets of specs–one for each role.

Shared examples and the it_should_behave_like method are working well for testing the controllers (where I just use rspec).  But for the feature specs (where I also add capybara), I can’t get shared examples to work.  It returns the undefined method error for the it_should_behave_like method.

So I rewrote the feature specs to be in this style:

require 'spec_helper'

def what_auditors_see
  page.should have_selector('nav ul li', text: 'My missions')

def what_client_service_managers_do_not_see
  page.should_not have_selector('nav ul li', text: 'Accounting')

feature "Layout Template (Navigation Bar and Data Dropdown Menu)" do

  scenario "as an auditor" do
    contact = create(:contact)
    create(:role_assignment, contact: contact, role: create(:role, name: "Quality"))
    sign_in contact

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s