Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. require 'rails_helper'
  2. class TestUser
  3. def speak
  4. :speak
  5. end
  6. def eat
  7. :eat
  8. end
  9. end
  10.  
  11. RSpec.describe 'Partial test doubles' do
  12. let(:user) { TestUser.new }
  13.  
  14. context 'when stubs are applied' do
  15. it 'applies test behavior for stubbed methods' do
  16. allow(user).to receive(:speak).and_return(:yell)
  17.  
  18. expect(user.speak).to eq(:yell)
  19. end
  20.  
  21. it 'skips test behavior for non stubbed methods' do
  22. allow(user).to receive(:speak).and_return(:yell)
  23.  
  24. expect(user.eat).to eq(:eat)
  25. end
  26. end
  27.  
  28. context 'when mocks are applied' do
  29. it 'applies test behavior for mocked methods' do
  30. expect(user).to receive(:speak).and_return(:yell)
  31.  
  32. expect(user.speak).to eq(:yell)
  33. end
  34.  
  35. it 'skips test behavior for non mocked methods' do
  36. expect(user).not_to receive(:speak)
  37.  
  38. expect(user.eat).to eq(:eat)
  39. end
  40. end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement