Closed nagaharish closed 9 years ago
Your controller will have current_ability as implemented by cancan(can) so that's where you'd stub. But I'd first say you shouldn't be stubbing an integration test :)
Hi Thank you. I actually don't wanted to change it dynamically always. The behavior might change every month depending on the market requirements. So that point of time we will change it in the app/abilities then the problem will be solved. The idea is that point of time we don't wanted to start fixing the test cases again.
Hence we wanted to stub it so all the test cases will be fine.
I hope this clarifies my question.
Then you'll need to mock and stub the current_ability in the controller.
Hi, I am having a code like can? :access, :project in my views. Based on that I am showing the link. So that is defined in the abilities file as usual which is working fine.
i.e., eg: app/abilities/admin.rb I am using can :access, :project
app/abilities/employee.rb I am using cannot :access, :project
Now I wanted to test in the following way in cucumber with the help of step_definition:
So this means I wanted to dynamically change the ability and ensure the test pass. How DO I do this? I have done something like this which is not working.
@user.ability.stub(:can?).with(:access, :project).and_return(false)
The reason behind this is tomorrow we might change employee ability also to can :access, :project hence i want this dynamic behavior.