0% found this document useful (0 votes)
16 views10 pages

RSpec

Uploaded by

Matias Manara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views10 pages

RSpec

Uploaded by

Matias Manara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Testing

RSpec

https://rspec.info/
Behaviour Driven Development for Ruby.
Making TDD Productive and Fun.

https://blog.softtek.com/es/implementando-bdd-con-cucumber
Testing Pyramid

Determine if the requirements of a speci cation or contract are met.


Acceptance Tests UI, UX, E2E

Software modules are combined and tested as a group.


Integration Tests API Testing, System Testing.

Unit Tests Automated testing of isolated modules


fi
Unit Testing
A unit test is a piece of code (usually a method) that invokes another piece
of code and checks the correctness

• Isolated

• Method level

• Smallest testable part

• Automated

• Repeatable
AAA PATTERN

def validate
# Arrange
calculator = Calculator.new()

# Act
result = calculator.sum(2, 3)

# Assert
expect(result).to eq(5)
RSpec
RSpec as TDD
$ rspec spec/burger_spec.rb

RSpec.describe Burger do class Burger


it 'should be with ketchup' do def initialize(ingredients = {})
burger = Burger.new(ketchup: true) @ingredients = ingredients
expect(burger).to be_with_ketchup end
end
def with_ketchup?
it 'should be without ketchup' do @ingredients[:ketchup]
burger = Burger.new(ketchup: false) end
expect(burger).not_to be_with_ketchup end
end
end
RSpec
def validate
# Arrange
question = Question.create(description: ‘What’s the answer?’)
option1 = Option.create(
description: ‘1’,
question_id: question.id,
correct: false
)

option2 = Option.create(
description: ‘1’,
question_id: question.id,
correct: true
)

user = user.create(name: ‘testuser’)

# Act
answer = Answer.new(
question: question.id,
user: user.id,
option: 3)

# Assert
expect(answer.correct).to eq(true)

You might also like