Rspec Flashcards
What is Rspec?
It is a testing Framework for automated tests
What does Rspec stand for?
Ruby Specifications
What is the structure of a spec?
- Given some context
- When some event occurs
- Then I expect some outcome
Given-When-Then
How is RSpec structured
- It uses ruby but has a DSL (domain specific language) meaning that it has its own way of doing things
What reasons are there to test?
- Find bugs
- Stimulates critical thinking
- Covers edge cases (like different languages)
- Exposes poorly written code
- Confidence when improving/refactoring code
- Confidence when adding features
- Confidence when upgrading related software
- Confidence during code deployments
When should you not write tests?
- Very small applications.
What makes testing easier?
By thinking in user stories
What do we want to test?
- Happy path
- Sad path
- Edge cases
- Bug fixes
What do we not want to test?
- Basic ruby
- Basic ruby on rails
- Third party APIs
- Behaviors that have been tested already
What is the difference between .rspec and .rspec-local ?
.rspec is the global configurations that are used by all the team members, .rspec-local are the local configurations on your computer. So if you want to have your own configurations that should not be shared with the other team members then you use the .rspec-local
What is the first thing you add in a spec file?
The first thing you must do is to require the file you want to test.
we want to require the file car.rb
ex
require ‘car’
what is describe used for?
describe is used to define an example group.
A good practice is to have a describe for each method
What is context?
Context is used an alias for describe these are used when you want to group the methods for a specific usecase
What is the fundamental syntax of the expectations?
expect( ).to ( )
and
expect( ).not_to ( )
What is the RSpec Hierarchy?
It is the order that we group our specs (fundamental structure)
1 Spec file = car_spec.rb 2 example group = describe 3 nested group = describe/context 4 example = it 5 expectations = expect( ).to ( )
How do you describe a class method?
describe .method do
How do you describe an instance method?
describe #method do
How do we skip over describe blocks?
You write an x in front of the describe
xdescribe ‘something
or you write skip(‘message’) inside the describe block
How do you skip specs?
You write an x in front of it
xit ‘something’
How do you mark a block as pending?
you use the word pending inside the block.
pending(‘pending message’)
What is the difference between pending and skip?
Pending still runs the code and gives failiures while skip skips the test altoghether.
How many expectations should you have for an example?
Only one