1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# frozen_string_literal: true
def expect_failure(&block)
expect(&block).to raise_exception(RSpec::Expectations::ExpectationNotMetError)
end
RSpec.describe 'basic hypothesis tests' do
they 'think integer addition is commutative' do
hypothesis do
x = any integers
y = any integers
expect(x + y).to eq(y + x)
end
end
they 'are able to find zero values' do
expect_failure do
hypothesis do
x = any integers
expect(x).not_to eq(0)
end
end
end
they 'are able to filter out values' do
hypothesis do
x = any integers
assume x != 0
1 / x
end
end
they 'find that string addition is not commutative' do
expect_failure do
hypothesis do
x = any strings
y = any strings
expect(x + y).to be == y + x
end
end
end
they 'raise unsatisfiable when all assumptions fail' do
expect do
hypothesis do
any integers
assume false
end
end.to raise_exception(Hypothesis::Unsatisfiable)
end
end
|