-
-
Save epidemian/d1e629b4ba9492e1250403bd324b313a to your computer and use it in GitHub Desktop.
Using RSpec mocks instead of a dynamic module and module prepend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/support/authenticated.rb | |
RSpec.shared_context "authenticated", shared_context: :metadata do | |
before do | |
allow_any_instance_of(described_class).to receive(:current_user) { current_uset } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/admin/controllers/study/create_spec.rb | |
RSpec.describe Admin::Controllers::Study::Create, type: :action do | |
let(:action) { described_class.new } | |
let(:params) { Hash[] } | |
let(:admin) { Fabricate.build(:admin) } | |
include_context "authenticated" do | |
let(:current_user) { admin } | |
end | |
it 'is successful' do | |
response = action.call(params) | |
expect(response[0]).to eq 302 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment