我不确定如何使 before 块中定义的变量在测试描述中可用。这就是我的意思。
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
3 个测试通过,但这就是输出的打印方式。注意缺少的最小值和最大值。
name
is valid when it
has character
has characters
has between and characters