ku-progsys / rbsyn

Program synthesis for Ruby
BSD 3-Clause "New" or "Revised" License
94 stars 4 forks source link

DSL for specifications #5

Closed ngsankha closed 5 years ago

ngsankha commented 5 years ago

An rspec like DSL for specifying tests that can be used to synthesize functions. Example:

define :username_available?, "(String) -> %bool" do

  spec "returns true when user doesn't exist" do
    username_available? 'bruce1'

    post { |result|
      result == true
    }
  end

  spec "returns false when user exists" do
    pre {
      u = User.create(name: 'Bruce Wayne', username: 'bruce1', password: 'coolcool')
      u.emails.create(email: 'bruce1@wayne.com')
    }

    username_available? 'bruce1'

    post { |result|
      result == false
    }
  end

  assert_equal generate_program, %{
def username_available?(arg0)
  User.exists?(username: arg0)
end
}.strip
end
ngsankha commented 5 years ago

This is done!