ruby on rails - Rspec + Cancan error -


admin_spec.rb

it "checks access user"   visit rails_admin_path   login(:user) #helper method   expect(page).to raise_error(cancan::accessdenied) end 

console output

failure/error: login(:user) cancan::accessdenied:   not authorized access page. 

but test still red. why , how fix it?

have taken @ article?

testing abilities in cancan

instead of visiting url, maybe can use can? method determine if :user allowed visit rails admin path.

i'm assuming you're using devise? if so, found other article may helpful. suggest including block allow devise test helpers.

alternatively, switch cancancan (that's use) , works easier (since cancan no longer supported):

  context 'sign_in'     scenario 'with valid information should redirect administration dashboard', :js => true       sign_in_with sign_in_url, registered_user.email, 'validpassword', 'admin_user'        expect(page).to have_content('site administration')     end      scenario 'with invalid information', :js => true       sign_in_with sign_in_url, registered_user.email, 'invalidvalidpassword', 'admin_user'       expect(page).to have_content('invalid email or password')     end   end 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -