Skip to content

Instantly share code, notes, and snippets.

@frostmark
Last active August 16, 2017 20:26
Show Gist options
  • Save frostmark/af4f8cb079fb4c496e28afe2aacc0731 to your computer and use it in GitHub Desktop.
Save frostmark/af4f8cb079fb4c496e28afe2aacc0731 to your computer and use it in GitHub Desktop.
testing modules in isolated
require 'rails_helper'
describe Policy do
let!(:user) { create :user }
let(:other_user) { create :user }
# создаем класс
class PolicyClass
# подключаем модуль который необходимо протестировать
include Policy
# добавляем пустой метод
def user
end
end
describe '#can_destroy?' do
policy = PolicyClass.new
it 'return true' do
allow(policy).to receive(:user) { user }
expect(policy.can_destroy?(user)).to be true
end
it 'return false' do
allow(policy).to receive(:user) { user }
expect(policy.can_destroy?(other_user)).to be false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment