To add a collaborator to this project you will need to use the Relish gem to add the collaborator via a terminal command. Soon you'll be able to also add collaborators here!
More about adding a collaboratorInitialize mocks with allowed calls
- Scenarios
-
- mock allows the predefined calls and returns value
-
- Given
-
a file named "spec/roles/fetcher.rb" with:
RSpec.define_role 'Fetcher' do def fetch(id) end end
- And
-
a file named "spec/spec_helper.rb" with:
require 'rspec/role-mocks' $LOAD_PATH.unshift("lib")
- Given
-
a file named "lib/user.rb" with:
class User < Struct.new(:fetcher) def favorite_artist fetcher.fetch(1) end end
- And
-
a file named "spec/user_spec.rb" with:
require 'spec_helper' require 'user' require 'roles/fetcher' RSpec.describe User, '#suspend!' do it 'notifies the console' do expected = 'Theolonious Monk' fetcher = role_double("Fetcher", fetch: expected) user = User.new(fetcher) actual = user.favorite_artist expect(actual).to eq expected end end
- When
-
I run
rspec spec/user_spec.rb
- Then
- the example should pass
Last published over 7 years ago by treppo.