I'm not sure how to make variables defined in the before block be available in the test description. Here is what I mean.
context "name" do
before do
@min_size = 1
@max_size = 255
end
context "is valid when it" do
it "has #{@min_size} character" do
expect(create(:person, name: Faker::Lorem.characters(@min_size))).to be_valid
end
it "has #{@max_size} characters" do
expect(create(:person, name: Faker::Lorem.characters(@max_size))).to be_valid
end
it "has between #{@min_size} and #{@max_size} characters" do
expect(create(:person, name: Faker::Lorem.characters((@min_size + @max_size)/2))).to be_valid
end
end
end
The 3 tests pass, but this is how the output prints. Notice the missing min and max values.
name
is valid when it
has character
has characters
has between and characters