Sha256: d18c38a339f3523344f75be67551681de092c39270d1e5a8f4d2ddcd27f1021b

Contents?: true

Size: 964 Bytes

Versions: 4

Compression:

Stored size: 964 Bytes

Contents

require_relative '../../spec_helper'
require 'sql/maker/condition'
require 'sql/maker/helper'

include SQL::Maker::Helper

def test(input, expected_term, expected_bind)
  describe 'SQL::Maker::Condition' do
    it input do
      source = eval(input, binding)
      cond = SQL::Maker::Condition.new(
        :quote_char => '`',
        :name_sep   => '.',
      )
      cond.add(source)
      sql = cond.as_sql
      sql = sql.gsub(/^\(/, '').gsub(/\)$/, '')
      expect(sql).to be == expected_term
      expect(cond.bind).to be == expected_bind
    end
  end
end

begin
  file = File.open("#{ROOT}/doc/sql/maker/condition.md")
  while line = file.gets
    break if line =~ /CONDITION CHEAT SHEET/
  end
  while line = file.gets
    next if line =~ /^ *#/
    src = $1 if line =~ /IN:\s*(.+)\s*$/
    query = eval($1, binding) if line =~ /OUT QUERY:(.+)/
    if line =~ /OUT BIND:(.+)/
      bind = eval($1, binding)
      test(src, query, bind)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sql-maker-1.0.0 spec/maker/condition/cheatsheat_spec.rb
sql-maker-0.0.5 spec/maker/condition/cheatsheat_spec.rb
sql-maker-0.0.4 spec/maker/condition/cheatsheat_spec.rb
sql-maker-0.0.3 spec/maker/condition/cheatsheat_spec.rb