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 collaboratorPlaying multiple roles
- Background
-
- Given
-
a file named "spec/spec_helper.rb" with:
require 'rspec/role-mocks' $LOAD_PATH.unshift('lib')
- And
-
a file named "spec/roles/logger.rb" with:
RSpec.define_role 'Logger' do def log(message); end end
- And
-
a file named "spec/roles/writer.rb" with:
RSpec.define_role 'Writer' do def write(message, opts); end end
- And
-
a file named "spec/console_logger_spec.rb" with:
require 'spec_helper' require 'console_logger' require 'roles/logger' require 'roles/writer' describe ConsoleLogger do it_plays_role 'Logger' it_plays_role 'Writer' end
- Scenarios
-
- Object plays all the roles
-
- Given
-
a file named "lib/console_logger.rb" with:
class ConsoleLogger def log(message); end def write(message, opts); end end
- When
-
I run
rspec spec/console_logger_spec.rb
- Then
- the example should pass
- Object does not play all the roles
-
- Given
-
a file named "lib/console_logger.rb" with:
class ConsoleLogger def not_log(message); end def not_write(message); end end
- When
-
I run
rspec spec/console_logger_spec.rb
- Then
- the example should fail
- And
-
the output should contain:
ConsoleLogger does not play role "Logger" as expected
- And
-
the output should contain:
ConsoleLogger does not play role "Writer" as expected
Last published over 7 years ago by treppo.