Commit 47a38809 authored by Tom Johnson's avatar Tom Johnson

Wrapping up

parent 504b2007
......@@ -30,7 +30,19 @@ If you have trouble with the above, please ensure the following are installed:
## Agenda
### Getting started with RSpec
The Samvera community has largely converged on using RSpec as a testing
framework. RSpec provides a DSL for rapid Test Driven Development.
Some RSpec Resources:
* [RSpec Core Documentation](https://relishapp.com/rspec/rspec-core/docs)
* [RSpec Expectations Documentation](https://relishapp.com/rspec/rspec-expectations/docs)
* [RSpec Mocks Documentation](https://relishapp.com/rspec/rspec-mocks/docs)
* [RSpec Rails Documentation](https://relishapp.com/rspec/rspec-rails/docs)
* [BetterSpecs](http://www.betterspecs.org/)
#### Your first test
Let's write an for an `Animal`. Our `Animal` will have one method `Animal#speak`. Write a _Unit Test_ for a `#speak` method with the behavior below at `spec/animal_spec.rb`; then add the implementation to make it pass.
```ruby
......@@ -44,6 +56,8 @@ class Animal
end
```
An example of a unit test for `#speak` is in the branch `exercise-1`.
> **Types of Tests**
>
> There are many (overlapping, sometimes contradictory) taxonomies of tests.
......@@ -62,9 +76,57 @@ end
> Rails-specific types found in
> [RSpec Rails](https://relishapp.com/rspec/rspec-rails/docs)
#### Integration Testing
#### Having a conversation
Let's add a simple `Conversation` class. Our `Conversation` will generate a
brief exchange between two animals using the `#chat` method. Let's write a test
for this method, then add the implementation as below:
```ruby
# lib/conversation.rb
class Conversation
attr_accessor :speakers
##
# @param [#speak] speaker_1
# @param [#speak] speaker_2
def initialize(speaker_1, speaker_2)
self.speakers = [speaker_1, speaker_2]
end
##
# @return [String]
def chat
"#{speakers[0].speak}\n#{speakers[1].speak}\n"
end
end
```
An example of a test for `#chat` is in the branch `exercise-2`.
**Discussion Topics**
* Is this a unit test, or an integration test?
* What is the purpose of the string arguments to the `describe` and `it` blocks?
* What's going on in the line beginning `subject(:conversation)`?
### Advanced RSpec
#### Test Doubles: Stubs, Mocks, Fakes
#### DRY Tests
* Testing interfaces: `shared_examples`
* Testing scenarios: `shared_context`
* [One expectation per test?!](http://www.betterspecs.org/#single)
#### Test Doubles: Stubs, Mocks, Fakes
* Real fakes
* [Mocks aren't Stubs](https://martinfowler.com/articles/mocksArentStubs.html)
* [RSpec Mock](https://relishapp.com/rspec/rspec-mocks/docs)
### Factories
* [Getting Started with FactoryBot](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md)
### Testing Samvera Applications
* https://github.com/samvera-labs/hyrax-spec
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment