Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rails_helper'
- class TestUser
- def speak
- :speak
- end
- def eat
- :eat
- end
- end
- RSpec.describe 'Partial test doubles' do
- let(:user) { TestUser.new }
- context 'when stubs are applied' do
- it 'applies test behavior for stubbed methods' do
- allow(user).to receive(:speak).and_return(:yell)
- expect(user.speak).to eq(:yell)
- end
- it 'skips test behavior for non stubbed methods' do
- allow(user).to receive(:speak).and_return(:yell)
- expect(user.eat).to eq(:eat)
- end
- end
- context 'when mocks are applied' do
- it 'applies test behavior for mocked methods' do
- expect(user).to receive(:speak).and_return(:yell)
- expect(user.speak).to eq(:yell)
- end
- it 'skips test behavior for non mocked methods' do
- expect(user).not_to receive(:speak)
- expect(user.eat).to eq(:eat)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement