Проверка того, что один массив хэшей содержится в другом (при этом порядок объявления ключей не важен, в отличии от использования .to eq
)
RSpec.describe [{ a: 1 , b: 2 }, { a: 2 , b: 1 }, { c: 11 , d: 22 }] do
let (:val) { [{ b: 1 , a: 2 }, { c: 11 , d: 22 }] }
it { is_expected.to include(*val) }
end
Вызов метода у subject для теста (its
выпилили из rspec 3, https://gist.github.com/myronmarston/4503509, тут можно поставить гем https://github.com/dnagir/its)
subject { described_class.new }
describe '.some_method' do
its(:some_method) { is_expected.to be_truthy }
end
Пропустить before hook для теста
before do |example|
unless example.metadata[:skip_before]
expect(attach_invoice).to receive(:update_assembly).and_call_original.once
end
end
it '', skip_before: true do
...
end
Проверить наличие полей у модели
expect(User.last).to have_attributes(name: name)
Ссылка на доку по встроенным матчерам https://relishapp.com/rspec/rspec-expectations/v/3-10/docs/built-in-matchers
not_ matcher
RSpec::Matchers.define_negated_matcher :not_change, :change
.receive.and_...
U can wrap your call with .and_wrap_original # https://rspec.info/documentation/3.6/rspec-mocks/RSpec/Mocks/MessageExpectation.html
Список всех тестов и кол-ва строк в них
find spec | grep '.rb$' | xargs wc -l | sort -n -s -k 1,1