Module: GreenDay::TestBuilder

Defined in:
lib/green_day/test_builder.rb

Class Method Summary collapse

Class Method Details

.build_example(submit_file_path, input, output) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/green_day/test_builder.rb', line 15

def build_example(submit_file_path, input, output)
  "    \#{tab}it 'test with \#{unify_cr_lf(input).chomp}' do\n    \#{tab}\#{tab}io = IO.popen('ruby \#{submit_file_path}', 'w+')\n    \#{tab}\#{tab}io.puts(\#{unify_cr_lf(input)})\n    \#{tab}\#{tab}io.close_write\n    \#{tab}\#{tab}expect(io.readlines.join).to eq(\#{unify_cr_lf(output)})\n    \#{tab}end\n  SPEC\nend\n"

.build_test(submit_file_path, sample_answers) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/green_day/test_builder.rb', line 7

def build_test(submit_file_path, sample_answers)
  "    RSpec.describe '\#{submit_file_path}' do\n    \#{sample_answers.map { |sample_answer| build_example(submit_file_path, sample_answer.input, sample_answer.output) }.join(\"\\n\")}\n    end\n  SPEC\nend\n"

.tabObject



32
33
34
# File 'lib/green_day/test_builder.rb', line 32

def tab
  "\s\s"
end

.unify_cr_lf(string) ⇒ Object



26
27
28
29
30
# File 'lib/green_day/test_builder.rb', line 26

def unify_cr_lf(string)
  return unless string # たまに画像で例を出してくるとsampleの文字がなくなる

  string.gsub(/\R/, "\n").dump
end