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/.
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 at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersHello, what you want is "shared examples/context": https://gist.github.com/1894922
On Thu, Feb 23, 2012 at 22:45, Justin Ko <jko170 at gmail.com> wrote:> Hello, what you want is "shared examples/context": > https://gist.github.com/1894922I commented there, too. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Author, JUnit Recipes Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com Find out what others have to say about me at http://nta.gs/jbrains
On Sat, Feb 25, 2012 at 9:25 AM, J. B. Rainsberger <me at jbrains.ca> wrote:> On Thu, Feb 23, 2012 at 22:45, Justin Ko <jko170 at gmail.com> wrote: > >> Hello, what you want is "shared examples/context": >> https://gist.github.com/1894922 > > I commented there, too.I commented there as well. -- @zachdennis http://www.continuousthinking.com http://www.mutuallyhuman.com