Can i do this with Spock?

junit, ruby-on-rails, spock, unit-testing

Solution

Using Spock:

class Validations extends Specification {
    def "must have a #attr"() {
        def a = new Address()

        expect:
        !a.valid
        a.errors.on(attr) != null

        where:
        attr << ["city", "zip", "street"]
    }
}

If there is more than one data variable, table syntax is more convenient:

        ...
        where:
        attr1    | attr2
        "city"   | ...
        "zip"    | ...
        "street" | ...

Problem

I saw an example in ROR for testing some domain class: ``` context "Validations" do [:city, :zip, :street].each do |attr| it "must have a #{attr}" do a = Address.new a.should_not be_valid a.errors.on(attr).should_not be_nil end end end ``` It creates tests on the fly with different values an different names... It's kind interesting, but... can I do this with spock or jUnit? Thanks a lot

Original source