Last active
August 16, 2017 20:26
-
-
Save frostmark/af4f8cb079fb4c496e28afe2aacc0731 to your computer and use it in GitHub Desktop.
testing modules in isolated
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
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