require_relative '../price_entry_class.rb'
require_relative '../exceptions.rb'
require 'spec_helper'
describe PriceEntry do
it "throws expection on invalid date format" do
expect { described_class.date_from_input_to_storage("20010101") }.to raise_error(InvalidInputData)
expect { described_class.date_from_input_to_storage("zażółć") }.to raise_error(InvalidInputData)
expect { described_class.date_from_input_to_storage(nil) }.to raise_error(InvalidInputData)
expect { described_class.date_from_input_to_storage(-19_199) }.to raise_error(InvalidInputData)
end
end
Is it OK to have multiple expectations in a single Rspec test? rubocop-rspec
claims that it would be preferable to separate this test into 4:
spec/price_entry_class_spec.rb:14:2: C: Example has too many expectations [4/1].
Claim that it is always better to have single assert in every unit test is quite surprising for me. Is there a good reason to split test like this into four separate ones?
This test is testing only one thing at a time (is obviously malformed input resulting in exceptions).
I can imagine rewriting it to
["20010101", "zażółć", nil, -19_199].each do |malformed_input|
expect { described_class.date_from_input_to_storage(malformed_input) }.to raise_error(InvalidInputData)
end
but I am not convinced that it is improving readability, maintainability or anything else.