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
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') end def what_client_service_managers_do_not_see page.should_not have_selector('nav ul li', text: 'Accounting') end 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 what_auditors_see what_client_service_managers_do_not_see end end