-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to mock a current_user in rspec? #16
Comments
If you look at the helper you'd see that you could provide the presenter instance yourself. What sort of test are you writing? For what object, in what context, and what is the goal of the test? |
@Spaceghost , if you look at my example method. There is a variable |
The context and environment of the test you're writing matters greatly
here. Is this a "controller test"? Is it "integration"? "feature"?
This must be answered in order to know how to provide the alternate to
the context.
Can you post the full test file and name if I've continued to poorly
communicate?
~Spaceghost
…On Tue, Mar 20, 2018 at 12:17 AM, Ken ***@***.***> wrote:
@Spaceghost , if you look at my example method. There is a variable
current_user from controller helper. How can I assign current_user a value
when running rspec?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Given a class TestPresenter < Keynote::Presenter
presents :test
def get_current_user
current_user
end
end Please be noted, the current_user is defined in # frozen_string_literal: true
RSpec.describe TestPresenter do
subject { k(test) }
let(:test) { create(:test) }
describe '#get_current_user' do
it 'returns current_user' do
expect(subject.get_current_user).to eq(user)
end
end
end If you run the above rspec directly, it prompts error |
In this case, you need to stub the `#current_user` method or mock the
receiver of `#current_user`
~Johnneylee
…On Mon, Aug 20, 2018 at 2:53 PM Ivan Joukov ***@***.***> wrote:
@gamesover <https://github.com/gamesover> having this exact problem, did
you figure it out?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/rf-/keynote/issues/16#issuecomment-414475676>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAPV6obBHgo_ZoSSgkDZg9RmxzutRaXRks5uSy_CgaJpZM4Sra5J>
.
|
If in keynote presenter, current_user is included.
In rspec, I don't know how to mock this
current_user
variable.allow(presenter).to receive(:current_user).and_return(user)
does not work and rspec saidpresenter
is not defined.Could you please show me an example?
Thanks.
The text was updated successfully, but these errors were encountered: