Last active
December 9, 2021 04:45
-
-
Save billyyarosh/9eaa4df6da3af21c1ba85cde19dbd49a to your computer and use it in GitHub Desktop.
Song Service Spec with Double
This file contains hidden or 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
RSpec.describe SongService do | |
require 'spec_helper' | |
subject { SongService.new(gateway_service: gateway_service) } | |
let(:song) { Song.new(name: 'Seek Up', artist: 'Dave Matthews Band', genre: 'Rock') } | |
context 'using doubles' do | |
let(:gateway_service) do | |
stub = double("gateway_service") | |
allow(stub).to receive(:create_song) do | |
Song.new(name: song.name, artist: song.artist, genre: song.genre, id: 'abc').to_json | |
end | |
stub | |
end | |
it 'creates a valid song' do | |
new_song = subject.create_song(song) | |
expect(new_song.name).to eq song.name | |
expect(new_song.artist).to eq song.artist | |
expect(new_song.genre).to eq song.genre | |
expect(new_song.id).to_not be_nil | |
expect(new_song.id).to_not eq song.id | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment