0

I am trying to do some component unit tests with hyperstack and hyperspec.

The problem is that I have policies that are blocking the test from running?

For example I have a policy that only a user can look at their own orders.

But unless I really complicate the test by logging in the user (then its not really a unit test) I can't see how to override the policy.

I tried putting a different policy in before(:all) but rspec doesn't like that.

Mitch VanDuyn
  • 2,838
  • 1
  • 22
  • 29

1 Answers1

1

I'm not familiar with rspec, but you should be able to mock the user class to pretend it's logged in. (Or mock whatever object is reporting the logged in status).

For example, if you were using rr, you could do something like

any_instance_of(User) do |klass|
  stub(klass).logged_in? { true }
end

Poking around the rspec docs, it looks like you might do something like this.

allow_any_instance_of(User).to receive(:logged_in?).and_return(true)
Cereal
  • 3,699
  • 2
  • 23
  • 36
  • cool. In my case I needed to allow ApplicationController to receive :acting_user and return a user I created in my test case. But that put me on the right track! – Mitch VanDuyn Apr 12 '19 at 15:20