On Feb 23, 2012, at 9:32 AM, Tom Tom wrote: > I am following railstutorial 2nd edition and in it we have a Signin test > in our integration tests as follows: > > require 'spec_helper' > > describe "Authentication" do > > subject { page } > > describe "signin" do > before { visit signin_path } > > it { should have_selector('h2', text: 'Sign in') } > it { should have_selector('title', text: 'Sign in') } > > describe "with valid information" do > let(:employee) { FactoryGirl.create(:employee) } > before { valid_signin(employee) } > > it { should have_selector('title', text: > employee.emp_full_name) } > > it { should_not have_link('Employees', href: > employees_path) } > it { should_not have_link('Profile', href: > employee_path(employee)) } > it { should_not have_link('Settings', href: > edit_employee_path(employee)) } > it { should_not have_link('New Employee', href: > new_employee_path) } > > it { should have_link('Sign out', href: signout_path) } > > it { should_not have_link('Sign in', href: signin_path) } > end > end > end > > This test passes as shown. > > I am trying to modify the test for the case when an Employee has admin > privileges. To that end I have modified the > app/views/layouts/_header.html.erb to ensure that only employees with > admin privileges can see the four links that currently read as > 'should_not have_link'. > > FactoryGirl has the ability to create an admin user. > I have admin_employee defined in employee controller which is: > > def admin_employee > redirect_to(root_path) unless current_user.admin? > > Can someone please help me design my test so that the above test will > pass for an employee with admin privileges? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Hello, what you want is "shared examples/context": https://gist.github.com/1894922 _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users