Ruby on Rails

Testing Rails Applications

Unit Test

Unit tests test parts of the application in isolation. usually a unit under test is a class or module.

let(:gift) { create :gift }

describe '#find' do
  subject { described_class.find(user, Time.zone.now.to_date) }
  it { is_expected.to eq gift }
end

source

This kind if test is as direct and specific as possible.

Request Test

Request tests are end to end tests that imitate the behavior of a user.

it 'allows the user to set their preferences' do
  check 'Ruby'
  click_on 'Save and Continue'
  expect(user.languages).to eq ['Ruby']
end

source

This kind of test focuses on user flows and runs through all layers of the system sometimes even rendering javascript.


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow