Sha256: 005e7a587723515cb63f90102f48d0e5695a4934a837bc7a900b28e494a22eb1

Contents?: true

Size: 1.31 KB

Versions: 91

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8
require 'spec_helper'
require 'eval_helper'

describe 'EvalHelper' do
  context :times_code do
    class EvalHelperTimesTest
      include EvalHelper

      def hoge(number, proc)
        code = times_code(number, proc)
      end
    end
    cases = [
      {
        case_no: 1,
        case_title: 'single_line_proc case',
        number: 2,
        proc: 'puts "#{i}times"',
        expected: '2.times { |i| puts "#{i}times" }'
      },
      {
        case_no: 2,
        case_title: 'multi_line_proc case',
        number: 3,
        proc: 'puts "#{i}times"\nputs "#{i*2}times"',
        expected: <<-EOS
3.times do |i|
  puts \"\#{i}times\"
  puts \"\#{i*2}times\"
end
        EOS
      },
    ]

    cases.each do |c|
      it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
        begin
          case_before c

          # -- given --
          # nothing

          # -- when --
          actual = EvalHelperTimesTest.new.hoge c[:number], c[:proc]

          # -- then --
          expect(actual).to eq(c[:expected])
        ensure
          case_after c
        end
      end

      def case_before(c)
        # implement each case before
      end

      def case_after(c)
        # implement each case after
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.130 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.129 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.128 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.127 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.126 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.125 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.124 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.123 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.122 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.121 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.120 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.119 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.118 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.117 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.116 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.115 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.114 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.113 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.112 spec/eval_helper/times_code_spec.rb
tbpgr_utils-0.0.111 spec/eval_helper/times_code_spec.rb