📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 5

Retour
RSpec - Hooks 'before' et 'after'
Facile
before(:each) do
  @widget = Widget.new
end
RSpec - Matcher 'eq'
Facile
expect(result).to eq(expected_value)
RSpec - Structure d'un test
Facile
RSpec.describe Calculatrice do
  it 'additionne deux nombres' do
    calc = Calculatrice.new
    expect(calc.add(2, 3)).to eq(5)
  end
end
RSpec - Tester les exceptions
Intermédiaire
expect { 1 / 0 }.to raise_error(ZeroDivisionError)
RSpec - Utilisation de 'let'
Intermédiaire
let(:widget) { Widget.new }

it 'a un nom' do
  expect(widget.name).to eq('default')
end