Вопрос

I'd like to test the validation of a model's attribute with rspec and factory_girl. The 'special' thing is, that one attribute (the name) isn't allowed to start with Numbers or special signs like %,&,$, ...

For testing this it would be great to write only one example like

it "is invalid with name starting by special character" do
    ["1","$","%"].each do |i|
       name = i + "test"
       FactoryGirl.build(:tutu, name: name).should_not be_valid
    end
end 

This work's for the first case but it won't return the result for the whole list. Is it possible to tell rspec not to stop on the error?

Это было полезно?

Решение

Do this instead:

["1","$","%"].each do |i|
  it "is invalid with name starting by '#{i}'" do
    FactoryGirl.build(:tutu, name: "#{i}test").should_not be_valid
  end
end 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top